|
23 | 23 | import org.mockito.InOrder; |
24 | 24 | import org.mockito.Mock; |
25 | 25 | import org.mockito.junit.jupiter.MockitoExtension; |
| 26 | +import org.mockito.junit.jupiter.MockitoSettings; |
| 27 | +import org.mockito.quality.Strictness; |
26 | 28 | import org.opensearch.dataprepper.metrics.PluginMetrics; |
27 | 29 | import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSet; |
28 | 30 | import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager; |
|
45 | 47 | import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest; |
46 | 48 | import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse; |
47 | 49 | import software.amazon.awssdk.services.sqs.model.SqsException; |
| 50 | +import software.amazon.awssdk.awscore.exception.AwsServiceException; |
| 51 | +import software.amazon.awssdk.services.sqs.model.KmsAccessDeniedException; |
| 52 | +import software.amazon.awssdk.services.sqs.model.KmsNotFoundException; |
| 53 | +import software.amazon.awssdk.services.sqs.model.KmsThrottledException; |
| 54 | +import software.amazon.awssdk.services.sqs.model.QueueDoesNotExistException; |
48 | 55 | import software.amazon.awssdk.services.sts.model.StsException; |
49 | 56 |
|
50 | 57 | import java.io.IOException; |
|
71 | 78 | import static org.junit.jupiter.params.provider.Arguments.arguments; |
72 | 79 | import static org.mockito.ArgumentMatchers.any; |
73 | 80 | import static org.mockito.ArgumentMatchers.anyInt; |
| 81 | +import static org.mockito.ArgumentMatchers.anyString; |
74 | 82 | import static org.mockito.ArgumentMatchers.eq; |
75 | 83 | import static org.mockito.Mockito.inOrder; |
| 84 | +import static org.mockito.Mockito.lenient; |
76 | 85 | import static org.mockito.Mockito.mock; |
77 | 86 | import static org.mockito.Mockito.never; |
78 | 87 | import static org.mockito.Mockito.reset; |
@@ -866,6 +875,54 @@ private static String createEventBridgeNotification(final Instant startTime) { |
866 | 875 | "\"reason\":\"PutObject\"}}"; |
867 | 876 | } |
868 | 877 |
|
| 878 | + @Test |
| 879 | + void run_increments_access_denied_metric_on_403_exception() { |
| 880 | + final SqsException sqsException = mock(SqsException.class); |
| 881 | + when(sqsException.statusCode()).thenReturn(403); |
| 882 | + when(sqsClient.receiveMessage(any(ReceiveMessageRequest.class))).thenThrow(sqsException); |
| 883 | + |
| 884 | + final Counter accessDeniedCounter = mock(Counter.class); |
| 885 | + when(pluginMetrics.counter(SqsWorker.SQS_MESSAGE_ACCESS_DENIED_METRIC_NAME)).thenReturn(accessDeniedCounter); |
| 886 | + lenient().when(pluginMetrics.counter(anyString())).thenReturn(mock(Counter.class)); |
| 887 | + |
| 888 | + final SqsWorker sqsWorker = createObjectUnderTest(); |
| 889 | + sqsWorker.run(); |
| 890 | + |
| 891 | + verify(accessDeniedCounter).increment(); |
| 892 | + } |
| 893 | + |
| 894 | + @Test |
| 895 | + void run_increments_queue_not_found_metric_on_404_exception() { |
| 896 | + final SqsException sqsException = mock(SqsException.class); |
| 897 | + when(sqsException.statusCode()).thenReturn(404); |
| 898 | + when(sqsClient.receiveMessage(any(ReceiveMessageRequest.class))).thenThrow(sqsException); |
| 899 | + |
| 900 | + final Counter queueNotFoundCounter = mock(Counter.class); |
| 901 | + when(pluginMetrics.counter(SqsWorker.SQS_QUEUE_NOT_FOUND_METRIC_NAME)).thenReturn(queueNotFoundCounter); |
| 902 | + lenient().when(pluginMetrics.counter(anyString())).thenReturn(mock(Counter.class)); |
| 903 | + |
| 904 | + final SqsWorker sqsWorker = createObjectUnderTest(); |
| 905 | + sqsWorker.run(); |
| 906 | + |
| 907 | + verify(queueNotFoundCounter).increment(); |
| 908 | + } |
| 909 | + |
| 910 | + @Test |
| 911 | + void run_increments_throttled_metric_on_throttling_exception() { |
| 912 | + final SqsException sqsException = mock(SqsException.class); |
| 913 | + when(sqsException.isThrottlingException()).thenReturn(true); |
| 914 | + when(sqsClient.receiveMessage(any(ReceiveMessageRequest.class))).thenThrow(sqsException); |
| 915 | + |
| 916 | + final Counter throttledCounter = mock(Counter.class); |
| 917 | + when(pluginMetrics.counter(SqsWorker.SQS_MESSAGE_THROTTLED_METRIC_NAME)).thenReturn(throttledCounter); |
| 918 | + lenient().when(pluginMetrics.counter(anyString())).thenReturn(mock(Counter.class)); |
| 919 | + |
| 920 | + final SqsWorker sqsWorker = createObjectUnderTest(); |
| 921 | + sqsWorker.run(); |
| 922 | + |
| 923 | + verify(throttledCounter).increment(); |
| 924 | + } |
| 925 | + |
869 | 926 | private static String createSecurityLakeNotification(final Instant startTime) { |
870 | 927 | return "{\"source\":\"aws.s3\",\"time\":\"" + startTime + "\",\"account\":\"123456789012\",\"region\":\"ca-central-1\"," + |
871 | 928 | "\"resources\":[\"arn:aws:s3:::example-bucket\"],\"detail\":{\"bucket\":{\"name\":\"example-bucket\"}," + |
|
0 commit comments