Search in sources :

Example 11 with InternalEvent

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

the class IpcSenderServiceTest method testBufferFlush.

@Test
public void testBufferFlush() 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);
    /*
     * Create 12 events. Every 5 adds a send should happen.
     */
    ArrayList<InternalEvent> sent = new ArrayList<InternalEvent>();
    for (int i = 0; i < 12; i++) {
        InternalEvent ie = new DummyEvent("" + i, 0);
        ie.setPartitions(new LinkedHashMap(0));
        sent.add(ie);
        ipc.add(ie);
    }
    /*
     * Flush anything left in the buffer
     */
    ipc.shutdown();
    /*
     * Verify expected calls
     */
    verify(mockDummyTransporter, times(1)).sendBatch(new DummyTransportBuffer(sent.subList(0, 5)));
    verify(mockDummyTransporter, times(1)).sendBatch(new DummyTransportBuffer(sent.subList(5, 10)));
    verify(mockDummyTransporter, times(1)).sendBatch(new DummyTransportBuffer(sent.subList(10, 12)));
}
Also used : ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 12 with InternalEvent

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

the class PartitionOperationTest method testGetEvaluatedPartitionsString.

@Test
public void testGetEvaluatedPartitionsString() {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("foo");
    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("baz").when(devent).getField("foo");
    op.perform(ievent);
    LinkedHashMap<String, String> actual = ievent.getPartitions();
    LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
    expected.put("foo", "baz");
    assertEquals(expected, actual);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 13 with InternalEvent

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

the class GeoIpOperationTest method testInvalidIpRequired.

@Test(expected = UnknownHostException.class)
public void testInvalidIpRequired() throws Throwable {
    GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
    DummpyEvent devent = new DummpyEvent();
    devent.setField("ip_address", "noanip");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    try {
        op.perform(ievent);
    } catch (OperationException e) {
        throw e.getCause();
    }
}
Also used : OperationException(com.nextdoor.bender.operation.OperationException) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 14 with InternalEvent

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

the class GeoIpOperationTest method testKnownIpLocation.

@Test
public void testKnownIpLocation() throws Throwable {
    GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
    DummpyEvent devent = new DummpyEvent();
    devent.setField("ip_address", "5.5.5.5");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    HashMap<String, Object> expected = new HashMap<String, Object>();
    expected.put("ip_address", "5.5.5.5");
    HashMap<String, Object> expectedLoc = new HashMap<String, Object>();
    expectedLoc.put("lat", new Double("51.75"));
    expectedLoc.put("lon", new Double("2.25"));
    Map<String, Object> expectedGeo = new HashMap<String, Object>();
    expectedGeo.put("location", expectedLoc);
    expected.put("geo_ip", expectedGeo);
    assertEquals(expected, ievent.getEventObj().getPayload());
}
Also used : HashMap(java.util.HashMap) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 15 with InternalEvent

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

the class GeoIpOperationFactoryTest method testFactoryCreated.

@Test
public void testFactoryCreated() {
    GeoIpOperationConfig config = new GeoIpOperationConfig();
    config.setDstFieldName("test");
    config.setFailOnNotFound(false);
    config.setGeoLiteDb("s3://" + BUCKET + "/my-ip-data.mmdb");
    config.setSrcFieldName("ip_address");
    config.setGeoProperties(Arrays.asList(GeoProperty.COUNTRY_NAME, GeoProperty.COUNTRY_ISO_CODE, GeoProperty.SUBDIVISION_NAME, GeoProperty.SUBDIVISION_ISO_CODE, GeoProperty.CITY_NAME, GeoProperty.POSTAL_CODE, GeoProperty.LOCATION));
    this.opFactory.setConf(config);
    GeoIpOperation op = this.opFactory.newInstance();
    DummpyEvent devent = new DummpyEvent();
    devent.setField("ip_address", "5.5.5.5");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    HashMap<String, Object> expected = new HashMap<String, Object>();
    expected.put("ip_address", "5.5.5.5");
    HashMap<String, Object> expectedLoc = new HashMap<String, Object>();
    expectedLoc.put("lat", new Double("51.75"));
    expectedLoc.put("lon", new Double("2.25"));
    Map<String, Object> expectedGeo = new HashMap<String, Object>();
    expectedGeo.put("location", expectedLoc);
    expectedGeo.put("country_name", "Eriador");
    expectedGeo.put("country_iso_code", "ER");
    expectedGeo.put("subdivision_name", "Rivendell");
    expectedGeo.put("subdivision_iso_code", "ENG");
    expectedGeo.put("city_name", "Rivendell");
    expectedGeo.put("postal_code", "1234");
    expected.put("test", expectedGeo);
    assertEquals(expected, ievent.getEventObj().getPayload());
}
Also used : HashMap(java.util.HashMap) DummpyEvent(com.nextdoor.bender.operations.geo.GeoIpOperationTest.DummpyEvent) 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