Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Sep 4, 2024
1 parent d14aa7b commit 4d23310
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions RFS/src/test/java/com/rfs/common/OpenSearchClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void testBulkRequest_succeedAfterRetries() {
var server500 = new HttpResponse(500, "", null, "{\"error\":\"Cannot Process Error!\"}");

var restClient = mock(RestClient.class);
when(restClient.postAsync(any(), any(), any())).thenReturn(Mono.just(bothDocsFail))
when(restClient.postAsync(any(), any(), any(), any())).thenReturn(Mono.just(bothDocsFail))
.thenReturn(Mono.just(oneFailure))
.thenReturn(Mono.just(server500))
.thenReturn(Mono.just(finalDocSuccess));
Expand All @@ -159,7 +159,7 @@ void testBulkRequest_succeedAfterRetries() {
// Assertions
// StepVerifier.create(responseMono).expectComplete().verify();

verify(restClient, times(4)).postAsync(any(), any(), any());
verify(restClient, times(4)).postAsync(any(), any(), any(), any());
verifyNoInteractions(failedRequestLogger);
}

Expand All @@ -169,7 +169,7 @@ void testBulkRequest_recordsTotalFailures() {
var docFails = bulkItemResponse(true, List.of(itemEntryFailure(docId1)));

var restClient = mock(RestClient.class);
when(restClient.postAsync(any(), any(), any())).thenReturn(Mono.just(docFails));
when(restClient.postAsync(any(), any(), any(), any())).thenReturn(Mono.just(docFails));

var failedRequestLogger = mock(FailedRequestsLogger.class);
var openSearchClient = spy(new OpenSearchClient(restClient, failedRequestLogger));
Expand All @@ -192,7 +192,7 @@ void testBulkRequest_recordsTotalFailures() {
assertThat(exception.getMessage(), containsString("Retries exhausted"));

var maxAttempts = maxRetries + 1;
verify(restClient, times(maxAttempts)).postAsync(any(), any(), any());
verify(restClient, times(maxAttempts)).postAsync(any(), any(), any(), any());
verify(failedRequestLogger).logBulkFailure(any(), any(), any(), any());
verifyNoMoreInteractions(failedRequestLogger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void testGzipCompression(int size) throws Exception {
// Generate test data
ByteBuffer inputBuffer = generateTestData(size);
Map<String, List<String>> headers = new HashMap<>();

headers.put("content-encoding", List.of("gzip"));
// Store initial position and limit
int initialPosition = inputBuffer.position();
int initialLimit = inputBuffer.limit();
Expand Down Expand Up @@ -82,6 +82,7 @@ void testGzipCompressionWithDirectBuffer(int size) throws Exception {
inputBuffer.flip();

Map<String, List<String>> headers = new HashMap<>();
headers.put("content-encoding", List.of("gzip"));

// Store initial position and limit
int initialPosition = inputBuffer.position();
Expand Down Expand Up @@ -133,6 +134,7 @@ void testLargeInput() throws Exception {
int largeSize = 50 * 1024 * 1024; // 50MB
ByteBuffer largeBuffer = generateTestData(largeSize);
Map<String, List<String>> headers = new HashMap<>();
headers.put("content-encoding", List.of("gzip"));

// Store initial position and limit
int initialPosition = largeBuffer.position();
Expand Down Expand Up @@ -167,6 +169,7 @@ public void testLargeInputWithDirectBuffer() throws Exception {
largeBuffer.flip();

Map<String, List<String>> headers = new HashMap<>();
headers.put("content-encoding", List.of("gzip"));

// Store initial position and limit
int initialPosition = largeBuffer.position();
Expand Down Expand Up @@ -208,8 +211,11 @@ private ByteBuffer generateTestData(int size) {
}

private byte[] decompress(ByteBuffer compressedBuffer) throws Exception {
ByteBuffer readArray = compressedBuffer.duplicate();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedBuffer.array()))) {
byte[] compressedArray = new byte[readArray.remaining()];
readArray.get(compressedArray);
try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedArray))) {
byte[] buffer = new byte[1024];
int len;
while ((len = gzipInputStream.read(buffer)) > 0) {
Expand Down

0 comments on commit 4d23310

Please sign in to comment.