Skip to content

Commit 38a265f

Browse files
committed
Fix Metrics Publisher in UTs
Signed-off-by: Tanishq Ranjan <tqranjan@amazon.com>
1 parent 7a8de29 commit 38a265f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobStoreContainerTests.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113

114114
import org.mockito.ArgumentCaptor;
115115
import org.mockito.ArgumentMatchers;
116+
import org.mockito.Mockito;
116117
import org.reactivestreams.Subscriber;
117118
import org.reactivestreams.Subscription;
118119

@@ -782,7 +783,8 @@ public void testExecuteSingleUploadIfEtagMatchesPreconditionFailed() throws IOEx
782783
when(client.putObject(any(PutObjectRequest.class), any(RequestBody.class))).thenThrow(preconditionFailedException);
783784

784785
final AtomicReference<Exception> capturedException = new AtomicReference<>();
785-
ActionListener<String> etagListener = ActionListener.wrap(r -> fail("Should have failed"), capturedException::set);
786+
ActionListener<String> realListener = ActionListener.wrap(r -> fail("Should have failed"), capturedException::set);
787+
ActionListener<String> etagListener = Mockito.spy(realListener);
786788

787789
final ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[blobSize]);
788790
blobContainer.executeSingleUploadIfEtagMatches(blobStore, blobName, inputStream, blobSize, metadata, eTag, etagListener);
@@ -971,7 +973,8 @@ public void testExecuteSingleUploadIfEtagMatchesSdkException() throws IOExceptio
971973
when(client.putObject(any(PutObjectRequest.class), any(RequestBody.class))).thenThrow(sdkException);
972974

973975
final AtomicReference<Exception> capturedException = new AtomicReference<>();
974-
ActionListener<String> etagListener = ActionListener.wrap(r -> fail("Should have failed for SdkException"), capturedException::set);
976+
ActionListener<String> realListener = ActionListener.wrap(r -> fail("Should have failed for SdkException"), capturedException::set);
977+
ActionListener<String> etagListener = Mockito.spy(realListener);
975978

976979
final ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[blobSize]);
977980
blobContainer.executeSingleUploadIfEtagMatches(blobStore, blobName, inputStream, blobSize, metadata, eTag, etagListener);
@@ -1067,20 +1070,14 @@ public void testExecuteSingleUploadIfEtagMatchesNullOrEmptyInput() throws IOExce
10671070
verify(mockListenerCase1, never()).onFailure(any());
10681071
verify(clientReference1).close();
10691072

1070-
final StatsMetricPublisher metricPublisher2 = mock(StatsMetricPublisher.class);
1071-
final software.amazon.awssdk.metrics.MetricPublisher awsMetricPublisher2 = mock(
1072-
software.amazon.awssdk.metrics.MetricPublisher.class
1073-
);
1074-
when(metricPublisher2.putObjectMetricPublisher).thenReturn(awsMetricPublisher2);
1075-
10761073
final ByteArrayInputStream inputStreamCase2 = new ByteArrayInputStream(new byte[0]);
10771074
@SuppressWarnings("unchecked")
10781075
ActionListener<String> mockListenerCase2 = mock(ActionListener.class);
10791076

10801077
final S3Client client2 = mock(S3Client.class);
10811078
final AmazonS3Reference clientReference2 = mock(AmazonS3Reference.class);
10821079

1083-
when(blobStore.getStatsMetricPublisher()).thenReturn(metricPublisher2);
1080+
when(blobStore.getStatsMetricPublisher()).thenReturn(new StatsMetricPublisher());
10841081
when(blobStore.clientReference()).thenReturn(clientReference2);
10851082
when(clientReference2.get()).thenReturn(client2);
10861083
when(client2.putObject(any(PutObjectRequest.class), any(RequestBody.class))).thenReturn(

0 commit comments

Comments
 (0)