use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerTest method testOperationException.
@Test
public void testOperationException() throws HandlerException {
BaseHandler.CONFIG_FILE = "/config/handler_config.json";
handler.skipWriteStats = true;
List<DummyEvent> events = new ArrayList<DummyEvent>(1);
events.add(new DummyEvent("foo", 0));
TestContext context = new TestContext();
context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
handler.init(context);
List<OperationProcessor> operationProcessors = handler.sources.get(0).getOperationProcessors();
for (OperationProcessor operationProcessor : operationProcessors) {
BaseOperation operation = spy(operationProcessor.getOperation());
doThrow(new OperationException("expected")).when(operation).perform(any());
operationProcessor.setOperation(operation);
}
handler.handler(events, context);
assertEquals(1, operationProcessors.get(0).getErrorCountStat().getValue());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerTest method testTagConfig.
@Test
public void testTagConfig() throws HandlerException {
List<DummyEvent> events = new ArrayList<DummyEvent>(1);
TestContext context = new TestContext();
context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:staging");
handler.handler(events, context);
assertEquals("/config/staging.json", handler.config.getConfigFile());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerTest method testGeneralTransportExceptionOnShutdown.
@Test(expected = TransportException.class)
public void testGeneralTransportExceptionOnShutdown() throws Throwable {
BaseHandler.CONFIG_FILE = "/config/handler_config.json";
List<DummyEvent> events = new ArrayList<DummyEvent>(1);
events.add(new DummyEvent("foo", 0));
TestContext context = new TestContext();
context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
handler.init(context);
IpcSenderService spy = spy(handler.getIpcService());
handler.setIpcService(spy);
doThrow(new TransportException("expected")).when(spy).shutdown();
try {
handler.handler(events, context);
} catch (Exception e) {
throw e.getCause().getCause();
}
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerTest method testEndToEndWithNoOperations.
@Test
public void testEndToEndWithNoOperations() throws HandlerException {
BaseHandler.CONFIG_FILE = "/config/handler_config_no_operations.json";
List<DummyEvent> events = new ArrayList<DummyEvent>(2);
events.add(new DummyEvent("foo", 0));
events.add(new DummyEvent("bar", 0));
TestContext context = new TestContext();
context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
handler.handler(events, context);
/*
* Verify Events made it all the way through
*/
assertEquals(2, BufferedTransporter.output.size());
assertEquals("foo", BufferedTransporter.output.get(0));
assertEquals("bar", BufferedTransporter.output.get(1));
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class S3TransporterTest method testUnpartitioned.
@Test
public void testUnpartitioned() throws TransportException, IllegalStateException, IOException {
/*
* Create mock client, requets, and replies
*/
AmazonS3Client mockClient = getMockClient();
/*
* Fill buffer with mock data
*/
S3TransportBuffer buffer = new S3TransportBuffer(1000, false, new S3TransportSerializer());
InternalEvent mockIevent = mock(InternalEvent.class);
doReturn("foo").when(mockIevent).getSerialized();
/*
* Create transport
*/
Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
S3Transport transport = new S3Transport(mockClient, "bucket", "basepath", false, multiPartUploads);
/*
* Do actual test
*/
buffer.add(mockIevent);
LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
partitions.put(S3Transport.FILENAME_KEY, "a_filename");
ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
transport.sendBatch(buffer, partitions, new TestContext());
verify(mockClient).uploadPart(argument.capture());
/*
* Check results
*/
assertEquals("bucket", argument.getValue().getBucketName());
assertEquals("basepath/a_filename", argument.getValue().getKey());
assertEquals(1, argument.getValue().getPartNumber());
// foo\n
assertEquals(4, argument.getValue().getPartSize());
assertEquals("123", argument.getValue().getUploadId());
}
Aggregations