Search in sources :

Example 61 with InternalEvent

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

the class ElasticSearchTansportSerializerTest method testSerializeDateIndexName.

@Test
public void testSerializeDateIndexName() throws UnsupportedEncodingException, IOException {
    ElasticSearchTransportSerializer serializer = new ElasticSearchTransportSerializer(false, "event", "log-", "yyyy-MM-dd", false);
    KinesisEvent kevent = TestUtils.createEvent(this.getClass(), "basic_event.json");
    String payload = new String(kevent.getRecords().get(0).getKinesis().getData().array());
    InternalEvent record = new DummyEvent(payload, 1478737790000l);
    String actual = new String(serializer.serialize(record));
    String expected = TestUtils.getResourceString(this.getClass(), "datetime_output.txt");
    assertEquals(expected, actual);
}
Also used : KinesisEvent(com.amazonaws.services.lambda.runtime.events.KinesisEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 62 with InternalEvent

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

the class ElasticSearchTansportSerializerTest method testSerialize.

@Test
public void testSerialize() throws UnsupportedEncodingException, IOException {
    ElasticSearchTransportSerializer serializer = new ElasticSearchTransportSerializer(false, "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_output.txt");
    /*
     * Verify build output does not contain hash
     */
    assertEquals(expected, actual);
}
Also used : InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 63 with InternalEvent

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

the class S3TransportBufferTest method testBz2.

@Test
public void testBz2() throws IOException, TransportException {
    S3TransportSerializer serializer = mock(S3TransportSerializer.class);
    doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class));
    S3TransportBuffer buffer = new S3TransportBuffer(100, true, serializer);
    InternalEvent mockEvent = mock(InternalEvent.class);
    buffer.add(mockEvent);
    buffer.close();
    byte[] actual = buffer.getInternalBuffer().toByteArray();
    byte[] expected = { 66, 90, 104, 57, 49, 65, 89, 38, 83, 89, 73, -2, -60, -91, 0, 0, 0, 1, 0, 1, 0, -96, 0, 48, -128, 65, 22, 46, -28, -118, 112, -95, 32, -109, -3, -119, 74 };
    assertArrayEquals(expected, actual);
}
Also used : InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 64 with InternalEvent

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

the class S3TransportBufferTest method testAddBufferFull.

@Test(expected = IllegalStateException.class)
public void testAddBufferFull() throws IOException, TransportException {
    S3TransportSerializer serializer = mock(S3TransportSerializer.class);
    doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class));
    S3TransportBuffer buffer = new S3TransportBuffer(5, false, serializer);
    InternalEvent mockEvent = mock(InternalEvent.class);
    buffer.add(mockEvent);
    buffer.add(mockEvent);
}
Also used : InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 65 with InternalEvent

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

the class GenericTansportSerializerTest method testSerialize.

@Test
public void testSerialize() throws UnsupportedEncodingException, IOException {
    GenericTransportSerializer serializer = new GenericTransportSerializer();
    InternalEvent record = new DummyEvent("foo", 0);
    record.setEventTime(1505927823123l);
    record.setSerialized("foo");
    String actual = new String(serializer.serialize(record));
    String expected = TestUtils.getResourceString(this.getClass(), "basic_output.txt");
    assertEquals(expected, actual);
}
Also used : GenericTransportSerializer(com.nextdoor.bender.ipc.generic.GenericTransportSerializer) 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