Search in sources :

Example 36 with InternalEvent

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());
}
Also used : LowerCaseKeyOperation(com.nextdoor.bender.operation.json.key.LowerCaseKeyOperation) JsonElement(com.google.gson.JsonElement) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 37 with InternalEvent

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)));
}
Also used : ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 38 with InternalEvent

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"));
}
Also used : ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 39 with InternalEvent

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"));
}
Also used : ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 40 with InternalEvent

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);
}
Also used : PrintStream(java.io.PrintStream) TestContext(com.nextdoor.bender.aws.TestContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

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