use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class GeoIpOperationTest method testIpList.
@Test
public void testIpList() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
DummpyEvent devent = new DummpyEvent();
devent.setField("ip_address", "5.5.5.5, 10.10.10.10");
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, 10.10.10.10");
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 GeoIpOperationTest method testAllKnownFields.
@Test
public void testAllKnownFields() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.COUNTRY_NAME, GeoProperty.COUNTRY_ISO_CODE, GeoProperty.SUBDIVISION_NAME, GeoProperty.SUBDIVISION_ISO_CODE, GeoProperty.CITY_NAME, GeoProperty.POSTAL_CODE, 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);
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("geo_ip", expectedGeo);
assertEquals(expected, ievent.getEventObj().getPayload());
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class S3TransporterTest method testGzFilename.
@Test
public void testGzFilename() throws TransportException, IllegalStateException, IOException {
/*
* Create mock client, requests, and replies
*/
AmazonS3Client mockClient = getMockClient();
/*
* Fill buffer with mock data
*/
S3TransportBuffer buffer = new S3TransportBuffer(1000, true, new S3TransportSerializer());
InternalEvent mockIevent = mock(InternalEvent.class);
doReturn("foo").when(mockIevent).getSerialized();
/*
* Create transport
*/
Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
S3Transport transport = new S3Transport(mockClient, "bucket", "basepath/", true, multiPartUploads);
/*
* Do actual test
*/
buffer.add(mockIevent);
LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
partitions.put(S3Transport.FILENAME_KEY, "a_filename.gz");
ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
transport.sendBatch(buffer, partitions, new TestContext());
verify(mockClient).uploadPart(argument.capture());
/*
* Check results
*/
assertEquals("basepath/a_filename.bz2", argument.getValue().getKey());
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class S3TransporterTest method testAmazonClientException.
@Test(expected = TransportException.class)
public void testAmazonClientException() throws TransportException, IllegalStateException, IOException {
/*
* Create mock client, requets, and replies
*/
AmazonS3Client mockClient = mock(AmazonS3Client.class);
UploadPartResult uploadResult = new UploadPartResult();
uploadResult.setETag("foo");
doThrow(new AmazonClientException("expected")).when(mockClient).uploadPart(any(UploadPartRequest.class));
InitiateMultipartUploadResult initUploadResult = new InitiateMultipartUploadResult();
initUploadResult.setUploadId("123");
doReturn(initUploadResult).when(mockClient).initiateMultipartUpload(any(InitiateMultipartUploadRequest.class));
/*
* Fill buffer with mock data
*/
S3TransportBuffer buffer = new S3TransportBuffer(1000, false, new S3TransportSerializer());
InternalEvent mockIevent = mock(InternalEvent.class);
doReturn("foo").when(mockIevent).getSerialized();
/*
* Create transport
*/
Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
S3Transport transport = new S3Transport(mockClient, "bucket", "basepath", false, multiPartUploads);
/*
* Do actual test
*/
buffer.add(mockIevent);
LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
partitions.put(S3Transport.FILENAME_KEY, "a_filename");
ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
try {
transport.sendBatch(buffer, partitions, new TestContext());
} catch (Exception e) {
assertEquals(e.getCause().getClass(), AmazonClientException.class);
throw e;
}
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class ElasticSearchTansportSerializerTest method testSerializeWithHash.
@Test
public void testSerializeWithHash() throws UnsupportedEncodingException, IOException {
ElasticSearchTransportSerializer serializer = new ElasticSearchTransportSerializer(true, "event", "log", false);
InternalEvent record = new DummyEvent("foo", 0);
record.setSerialized("foo");
String actual = new String(serializer.serialize(record));
String expected = TestUtils.getResourceString(this.getClass(), "basic_hash_output.txt");
/*
* Verify build output does contain hash
*/
assertEquals(expected, actual);
}
Aggregations