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) {
}
}
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());
}
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);
}
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());
}
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());
}
Aggregations