use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class TcpTransportBufferTest method clearShouldEmptyBuffer.
@Test
public void clearShouldEmptyBuffer() {
TransportSerializer serializer = mock(TransportSerializer.class);
TcpTransportBuffer buffer = new TcpTransportBuffer(10L, serializer);
InternalEvent event = new InternalEvent("", null, 0);
byte[] bytes = "foo".getBytes();
when(serializer.serialize(eq(event))).thenReturn(bytes);
assertTrue(buffer.add(event));
assertEquals(bytes.length, buffer.getInternalBuffer().size());
assertFalse(buffer.isEmpty());
buffer.clear();
assertEquals(0L, buffer.getInternalBuffer().size());
assertTrue(buffer.isEmpty());
assertTrue(buffer.add(event));
assertEquals(bytes.length, buffer.getInternalBuffer().size());
assertFalse(buffer.isEmpty());
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class TimeOperationTest method testInvalidTime.
@Test(expected = OperationException.class)
public void testInvalidTime() {
InternalEvent ievent = new InternalEvent("foo", null, 1);
DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
ievent.setEventObj(devent);
doReturn("-1").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 PartitionOperationTest method testGetEvaluatedPartitionsNoSuchElementException.
@Test
public void testGetEvaluatedPartitionsNoSuchElementException() {
List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
List<String> sources = Arrays.asList("one");
PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
partitionSpecs.add(spec);
PartitionOperation op = new PartitionOperation(partitionSpecs);
InternalEvent ievent = new InternalEvent("foo", null, 1);
DummyDeserializedEvent devent = spy(new DummyDeserializedEvent("baz"));
ievent.setEventObj(devent);
doThrow(new NoSuchElementException()).when(devent).getField(any());
op.perform(ievent);
LinkedHashMap<String, String> actual = ievent.getPartitions();
LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
expected.put("foo", null);
assertEquals(expected, actual);
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class PartitionOperationTest method testGetEvaluatedPartitionsStringMultipleFields.
@Test
public void testGetEvaluatedPartitionsStringMultipleFields() {
List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
List<String> sources = Arrays.asList("one", "two");
PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
partitionSpecs.add(spec);
PartitionOperation op = new PartitionOperation(partitionSpecs);
InternalEvent ievent = new InternalEvent("foo", null, 1);
DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
ievent.setEventObj(devent);
doReturn(null).doReturn("5").when(devent).getField(any());
op.perform(ievent);
LinkedHashMap<String, String> actual = ievent.getPartitions();
LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
expected.put("foo", "5");
assertEquals(expected, actual);
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class PartitionOperationTest method testGetEvaluatedPartitionsStringMultipleFieldsNull.
@Test
public void testGetEvaluatedPartitionsStringMultipleFieldsNull() {
List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
List<String> sources = Arrays.asList("one", "two");
PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
partitionSpecs.add(spec);
PartitionOperation op = new PartitionOperation(partitionSpecs);
InternalEvent ievent = new InternalEvent("foo", null, 1);
DummyDeserializedEvent devent = spy(new DummyDeserializedEvent("baz"));
ievent.setEventObj(devent);
doReturn(null).doReturn(null).when(devent).getField(any());
op.perform(ievent);
LinkedHashMap<String, String> actual = ievent.getPartitions();
LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
expected.put("foo", null);
assertEquals(expected, actual);
}
Aggregations