|
8 | 8 | import static org.junit.Assert.assertEquals; |
9 | 9 | import static org.junit.Assert.assertTrue; |
10 | 10 | import static org.mockito.ArgumentMatchers.any; |
| 11 | +import static org.mockito.ArgumentMatchers.anyInt; |
11 | 12 | import static org.mockito.ArgumentMatchers.anyString; |
12 | 13 | import static org.mockito.ArgumentMatchers.eq; |
13 | 14 | import static org.mockito.Mockito.*; |
@@ -242,7 +243,7 @@ void testConcurrentRunWithPlatformThreads() throws Throwable { |
242 | 243 | AWSLambda.startRuntimeLoops(lambdaRequestHandler, lambdaLogger, concurrencyConfig, runtimeClient); |
243 | 244 |
|
244 | 245 | // Success Reports Must Equal number of tasks that ran successfully. |
245 | | - verify(runtimeClient, times(7)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), any()); |
| 246 | + verify(runtimeClient, times(7)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), anyInt(), any()); |
246 | 247 | // Hashmap keys should equal the number of threads (runtime loops). |
247 | 248 | assertEquals(4, SampleHandler.hashMap.size()); |
248 | 249 | // Hashmap total count should equal all tasks that ran * number of iterations per task |
@@ -284,7 +285,7 @@ void testConcurrentRunWithPlatformThreadsWithFailures() throws Throwable { |
284 | 285 | verify(runtimeClient).reportInvocationError(eq(UserFaultID), any(), any()); |
285 | 286 |
|
286 | 287 | // Success Reports Must Equal number of tasks that ran successfully. |
287 | | - verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), any()); |
| 288 | + verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), anyInt(), any()); |
288 | 289 |
|
289 | 290 | // Hashmap keys should equal the minumum between(number of threads (runtime loops) AND number of tasks that ran successfully). |
290 | 291 | assertEquals(2, SampleHandler.hashMap.size()); |
@@ -331,7 +332,7 @@ void testConcurrentModeLoopDoesNotExitExceptForLambdaRuntimeClientMaxRetriesExce |
331 | 332 | verify(runtimeClient).reportInvocationError(eq(IOErrorID), any(), any()); |
332 | 333 |
|
333 | 334 | // Success Reports Must Equal number of tasks that ran successfully. |
334 | | - verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), any()); |
| 335 | + verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), anyInt(), any()); |
335 | 336 |
|
336 | 337 | // Hashmap keys should equal the minumum between(number of threads (runtime loops) AND number of tasks that ran successfully). |
337 | 338 | assertEquals(1, SampleHandler.hashMap.size()); |
@@ -520,7 +521,7 @@ void testSequentialWithFatalUserFaultErrorStopsLoop() throws Throwable { |
520 | 521 | verify(runtimeClient).reportInvocationError(eq(UserFaultID), any(), any()); |
521 | 522 |
|
522 | 523 | // Success Reports Must Equal number of tasks that ran successfully. And only 2 Error reports for failImmediatelyRequest and userFaultRequest. |
523 | | - verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), any()); |
| 524 | + verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), anyInt(), any()); |
524 | 525 | verify(runtimeClient, times(2)).reportInvocationError(any(), any(), any()); |
525 | 526 |
|
526 | 527 | // Hashmap keys should equal one as it is not multithreaded. |
@@ -566,7 +567,7 @@ void testSequentialWithVirtualMachineErrorStopsLoop() throws Throwable { |
566 | 567 | verify(runtimeClient).reportInvocationError(eq(IOErrorID), any(), any()); |
567 | 568 |
|
568 | 569 | // Success Reports Must Equal number of tasks that ran successfully. And only 2 Error reports for failImmediatelyRequest and virtualMachineErrorRequest. |
569 | | - verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), any()); |
| 570 | + verify(runtimeClient, times(2)).reportInvocationSuccess(eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), anyInt(), any()); |
570 | 571 | verify(runtimeClient, times(2)).reportInvocationError(any(), any(), any()); |
571 | 572 |
|
572 | 573 | // Hashmap keys should equal one as it is not multithreaded. |
@@ -671,7 +672,45 @@ void testInvocationIdIsPassedToReportSuccess() throws Throwable { |
671 | 672 | AWSLambda.startRuntimeLoops(lambdaRequestHandler, lambdaLogger, concurrencyConfig, runtimeClient); |
672 | 673 |
|
673 | 674 | verify(runtimeClient).reportInvocationSuccess( |
674 | | - eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), eq("test-inv-uuid-1234")); |
| 675 | + eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), any(), anyInt(), eq("test-inv-uuid-1234")); |
| 676 | + } |
| 677 | + |
| 678 | + /** Exposes the backing array so tests can check that it is posted as is. */ |
| 679 | + private static final class InspectableByteArrayOutputStream extends ByteArrayOutputStream { |
| 680 | + byte[] backingArray() { |
| 681 | + return buf; |
| 682 | + } |
| 683 | + } |
| 684 | + |
| 685 | + private void runOneInvocation(LambdaRequestHandler handler) throws Throwable { |
| 686 | + when(concurrencyConfig.isMultiConcurrent()).thenReturn(false); |
| 687 | + |
| 688 | + InvocationRequest request = getFakeInvocationRequest(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE); |
| 689 | + request.setInvocationId("test-inv-uuid-1234"); |
| 690 | + |
| 691 | + // Fatal error to stop the loop after one successful invocation |
| 692 | + InvocationRequest fatalRequest = mock(InvocationRequest.class); |
| 693 | + when(fatalRequest.getId()).thenThrow(UserFault.makeUserFault(new IOError(new Throwable()), true)).thenReturn("fatal"); |
| 694 | + |
| 695 | + when(runtimeClient.nextInvocation()) |
| 696 | + .thenReturn(request) |
| 697 | + .thenReturn(fatalRequest); |
| 698 | + |
| 699 | + AWSLambda.startRuntimeLoops(handler, lambdaLogger, concurrencyConfig, runtimeClient); |
| 700 | + } |
| 701 | + |
| 702 | + @Test |
| 703 | + @Timeout(value = 1, unit = TimeUnit.MINUTES) |
| 704 | + void testResponseBackingArrayIsPostedWithoutCopy() throws Throwable { |
| 705 | + InspectableByteArrayOutputStream output = new InspectableByteArrayOutputStream(); |
| 706 | + output.write("\"success\"".getBytes()); |
| 707 | + |
| 708 | + runOneInvocation(request -> output); |
| 709 | + |
| 710 | + // The backing array itself is passed, with the content length, instead of a toByteArray() copy. |
| 711 | + verify(runtimeClient).reportInvocationSuccess( |
| 712 | + eq(SampleHandler.ADD_ENTRY_TO_MAP_ID_OP_MODE), same(output.backingArray()), eq(9), eq("test-inv-uuid-1234")); |
| 713 | + verify(runtimeClient, never()).reportInvocationSuccess(anyString(), any(), any()); |
675 | 714 | } |
676 | 715 |
|
677 | 716 | @Test |
|
0 commit comments