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