Java Code Examples for com.amazonaws.services.lambda.runtime.events.KinesisEvent#Record

The following examples show how to use com.amazonaws.services.lambda.runtime.events.KinesisEvent#Record . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLambdaDeaggregation.java    From kinesis-aggregation with Apache License 2.0 6 votes vote down vote up
@Test
public void testAggregatedRecord() {
	// create a new KinesisEvent.Record from the aggregated data
	KinesisEvent.Record r = new KinesisEvent.Record();
	r.setPartitionKey(aggregated.getPartitionKey());
	r.setApproximateArrivalTimestamp(new Date(System.currentTimeMillis()));
	r.setData(ByteBuffer.wrap(aggregated.toRecordBytes()));
	r.setKinesisSchemaVersion("1.0");
	KinesisEventRecord ker = new KinesisEventRecord();
	ker.setKinesis(r);

	// deaggregate the record
	List<UserRecord> userRecords = deaggregator.deaggregate(Arrays.asList(ker));

	assertEquals("Deaggregated Count Matches", aggregated.getNumUserRecords(), userRecords.size());
	verifyOneToOneMapping(userRecords);
}
 
Example 2
Source File: TestLambdaDeaggregation.java    From kinesis-aggregation with Apache License 2.0 6 votes vote down vote up
@Test
public void testAggregatedRecord() throws Exception {
	// create a new KinesisEvent.Record from the aggregated data
	KinesisEvent.Record r = new KinesisEvent.Record();
	r.setPartitionKey(aggregated.getPartitionKey());
	r.setApproximateArrivalTimestamp(new Date(System.currentTimeMillis()));
	r.setData(ByteBuffer.wrap(aggregated.toRecordBytes()));
	r.setKinesisSchemaVersion("1.0");
	KinesisEventRecord ker = new KinesisEventRecord();
	ker.setKinesis(r);

	// deaggregate the record
	List<KinesisClientRecord> userRecords = deaggregator.deaggregate(Arrays.asList(ker));

	assertEquals("Deaggregated Count Matches", aggregated.getNumUserRecords(), userRecords.size());
	verifyOneToOneMapping(userRecords);
}
 
Example 3
Source File: RecordDeaggregator.java    From kinesis-aggregation with Apache License 2.0 5 votes vote down vote up
private com.amazonaws.services.kinesis.model.Record convertOne(KinesisEventRecord record) {
	KinesisEvent.Record r = record.getKinesis();
	com.amazonaws.services.kinesis.model.Record out = new com.amazonaws.services.kinesis.model.Record()
			.withPartitionKey(r.getPartitionKey()).withEncryptionType(r.getEncryptionType())
			.withApproximateArrivalTimestamp(r.getApproximateArrivalTimestamp())
			.withSequenceNumber(r.getSequenceNumber()).withData(r.getData());

	return out;

}
 
Example 4
Source File: TestLambdaDeaggregation.java    From kinesis-aggregation with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	aggregator = new RecordAggregator();

	recordList = new LinkedList<>();

	// create 10 random records for testing
	for (int i = 0; i < c; i++) {
		// create trackable id
		String id = UUID.randomUUID().toString();

		// create a kinesis model record
		byte[] data = RandomStringUtils.randomAlphabetic(20).getBytes();

		KinesisEvent.Record r = new KinesisEvent.Record();
		r.withPartitionKey(id).withApproximateArrivalTimestamp(new Date(System.currentTimeMillis()))
				.withData(ByteBuffer.wrap(data));
		KinesisEventRecord ker = new KinesisEventRecord();
		ker.setKinesis(r);
		recordList.add(ker);

		// add the record to the check set
		checkset.put(id, ker);

		// add the record to the aggregated AggRecord // create an aggregated set of
		aggregator.addUserRecord(id, data);
	}

	// get the aggregated data
	aggregated = aggregator.clearAndGet();
	assertEquals("Aggregated Record Count Correct", aggregated.getNumUserRecords(), c);
}
 
Example 5
Source File: RecordDeaggregator.java    From kinesis-aggregation with Apache License 2.0 5 votes vote down vote up
private Record convertOne(KinesisEventRecord record) {
	KinesisEvent.Record r = record.getKinesis();
	Record out = Record.builder().partitionKey(r.getPartitionKey()).encryptionType(r.getEncryptionType())
			.approximateArrivalTimestamp(r.getApproximateArrivalTimestamp().toInstant())
			.sequenceNumber(r.getSequenceNumber()).data(SdkBytes.fromByteBuffer(r.getData())).build();

	return out;

}
 
Example 6
Source File: DeaggregationUtils.java    From kinesis-aggregation with Apache License 2.0 5 votes vote down vote up
public static software.amazon.awssdk.services.kinesis.model.Record convertOne(KinesisEventRecord record) {
	KinesisEvent.Record r = record.getKinesis();
	software.amazon.awssdk.services.kinesis.model.Record out = software.amazon.awssdk.services.kinesis.model.Record
			.builder().partitionKey(r.getPartitionKey()).encryptionType(r.getEncryptionType())
			.approximateArrivalTimestamp(r.getApproximateArrivalTimestamp().toInstant())
			.sequenceNumber(r.getSequenceNumber()).data(SdkBytes.fromByteBuffer(r.getData())).build();

	return out;
}
 
Example 7
Source File: TestLambdaDeaggregation.java    From kinesis-aggregation with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	aggregator = new RecordAggregator();

	recordList = new LinkedList<>();

	// create 10 random records for testing
	for (int i = 0; i < c; i++) {
		// create trackable id
		String id = UUID.randomUUID().toString();

		// create a kinesis model record
		byte[] data = RandomStringUtils.randomAlphabetic(20).getBytes();

		KinesisEvent.Record r = new KinesisEvent.Record();
		r.withPartitionKey(id).withApproximateArrivalTimestamp(new Date(System.currentTimeMillis()))
				.withData(ByteBuffer.wrap(data));
		KinesisEventRecord ker = new KinesisEventRecord();
		ker.setKinesis(r);
		recordList.add(ker);

		// add the record to the check set
		checkset.put(id, ker);

		// add the record to the aggregated AggRecord // create an aggregated set of
		aggregator.addUserRecord(id, data);
	}

	// get the aggregated data
	aggregated = aggregator.clearAndGet();
	assertEquals("Aggregated Record Count Correct", aggregated.getNumUserRecords(), c);
}
 
Example 8
Source File: SpringBootKinesisEventHandlerTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private static KinesisEvent asAggregatedKinesisEvent(List<?> payloads) {
	RecordAggregator aggregator = new RecordAggregator();

	payloads.stream().map(SpringBootKinesisEventHandlerTests::asJsonByteBuffer)
			.forEach(buffer -> {
				try {
					aggregator.addUserRecord("fakePartitionKey", buffer.array());
				}
				catch (Exception e) {
					fail("Creating aggregated record failed");
				}
			});

	AggRecord aggRecord = aggregator.clearAndGet();

	KinesisEvent.Record record = new KinesisEvent.Record();
	record.setData(ByteBuffer.wrap(aggRecord.toRecordBytes()));

	KinesisEvent.KinesisEventRecord wrappingRecord = new KinesisEvent.KinesisEventRecord();
	wrappingRecord.setKinesis(record);
	wrappingRecord.setEventVersion("1.0");

	KinesisEvent event = new KinesisEvent();
	event.setRecords(singletonList(wrappingRecord));

	return event;
}
 
Example 9
Source File: SpringBootKinesisEventHandlerTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static KinesisEvent asKinesisEvent(List<Object> payloads) {
	KinesisEvent kinesisEvent = new KinesisEvent();

	List<KinesisEvent.KinesisEventRecord> kinesisEventRecords = new ArrayList<>();

	for (Object payload : payloads) {
		KinesisEvent.Record record = new KinesisEvent.Record();
		record.setData(asJsonByteBuffer(payload));

		KinesisEvent.KinesisEventRecord kinesisEventRecord = new KinesisEvent.KinesisEventRecord();
		kinesisEventRecord.setKinesis(record);

		kinesisEventRecords.add(kinesisEventRecord);
	}

	kinesisEvent.setRecords(kinesisEventRecords);

	return kinesisEvent;
}