Search in sources :

Example 56 with InternalEvent

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

Example 57 with InternalEvent

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

Example 58 with InternalEvent

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());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestContext(com.nextdoor.bender.aws.TestContext) UploadPartRequest(com.amazonaws.services.s3.model.UploadPartRequest) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Test(org.junit.Test)

Example 59 with InternalEvent

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;
    }
}
Also used : InitiateMultipartUploadResult(com.amazonaws.services.s3.model.InitiateMultipartUploadResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AmazonClientException(com.amazonaws.AmazonClientException) TestContext(com.nextdoor.bender.aws.TestContext) InitiateMultipartUploadRequest(com.amazonaws.services.s3.model.InitiateMultipartUploadRequest) UploadPartRequest(com.amazonaws.services.s3.model.UploadPartRequest) TransportException(com.nextdoor.bender.ipc.TransportException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) UploadPartResult(com.amazonaws.services.s3.model.UploadPartResult) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Test(org.junit.Test)

Example 60 with InternalEvent

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);
}
Also used : 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