Skip to content

Commit

Permalink
SOLR-15501: Fix longstanding GCS test issue
Browse files Browse the repository at this point in the history
A library we use to stub out GCS in tests only works in a limited set of
locales.  We'd been working around this problem by maintaining a list of
the 'incompatible' locales and skipping the tests if any of the known
bad ones were in use.  This worked much of the time but often failed
because the list of incompatible locales was incomplete and Jenkins jobs
were constantly finding fails with different seeds.

This commit replaces this approach with a different one - have the test
catch the locale-specific error and skip the test at that point.  This
should clean up the sporadic failures that pop up now and then in Jenkins
builds.
  • Loading branch information
gerlowskija committed Jan 25, 2022
1 parent 742155a commit b88ad33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@

package org.apache.solr.gcs;

import com.google.common.collect.Lists;
import org.apache.solr.cloud.api.collections.AbstractBackupRepositoryTest;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.backup.repository.BackupRepository;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.apache.solr.common.params.CoreAdminParams.BACKUP_LOCATION;
Expand All @@ -41,19 +37,6 @@
*/
public class GCSBackupRepositoryTest extends AbstractBackupRepositoryTest {

// Locale langs unsupported by google-cloud-nio's 'Storage' drop-in. May need added to as Jenkins finds fails.
// (Note that the issue here is in the test-stub, actual GCS use is fine with these locales).
private static final List<String> INCOMPATIBLE_LOCALE_LANGS = Lists.newArrayList("ar", "dz", "uz", "ne", "mzn", "pa",
"sd", "mr", "ig", "as", "fa", "my", "bn", "lrc", "ur", "ks", "th", "ckb", "ja", "ps", "hi");

@BeforeClass
public static void ensureCompatibleLocale() {
final String defaultLang = Locale.getDefault().getLanguage();

assumeFalse("This test uses a GCS mock library that is incompatible with the current default locale " + defaultLang,
INCOMPATIBLE_LOCALE_LANGS.contains(defaultLang));
}

@AfterClass
public static void tearDownClass() throws Exception {
LocalStorageGCSBackupRepository.clearStashedStorage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public class GCSIncrementalBackupTest extends AbstractIncrementalBackupTest {

private static String backupLocation;

@BeforeClass
public static void ensureCompatibleLocale() {
GCSBackupRepositoryTest.ensureCompatibleLocale();
}

@BeforeClass
public static void setupClass() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageException;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
import com.google.common.collect.Lists;

Expand All @@ -29,6 +30,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.apache.lucene.util.LuceneTestCase.assumeFalse;

public class LocalStorageGCSBackupRepository extends GCSBackupRepository {

protected static Storage stashedStorage = null;
Expand Down Expand Up @@ -98,7 +101,13 @@ protected void initializeBackupLocation() {
final URI baseLocationUri = createDirectoryURI(baseLocation);
createDirectory(baseLocationUri);
} catch (Exception e) {
throw new RuntimeException(e);
final Throwable cause = e.getCause();
if (cause != null) {
assumeFalse("This test uses a GCS mock library that is incompatible with the current default locale",
e instanceof StorageException &&
cause.getMessage().contains("Invalid date/time format") &&
cause instanceof NumberFormatException);
}
}
}
}

0 comments on commit b88ad33

Please sign in to comment.