use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class LowerCaseKeyMutatorTest method testMutatePayload.
@Test
public void testMutatePayload() throws JsonSyntaxException, IOException, OperationException {
JsonParser parser = new JsonParser();
JsonElement input = parser.parse(getResourceString("basic_input_case.json"));
String expectedOutput = getResourceString("basic_output_case.json");
DummpyEvent devent = new DummpyEvent();
devent.payload = input.getAsJsonObject();
LowerCaseKeyOperation operation = new LowerCaseKeyOperation();
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
operation.perform(ievent);
assertEquals(expectedOutput, input.toString());
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class IpcSenderServiceTest method testPartitionedTransport.
@Test
public void testPartitionedTransport() throws InterruptedException, TransportException {
/*
* Create a transport factory and dummy transporter
*/
DummyTransporter mockDummyTransporter = mock(DummyTransporter.class);
DummyTransporterFactory tfactory = new DummyTransporterFactory();
tfactory.transporter = mockDummyTransporter;
IpcSenderService ipc = new IpcSenderService(tfactory);
ArrayList<InternalEvent> sent1 = new ArrayList<InternalEvent>();
ArrayList<InternalEvent> sent2 = new ArrayList<InternalEvent>();
/*
* Write 3 events to partition test1
*/
LinkedHashMap<String, String> part1 = new LinkedHashMap<String, String>(1);
part1.put("p1", "test1");
for (int i = 0; i < 3; i++) {
InternalEvent ie = new DummyEvent("" + i, 0, part1);
sent1.add(ie);
ipc.add(ie);
}
/*
* Write 5 events to partition test2
*/
LinkedHashMap<String, String> part2 = new LinkedHashMap<String, String>(1);
part2.put("p1", "test2");
for (int i = 0; i < 5; i++) {
InternalEvent ie = new DummyEvent("" + i, 0, part2);
sent2.add(ie);
ipc.add(ie);
}
/*
* Write 2 events to partition test1 again
*/
LinkedHashMap<String, String> part3 = new LinkedHashMap<String, String>(1);
part3.put("p1", "test1");
for (int i = 0; i < 2; i++) {
InternalEvent ie = new DummyEvent("" + i, 0, part3);
sent1.add(ie);
ipc.add(ie);
}
/*
* Flush anything left in the buffer
*/
ipc.shutdown();
/*
* Verify expected calls
*/
verify(mockDummyTransporter, times(1)).sendBatch(new DummyTransportBuffer(sent1.subList(0, 5)));
verify(mockDummyTransporter, times(1)).sendBatch(new DummyTransportBuffer(sent2.subList(0, 5)));
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class SubstitutionOperationTest method testUnknownField.
@Test
public void testUnknownField() {
ArrayList<SubstitutionSpec> subSpecs = new ArrayList<SubstitutionSpec>();
subSpecs.add(new SubstitutionSpec("bar", "foo", Interpreter.FIELD));
DummpyEvent devent = new DummpyEvent();
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(subSpecs);
op.perform(ievent);
assertEquals(null, devent.getField("bar"));
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class SubstitutionOperationTest method testStaticField.
@Test
public void testStaticField() {
ArrayList<SubstitutionSpec> subSpecs = new ArrayList<SubstitutionSpec>();
subSpecs.add(new SubstitutionSpec("foo", "1234", Interpreter.STATIC));
DummpyEvent devent = new DummpyEvent();
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(subSpecs);
op.perform(ievent);
assertEquals("1234", devent.getField("foo"));
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class StdoutTransportTest method testStdout.
@Test
public void testStdout() throws IllegalStateException, IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
System.setOut(new PrintStream(bo));
StdoutTransport transport = new StdoutTransport();
GenericTransportBuffer buf = new GenericTransportBuffer(1, false, new StdoutTransportSerializer());
InternalEvent event = new InternalEvent("junk", new TestContext(), 123);
event.setSerialized("junk");
buf.add(event);
transport.sendBatch(buf);
bo.flush();
String allWrittenLines = new String(bo.toByteArray());
assertEquals("junk\n", allWrittenLines);
}
Aggregations