Search in sources :

Example 31 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class TcpTransportBufferTest method shouldThrowIfBufferSizeOverflow.

@Test
public void shouldThrowIfBufferSizeOverflow() {
    TransportSerializer serializer = mock(TransportSerializer.class);
    TcpTransportBuffer buffer = new TcpTransportBuffer(10L, serializer);
    InternalEvent event = new InternalEvent("", null, 0);
    byte[] bytes = "123456789".getBytes();
    when(serializer.serialize(eq(event))).thenReturn(bytes);
    assertTrue(buffer.add(event));
    assertEquals(bytes.length, buffer.getInternalBuffer().size());
    try {
        buffer.add(event);
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException ex) {
    }
}
Also used : TransportSerializer(com.nextdoor.bender.ipc.TransportSerializer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 32 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class TimeOperationTest method testValidTime.

@Test
public void testValidTime() {
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
    ievent.setEventObj(devent);
    doReturn("1504728473").when(devent).getField("foo");
    TimeOperation op = new TimeOperation("foo", TimeFieldType.SECONDS);
    op.perform(ievent);
    assertEquals(1504728473000l, ievent.getEventTime());
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 33 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class TimeOperationTest method testNullField.

@Test(expected = OperationException.class)
public void testNullField() {
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
    ievent.setEventObj(devent);
    doReturn(null).when(devent).getField("foo");
    TimeOperation op = new TimeOperation("foo", TimeFieldType.SECONDS);
    op.perform(ievent);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 34 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class JsonRootNodeMutatorTest method testMutateRootNode.

@Test
public void testMutateRootNode() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
    JsonParser parser = new JsonParser();
    JsonElement input = parser.parse(getResourceString("basic_input.json"));
    DummpyEvent devent = new DummpyEvent();
    devent.payload = input.getAsJsonObject();
    JsonRootNodeOperationFactory f = new JsonRootNodeOperationFactory();
    JsonRootNodeOperation operation = new JsonRootNodeOperation("$.i.ia");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    operation.perform(ievent);
    assertEquals("{\"iaa\":\"bar\"}", devent.payload.toString());
}
Also used : JsonRootNodeOperationFactory(com.nextdoor.bender.operation.json.key.JsonRootNodeOperationFactory) JsonElement(com.google.gson.JsonElement) JsonRootNodeOperation(com.nextdoor.bender.operation.json.key.JsonRootNodeOperation) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 35 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class KeyNameMutatorTest method testMutatePayload.

@Test
public void testMutatePayload() throws JsonSyntaxException, IOException, OperationException {
    JsonParser parser = new JsonParser();
    JsonElement input = parser.parse(getResourceString("basic_input.json"));
    String expectedOutput = getResourceString("basic_output_key_name.json");
    DummpyEvent devent = new DummpyEvent();
    devent.payload = input.getAsJsonObject();
    KeyNameOperation operation = new KeyNameOperation();
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    operation.perform(ievent);
    assertEquals(expectedOutput, input.toString());
}
Also used : JsonElement(com.google.gson.JsonElement) KeyNameOperation(com.nextdoor.bender.operation.json.key.KeyNameOperation) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)68 Test (org.junit.Test)67 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 TestContext (com.nextdoor.bender.aws.TestContext)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)9 DummyDeserializedEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent)9 JsonElement (com.google.gson.JsonElement)7 JsonParser (com.google.gson.JsonParser)7 OperationTest (com.nextdoor.bender.operations.json.OperationTest)7 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)6 GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)5 GenericTransportSerializer (com.nextdoor.bender.ipc.generic.GenericTransportSerializer)5 DummyOperation (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation)4 UploadPartResult (com.amazonaws.services.s3.model.UploadPartResult)3 Stat (com.nextdoor.bender.monitoring.Stat)3 KeyNameOperation (com.nextdoor.bender.operation.json.key.KeyNameOperation)3 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)3