Skip to content

Commit ddaa4ea

Browse files
committed
Fix up some S3BlobStoreContainerTests
1 parent c860a8a commit ddaa4ea

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobStore.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,25 @@ public TimeValue getGetRegisterRetryDelay() {
498498
return getRegisterRetryDelay;
499499
}
500500

501-
public static StorageClass initStorageClass(String storageClass) {
502-
if ((storageClass == null) || storageClass.equals("")) {
501+
public static StorageClass initStorageClass(String storageClassName) {
502+
if ((storageClassName == null) || storageClassName.equals("")) {
503503
return StorageClass.STANDARD;
504504
}
505505

506+
final StorageClass storageClass;
506507
try {
507-
final StorageClass _storageClass = StorageClass.fromValue(storageClass.toUpperCase(Locale.ENGLISH));
508-
if (_storageClass.equals(StorageClass.GLACIER)) {
509-
throw new BlobStoreException("Glacier storage class is not supported");
510-
}
511-
512-
return _storageClass;
513-
} catch (final IllegalArgumentException illegalArgumentException) {
514-
throw new BlobStoreException("`" + storageClass + "` is not a valid S3 Storage Class.");
508+
storageClass = StorageClass.fromValue(storageClassName.toUpperCase(Locale.ENGLISH));
509+
} catch (final Exception e) {
510+
throw new BlobStoreException("`" + storageClassName + "` is not a valid S3 Storage Class.", e);
511+
}
512+
if (storageClass.equals(StorageClass.GLACIER)) {
513+
throw new BlobStoreException("Glacier storage class is not supported");
515514
}
515+
if (storageClass.equals(StorageClass.UNKNOWN_TO_SDK_VERSION)) {
516+
throw new BlobStoreException("`" + storageClassName + "` is not a known S3 Storage Class.");
517+
}
518+
519+
return storageClass;
516520
}
517521

518522
/**

modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3BlobStoreContainerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public void testExecuteMultipartUploadAborted() {
384384

385385
private static S3Client configureMockClient(S3BlobStore blobStore) {
386386
final S3Client client = mock(S3Client.class);
387-
final SdkHttpClient httpClient = mock(ApacheHttpClient.class);
387+
final SdkHttpClient httpClient = mock(SdkHttpClient.class);
388388
try (AmazonS3Reference clientReference = new AmazonS3Reference(client, httpClient)) {
389389
clientReference.mustIncRef(); // held by the mock, ultimately released in closeMockClient
390390
when(blobStore.clientReference()).then(invocation -> {
@@ -436,7 +436,7 @@ public void testInitCannedACL() {
436436
"public-read",
437437
"public-read-write",
438438
"authenticated-read",
439-
"log-delivery-write",
439+
// "log-delivery-write", TODO NOMERGE this isn't supported in SDKv2
440440
"bucket-owner-read",
441441
"bucket-owner-full-control" };
442442

@@ -485,7 +485,7 @@ public void testCaseInsensitiveStorageClass() {
485485

486486
public void testInvalidStorageClass() {
487487
BlobStoreException ex = expectThrows(BlobStoreException.class, () -> S3BlobStore.initStorageClass("whatever"));
488-
assertThat(ex.getMessage(), equalTo("`whatever` is not a valid S3 Storage Class."));
488+
assertThat(ex.getMessage(), equalTo("`whatever` is not a known S3 Storage Class."));
489489
}
490490

491491
public void testRejectGlacierStorageClass() {

0 commit comments

Comments
 (0)