Skip to content

Commit

Permalink
Merge pull request #96 from IanMeyers/master
Browse files Browse the repository at this point in the history
AWS SDK V2 Support
  • Loading branch information
IanMeyers authored Jun 5, 2020
2 parents 61ef34e + a7f0849 commit ef25f3a
Show file tree
Hide file tree
Showing 16 changed files with 1,052 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,55 @@
package com.amazonaws.kinesis.agg;

import java.nio.charset.StandardCharsets;
import com.amazonaws.kinesis.agg.RecordAggregator;
import com.amazonaws.kinesis.agg.AggRecord;
import java.util.Base64;
import java.util.Random;

import org.junit.Assert;
import org.junit.Test;

public class RecordAggregatorTest
{
protected final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";

@Test
public void testSingleUserRecord()
{
RecordAggregator aggregator = new RecordAggregator();

Assert.assertEquals(0, aggregator.getNumUserRecords());

try
{
aggregator.addUserRecord("partition_key", ALPHABET.getBytes(StandardCharsets.UTF_8));
}
catch (Exception e)
{
e.printStackTrace();
Assert.fail("Encountered unexpected exception: " + e.getMessage());
}
Assert.assertEquals(1, aggregator.getNumUserRecords());

AggRecord record = aggregator.clearAndGet();
Assert.assertNotNull(record);
Assert.assertEquals(0, aggregator.getNumUserRecords());

Assert.assertEquals(1, record.getNumUserRecords());
}
public class RecordAggregatorTest {
protected final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";

@Test
public void testSingleUserRecord() {
RecordAggregator aggregator = new RecordAggregator();

Assert.assertEquals(0, aggregator.getNumUserRecords());

try {
aggregator.addUserRecord("partition_key", ALPHABET.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Encountered unexpected exception: " + e.getMessage());
}
Assert.assertEquals(1, aggregator.getNumUserRecords());

AggRecord record = aggregator.clearAndGet();
Assert.assertNotNull(record);
Assert.assertEquals(0, aggregator.getNumUserRecords());

Assert.assertEquals(1, record.getNumUserRecords());
}

@Test
public void testMultiRecord() throws Exception {
RecordAggregator aggregator = new RecordAggregator();
Random rand = new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ubWxramloZ2ZlZGNiYRogCAAQABoaYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoaIAgAEAAaGnp5eHd2dXRzcnFwb25tbGtqaWhnZmVkY2JhGiAIABAAGhphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ehogCAAQABoaenl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmEaIAgAEAAaGmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6GiAIABAAGhp6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYRogCAAQABoaYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoaIAgAEAAaGnp5eHd2dXRzcnFwb25tbGtqaWhnZmVkY2Jh0I8WvwEDJiGD4YsiKIfUOw==";
Assert.assertEquals(0, aggregator.getNumUserRecords());
String flip = new StringBuilder(ALPHABET).reverse().toString();

// add 100 random records all with the same partition key
for (int i = 0; i < c; i++) {
String pattern = i % 2 == 0 ? ALPHABET : flip;
aggregator.addUserRecord(key, pattern.getBytes(StandardCharsets.UTF_8));
}

AggRecord r = aggregator.clearAndGet();
Assert.assertEquals(c, r.getNumUserRecords());
String encodedString = Base64.getEncoder().encodeToString(r.toRecordBytes());
Assert.assertEquals(encodedTargetValue, encodedString);
}
}
4 changes: 3 additions & 1 deletion java/KinesisDeaggregator/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Kinesis Java Record Deaggregator
# Kinesis Java Record Deaggregator for AWS V1 SDK's

This library provides a set of convenience functions to perform in-memory record deaggregation that is compatible with the [Kinesis Aggregated Record Format](https://github.com/awslabs/amazon-kinesis-producer/blob/master/aggregation-format.md) used by the Kinesis Producer Library (KPL) and the KinesisAggregator module. This module can be used in any Java-based application that receives aggregated Kinesis records, including applications running on AWS Lambda.

This module is only compatible with version 1.x AWS SDK's.

## Record Deaggregation

The `RecordDeaggregator` is the class that does the work of extracting individual Kinesis user records from aggregated Kinesis Records received by AWS Lambda or directly through the Kinesis Java SDK. This class provide multiple ways to deaggregate records: stream-based, list-based, batch-based and single record.
Expand Down
8 changes: 8 additions & 0 deletions java/KinesisDeaggregator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Loading

0 comments on commit ef25f3a

Please sign in to comment.