From 8f4553b126b411e6b649b5f53f62bb66b37d3032 Mon Sep 17 00:00:00 2001 From: Sooraj Sinha Date: Wed, 24 Jul 2024 08:35:30 +0530 Subject: [PATCH] Update unit tests Signed-off-by: Sooraj Sinha --- .../BlobStoreTransferServiceTests.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/server/src/test/java/org/opensearch/index/translog/transfer/BlobStoreTransferServiceTests.java b/server/src/test/java/org/opensearch/index/translog/transfer/BlobStoreTransferServiceTests.java index db15cc2faf27e..10e4cc6cfb1ef 100644 --- a/server/src/test/java/org/opensearch/index/translog/transfer/BlobStoreTransferServiceTests.java +++ b/server/src/test/java/org/opensearch/index/translog/transfer/BlobStoreTransferServiceTests.java @@ -145,8 +145,28 @@ public void testUploadBlobFromInputStreamAsyncFSRepo() throws IOException, Inter FsBlobStore fsBlobStore = mock(FsBlobStore.class); when(fsBlobStore.blobContainer(any())).thenReturn(mockAsyncFsContainer); - TransferService transferService = new BlobStoreTransferService(fsBlobStore, threadPool); - uploadBlobFromInputStream(transferService); + BlobStoreTransferService transferServiceSpy = Mockito.spy(new BlobStoreTransferService(fsBlobStore, threadPool)); + uploadBlobFromInputStream(transferServiceSpy); + + ArgumentCaptor inputStreamCaptor = ArgumentCaptor.forClass( + RemoteTransferContainer.OffsetRangeInputStreamSupplier.class + ); + verify(transferServiceSpy).uploadBlobAsyncInternal( + Mockito.anyString(), + Mockito.anyString(), + Mockito.anyLong(), + Mockito.any(), + Mockito.any(), + inputStreamCaptor.capture(), + Mockito.anyLong(), + Mockito.any(), + Mockito.any() + ); + RemoteTransferContainer.OffsetRangeInputStreamSupplier inputStreamSupplier = inputStreamCaptor.getValue(); + OffsetRangeInputStream inputStream1 = inputStreamSupplier.get(1, 0); + OffsetRangeInputStream inputStream2 = inputStreamSupplier.get(1, 2); + assertNotEquals(inputStream1, inputStream2); + assertNotEquals(inputStream1.getFilePointer(), inputStream2.getFilePointer()); } private IndexMetadata getIndexMetadata() { @@ -159,7 +179,6 @@ private IndexMetadata getIndexMetadata() { } private void uploadBlobFromInputStream(TransferService transferService) throws IOException, InterruptedException { - BlobStoreTransferService transferServiceSpy = Mockito.spy((BlobStoreTransferService) transferService); TestClass testObject = new TestClass("field1", "value1"); AtomicBoolean succeeded = new AtomicBoolean(false); ChecksumBlobStoreFormat blobStoreFormat = new ChecksumBlobStoreFormat<>( @@ -193,28 +212,9 @@ public void onFailure(Exception e) { resp -> listener.onResponse(testObject), ex -> listener.onFailure(ex) ); - transferServiceSpy.uploadBlob(inputStream, repository.basePath(), "test-object", WritePriority.URGENT, completionListener); + transferService.uploadBlob(inputStream, repository.basePath(), "test-object", WritePriority.URGENT, completionListener); assertTrue(latch.await(1000, TimeUnit.MILLISECONDS)); assertTrue(succeeded.get()); - ArgumentCaptor inputStreamCaptor = ArgumentCaptor.forClass( - RemoteTransferContainer.OffsetRangeInputStreamSupplier.class - ); - verify(transferServiceSpy).uploadBlobAsyncInternal( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyLong(), - Mockito.any(), - Mockito.any(), - inputStreamCaptor.capture(), - Mockito.anyLong(), - Mockito.any(), - Mockito.any() - ); - RemoteTransferContainer.OffsetRangeInputStreamSupplier inputStreamSupplier = inputStreamCaptor.getValue(); - OffsetRangeInputStream inputStream1 = inputStreamSupplier.get(1, 0); - OffsetRangeInputStream inputStream2 = inputStreamSupplier.get(1, 2); - assertNotEquals(inputStream1, inputStream2); - assertNotEquals(inputStream1.getFilePointer(), inputStream2.getFilePointer()); } }