Skip to content

Commit

Permalink
Add AwsS3IngesterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu committed Apr 15, 2019
1 parent b4c6b2d commit 4bda432
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public class AwsS3Ingester
private final AwsS3Sender sender;
private final S3DestinationDecider s3DestinationDecider;

public AwsS3Ingester(AwsS3Sender sender, S3DestinationDecider s3DestinationDecider)
{
this(new Config(), sender, s3DestinationDecider);
}

public AwsS3Ingester(Config config, AwsS3Sender sender, S3DestinationDecider s3DestinationDecider)
{
config.validateValues();
Expand Down Expand Up @@ -69,7 +64,6 @@ public Sender getSender()

@Override
public void close()
throws IOException
{
sender.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2019 Mitsunori Komatsu (komamitsu)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.komamitsu.fluency.aws.s3.ingester;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.komamitsu.fluency.aws.s3.ingester.sender.AwsS3Sender;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Instant;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

class AwsS3IngesterTest
{
private AwsS3Sender s3Sender;
private S3DestinationDecider destinationDecider;
private AwsS3Ingester ingester;

@BeforeEach
void setUp()
{
s3Sender = mock(AwsS3Sender.class);

destinationDecider = mock(S3DestinationDecider.class);
doReturn(new S3DestinationDecider.S3Destination("mybucket", "my/key/base"))
.when(destinationDecider).decide(anyString(), any(Instant.class));

AwsS3Ingester.Config config = new AwsS3Ingester.Config();
config.setKeySuffix(".xyz");
ingester = new AwsS3Ingester(config, s3Sender, destinationDecider);
}

@Test
void ingest()
throws IOException
{
ingester.ingest("foo.bar",
ByteBuffer.wrap("hello, world".getBytes(StandardCharsets.UTF_8)));

verify(s3Sender, times(1))
.send(eq("mybucket"),
eq("my/key/base.xyz"),
eq(ByteBuffer.wrap("hello, world".getBytes(StandardCharsets.UTF_8))));
}

@Test
void close()
{
ingester.close();

verify(s3Sender, times(1)).close();
}
}

0 comments on commit 4bda432

Please sign in to comment.