-
DynamoDB에서 Error Injectiondevelop 2022. 9. 1. 14:00
DynamoDB에서 Test를 수행 할 때에 Error를 주입해서 동작을 확인해야 할 때가 있습니다. 대표적으로 ThrottlingException 처럼 발생할 가능성이 높은 에러들은 미리 확인해야 하죠.
관련해서 2013년에 AWS Blog에 올라왔던 Injecting Failures and Latency using the AWS SDK for Java 의 방법이 다른 모듈에 의존성 없이 적용할 수 있습니다. 문제는 해당 Source가 2013년 기준으로, 여기서 사용했던 RequestHandler는 deprecate 되어서 RequestHandler2가 되었고, 더더욱 최신 AWS Java SDK v2에서는 해당 Class가 아예 없어져서 적용할 수 없네요.
찾아보니 ClientOverrideConfiguration을 통해서 이전과 동일하게 등록 가능합니다.
boolean throttleDynamoDb = false; @Bean DynamoDbClient dynamoDbClient(AwsProperties awsProperties) { return DynamoDbClient.builder() ... .overrideConfiguration( ClientOverrideConfiguration.builder() .addExecutionInterceptor(new DynamoDbBehavior()) .build() ) .build(); } class DynamoDbBehavior implements ExecutionInterceptor { @Override public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) { if (throttleDynamoDb) { throw ProvisionedThroughputExceededException.builder().message("injected").build(); } return ExecutionInterceptor.super.modifyRequest(context, executionAttributes); } }
위와 같이 등록 가능하고, throttleDynamoDb 변수를 통해서 throttling exception이 발생하는 지를 조절 가능합니다.
자세한 코드는 https://github.com/earthfall/TestServer/pull/9 을 참고하세요.
'develop' 카테고리의 다른 글
Kubernetes에서 node 내 thread 분리 이슈 (0) 2023.08.20 Ref: Sync 10,000 Argo CD Applications in One Shot (0) 2023.06.29 Spring Cloud Config (0) 2023.05.01 openssl 1.0.2에서 untrusted chain 문제 (0) 2022.11.06 Android Chrome Custom Tab 닫기 (0) 2021.09.26