Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kondaka <[email protected]>
  • Loading branch information
kkondaka committed Nov 18, 2024
1 parent c6c7f40 commit f2d6d53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void testWaitForFutures() {

LambdaCommonHandler.waitForFutures(futureList);

assertTrue(futureList.isEmpty());
assertFalse(futureList.isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.opensearch.dataprepper.plugins.lambda.common.config.ClientOptions;
import static org.opensearch.dataprepper.plugins.lambda.processor.LambdaProcessor.NUMBER_OF_RECORDS_FLUSHED_TO_LAMBDA_FAILED;
import static org.opensearch.dataprepper.plugins.lambda.processor.LambdaProcessor.NUMBER_OF_RECORDS_FLUSHED_TO_LAMBDA_SUCCESS;
import static org.opensearch.dataprepper.plugins.lambda.processor.LambdaProcessor.NUMBER_OF_SUCCESSFUL_REQUESTS_TO_LAMBDA;
import static org.opensearch.dataprepper.plugins.lambda.processor.LambdaProcessor.NUMBER_OF_FAILED_REQUESTS_TO_LAMBDA;


import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Timer;
Expand Down Expand Up @@ -107,8 +110,13 @@ public class LambdaProcessorTest {
@Mock
private Counter numberOfRecordsSuccessCounter;

@Mock
private Counter numberOfRequestsSuccessCounter;

@Mock
private Counter numberOfRecordsFailedCounter;
@Mock
private Counter numberOfRequestsFailedCounter;

@Mock
private InvokeResponse invokeResponse;
Expand All @@ -131,6 +139,10 @@ public void setUp() throws Exception {
numberOfRecordsSuccessCounter);
when(pluginMetrics.counter(eq(NUMBER_OF_RECORDS_FLUSHED_TO_LAMBDA_FAILED))).thenReturn(
numberOfRecordsFailedCounter);
when(pluginMetrics.counter(eq(NUMBER_OF_SUCCESSFUL_REQUESTS_TO_LAMBDA))).thenReturn(
numberOfRecordsSuccessCounter);
when(pluginMetrics.counter(eq(NUMBER_OF_FAILED_REQUESTS_TO_LAMBDA))).thenReturn(
numberOfRecordsFailedCounter);
when(pluginMetrics.timer(anyString())).thenReturn(lambdaLatencyMetric);
when(pluginMetrics.gauge(anyString(), any(AtomicLong.class))).thenAnswer(
invocation -> invocation.getArgument(1));
Expand Down Expand Up @@ -200,7 +212,10 @@ private void populatePrivateFields() throws Exception {
// Use reflection to set the private fields
setPrivateField(lambdaProcessor, "numberOfRecordsSuccessCounter",
numberOfRecordsSuccessCounter);
setPrivateField(lambdaProcessor, "numberOfRequestsSuccessCounter",
numberOfRequestsSuccessCounter);
setPrivateField(lambdaProcessor, "numberOfRecordsFailedCounter", numberOfRecordsFailedCounter);
setPrivateField(lambdaProcessor, "numberOfRequestsFailedCounter", numberOfRequestsFailedCounter);
setPrivateField(lambdaProcessor, "tagsOnMatchFailure", tagsOnMatchFailure);
setPrivateField(lambdaProcessor, "lambdaCommonHandler", lambdaCommonHandler);
}
Expand Down Expand Up @@ -274,7 +289,7 @@ public void testDoExecute_WithEmptyResponse() throws Exception {

// Assert
assertEquals(0, result.size(), "Result should be empty due to empty Lambda response.");
//verify(numberOfRecordsSuccessCounter, times(1)).increment(1.0);
verify(numberOfRecordsSuccessCounter, times(1)).increment(1.0);
}

@Test
Expand All @@ -292,7 +307,7 @@ public void testDoExecute_WithNullResponse() throws Exception {

// Assert
assertEquals(0, result.size(), "Result should be empty due to null Lambda response.");
//verify(numberOfRecordsSuccessCounter, times(1)).increment(1.0);
verify(numberOfRecordsSuccessCounter, times(1)).increment(1.0);
}

@Test
Expand Down

0 comments on commit f2d6d53

Please sign in to comment.