use of software.amazon.awssdk.services.s3.S3ClientBuilder in project fluency by komamitsu.
the class AwsS3SenderTest method close.
@Test
void close() {
S3Client s3Client = mock(S3Client.class);
S3ClientBuilder s3ClientBuilder = mock(S3ClientBuilder.class);
doReturn(s3Client).when(s3ClientBuilder).build();
AwsS3Sender sender = new AwsS3Sender(s3ClientBuilder);
sender.close();
verify(s3Client, times(1)).close();
}
use of software.amazon.awssdk.services.s3.S3ClientBuilder in project fluency by komamitsu.
the class AwsS3SenderTest method testSend.
private void testSend(AwsS3Sender.Config config, boolean gzipCompressed, int failures) throws IOException {
S3Client s3Client = mock(S3Client.class);
S3ClientBuilder s3ClientBuilder = mock(S3ClientBuilder.class);
doReturn(s3Client).when(s3ClientBuilder).build();
AtomicInteger retryCount = new AtomicInteger();
doAnswer(invocation -> {
PutObjectRequest request = invocation.getArgument(0);
assertEquals("hello.world", request.bucket());
assertEquals("2345/01/31/23/59-59-99999.data", request.key());
RequestBody body = invocation.getArgument(1);
try (InputStream s3In = body.contentStreamProvider().newStream();
InputStream in = gzipCompressed ? new GZIPInputStream(s3In) : s3In) {
byte[] content = ByteStreams.toByteArray(in);
assertEquals("0123456789", new String(content, StandardCharsets.UTF_8));
}
if (retryCount.getAndIncrement() < failures) {
throw new RuntimeException("Something happened");
}
return null;
}).when(s3Client).putObject(any(PutObjectRequest.class), any(RequestBody.class));
AwsS3Sender sender = new AwsS3Sender(s3ClientBuilder, config);
sender.send("hello.world", "2345/01/31/23/59-59-99999.data", ByteBuffer.wrap("0123456789".getBytes(StandardCharsets.UTF_8)));
verify(s3Client, times(failures + 1)).putObject(any(PutObjectRequest.class), any(RequestBody.class));
sender.close();
}
use of software.amazon.awssdk.services.s3.S3ClientBuilder in project fluency by komamitsu.
the class AwsS3SenderTest method buildClientWithCustomizedConfig.
@Test
void buildClientWithCustomizedConfig() {
AwsS3Sender.Config config = new AwsS3Sender.Config();
config.setEndpoint("https://another.s3endpoi.nt");
config.setRegion("ap-northeast-1");
config.setAwsAccessKeyId("foo");
config.setAwsSecretAccessKey("bar");
S3Client s3Client = mock(S3Client.class);
S3ClientBuilder s3ClientBuilder = mock(S3ClientBuilder.class);
doReturn(s3Client).when(s3ClientBuilder).build();
doAnswer(invocation -> {
AwsCredentialsProvider provider = invocation.getArgument(0);
AwsCredentials awsCredentials = provider.resolveCredentials();
assertEquals("foo", awsCredentials.accessKeyId());
assertEquals("bar", awsCredentials.secretAccessKey());
return null;
}).when(s3ClientBuilder).credentialsProvider(any());
new AwsS3Sender(s3ClientBuilder, config);
verify(s3ClientBuilder, times(1)).build();
verify(s3ClientBuilder, times(1)).endpointOverride(eq(URI.create("https://another.s3endpoi.nt")));
verify(s3ClientBuilder, times(1)).region(eq(Region.AP_NORTHEAST_1));
verify(s3ClientBuilder, times(1)).credentialsProvider(any());
}
use of software.amazon.awssdk.services.s3.S3ClientBuilder in project fluency by komamitsu.
the class AwsS3SenderTest method buildClientWithDefaults.
@Test
void buildClientWithDefaults() {
AwsS3Sender.Config config = new AwsS3Sender.Config();
S3Client s3Client = mock(S3Client.class);
S3ClientBuilder s3ClientBuilder = mock(S3ClientBuilder.class);
doReturn(s3Client).when(s3ClientBuilder).build();
new AwsS3Sender(s3ClientBuilder, config);
verify(s3ClientBuilder, times(1)).build();
verify(s3ClientBuilder, times(0)).endpointOverride(any());
verify(s3ClientBuilder, times(0)).region(any());
verify(s3ClientBuilder, times(0)).credentialsProvider(any());
}
Aggregations