Search in sources :

Example 1 with KinesisEvent

use of com.amazonaws.services.lambda.runtime.events.KinesisEvent in project bender by Nextdoor.

the class TestUtils method createEvent.

public static KinesisEvent createEvent(Class clazz, String resource) throws UnsupportedEncodingException, IOException {
    /*
     * Create a kinesis record from a sample JSON file
     */
    String json = IOUtils.toString(new InputStreamReader(clazz.getResourceAsStream(resource), "UTF-8"));
    Date approximateArrivalTimestamp = new Date();
    approximateArrivalTimestamp.setTime(1478737790000l);
    Record rec = new Record();
    rec.withPartitionKey("1").withSequenceNumber("2").withData(ByteBuffer.wrap(json.getBytes())).withApproximateArrivalTimestamp(approximateArrivalTimestamp);
    /*
     * Create a KinesisEventRecord and add single Record
     */
    KinesisEventRecord krecord = new KinesisEventRecord();
    krecord.setKinesis(rec);
    krecord.setEventSourceARN("arn:aws:kinesis:us-east-1:1234:stream/test-events-stream");
    krecord.setEventID("shardId-000000000000:1234");
    /*
     * Add single KinesisEventRecord to a KinesisEvent
     */
    KinesisEvent kevent = new KinesisEvent();
    List<KinesisEventRecord> events = new ArrayList<KinesisEventRecord>(1);
    events.add(krecord);
    kevent.setRecords(events);
    return kevent;
}
Also used : KinesisEventRecord(com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Record(com.amazonaws.services.lambda.runtime.events.KinesisEvent.Record) KinesisEventRecord(com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord) Date(java.util.Date) KinesisEvent(com.amazonaws.services.lambda.runtime.events.KinesisEvent)

Example 2 with KinesisEvent

use of com.amazonaws.services.lambda.runtime.events.KinesisEvent 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)

Aggregations

KinesisEvent (com.amazonaws.services.lambda.runtime.events.KinesisEvent)2 KinesisEventRecord (com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord)1 Record (com.amazonaws.services.lambda.runtime.events.KinesisEvent.Record)1 InternalEvent (com.nextdoor.bender.InternalEvent)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1