diff --git a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSBackupRepositoryTest.java b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSBackupRepositoryTest.java index e4a2e084445..68c825777ae 100644 --- a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSBackupRepositoryTest.java +++ b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSBackupRepositoryTest.java @@ -45,6 +45,7 @@ import org.apache.solr.common.util.NamedList; import org.apache.solr.core.backup.repository.BackupRepository; import org.junit.AfterClass; +import org.junit.Assume; import org.junit.Test; /** Unit tests for {@link GCSBackupRepository} that use an in-memory Storage object */ @@ -123,7 +124,7 @@ public void testCopyIndexFileToHandlesZeroByteReads() throws Exception { GCSBackupRepository repo = createRepositoryWithStorage(realStorage); URI sourceDir = repo.resolve(getBaseUri(), "backup"); BlobId blobId = BlobId.of(bucketName, sourceDir + "/source.dat"); - realStorage.create(BlobInfo.newBuilder(blobId).build(), data); + createBlob(realStorage, blobId, data); Storage zeroReturningStorage = createZeroReturningStorage(realStorage); GCSBackupRepository proxyRepo = createRepositoryWithStorage(zeroReturningStorage); @@ -150,7 +151,7 @@ public void testCopyIndexFileToCopiesFile() throws Exception { GCSBackupRepository repo = createRepositoryWithStorage(realStorage); URI sourceDir = repo.resolve(getBaseUri(), "backup"); BlobId blobId = BlobId.of(bucketName, sourceDir + "/source.dat"); - realStorage.create(BlobInfo.newBuilder(blobId).build(), data); + createBlob(realStorage, blobId, data); try (Directory dest = new ByteBuffersDirectory()) { repo.copyIndexFileTo(sourceDir, "source.dat", dest, "dest.dat"); @@ -163,6 +164,27 @@ public void testCopyIndexFileToCopiesFile() throws Exception { } } + /** + * Creates a blob, skipping (rather than failing) the test if the current default locale trips the + * known FakeStorageRpc/RFC3339 date-parsing bug - see {@link + * LocalStorageGCSBackupRepository#initializeBackupLocation()} for the same pattern. + */ + private static void createBlob(Storage storage, BlobId blobId, byte[] data) { + try { + storage.create(BlobInfo.newBuilder(blobId).build(), data); + } catch (Exception e) { + final Throwable cause = e.getCause(); + Assume.assumeFalse( + "This test uses a GCS mock library that is incompatible with the current default locale", + cause != null + && e instanceof StorageException + && cause.getMessage().contains("Invalid date/time format") + && cause instanceof NumberFormatException); + // Not the known locale incompatibility - a genuine failure, so don't swallow it. + throw new RuntimeException(e); + } + } + /** Storage proxy that fails on {@code reader} so we can assert copy errors are propagated. */ private static Storage createFailingStorage() { Storage delegate = LocalStorageHelper.customOptions(false).getService(); diff --git a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/LocalStorageGCSBackupRepository.java b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/LocalStorageGCSBackupRepository.java index fc26a188f87..da54e135de4 100644 --- a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/LocalStorageGCSBackupRepository.java +++ b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/LocalStorageGCSBackupRepository.java @@ -96,13 +96,14 @@ protected void initializeBackupLocation() { createDirectory(baseLocationUri); } catch (Exception 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); - } + assumeFalse( + "This test uses a GCS mock library that is incompatible with the current default locale", + cause != null + && e instanceof StorageException + && cause.getMessage().contains("Invalid date/time format") + && cause instanceof NumberFormatException); + // Not the known locale incompatibility - a genuine failure, so don't swallow it. + throw new RuntimeException(e); } } }