Search in sources :

Example 6 with Shard

use of com.amazonaws.services.dynamodbv2.model.Shard in project camel by apache.

the class ShardList method atAfterSeq.

Shard atAfterSeq(String sequenceNumber, BigIntComparisons condition) {
    BigInteger atAfter = new BigInteger(sequenceNumber);
    List<Shard> sorted = new ArrayList<>();
    sorted.addAll(shards.values());
    Collections.sort(sorted, StartingSequenceNumberComparator.INSTANCE);
    for (Shard shard : sorted) {
        if (shard.getSequenceNumberRange().getEndingSequenceNumber() != null) {
            BigInteger end = new BigInteger(shard.getSequenceNumberRange().getEndingSequenceNumber());
            // essentially: after < end or after <= end
            if (condition.matches(atAfter, end)) {
                return shard;
            }
        }
    }
    if (shards.size() > 0) {
        return sorted.get(sorted.size() - 1);
    }
    throw new IllegalStateException("Unable to find a shard with appropriate sequence numbers for " + sequenceNumber + " in " + shards);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Shard(com.amazonaws.services.dynamodbv2.model.Shard)

Example 7 with Shard

use of com.amazonaws.services.dynamodbv2.model.Shard in project camel by apache.

the class ShardListTest method nextReturnsShardWithParent.

@Test
public void nextReturnsShardWithParent() throws Exception {
    Shard first = new Shard().withShardId("first_shard").withParentShardId("other_shard_id");
    Shard second = new Shard().withParentShardId("first_shard").withShardId("second_shard");
    ShardList shards = new ShardList();
    shards.add(first);
    shards.add(second);
    assertThat(shards.nextAfter(first), is(second));
}
Also used : Shard(com.amazonaws.services.dynamodbv2.model.Shard) Test(org.junit.Test)

Example 8 with Shard

use of com.amazonaws.services.dynamodbv2.model.Shard in project camel by apache.

the class ShardListTest method removingShards.

@Test
public void removingShards() throws Exception {
    ShardList shards = new ShardList();
    shards.addAll(createShards(null, "a", "b", "c", "d"));
    Shard removeBefore = new Shard().withShardId("c").withParentShardId("b");
    shards.removeOlderThan(removeBefore);
    assertThat(shards.first().getShardId(), is("c"));
}
Also used : Shard(com.amazonaws.services.dynamodbv2.model.Shard) Test(org.junit.Test)

Example 9 with Shard

use of com.amazonaws.services.dynamodbv2.model.Shard in project camel by apache.

the class ShardListTest method reAddingEntriesMaintainsOrder.

@Test
public void reAddingEntriesMaintainsOrder() throws Exception {
    Shard first = new Shard().withShardId("first_shard");
    Shard second = new Shard().withParentShardId("first_shard").withShardId("second_shard");
    ShardList shards = new ShardList();
    shards.add(first);
    shards.add(second);
    assertThat(shards.nextAfter(first), is(second));
    Shard second2 = new Shard().withParentShardId("first_shard").withShardId("second_shard");
    Shard third = new Shard().withParentShardId("second_shard").withShardId("third_shard");
    shards.add(second2);
    shards.add(third);
    assertThat(shards.nextAfter(first), is(second));
    assertThat(shards.nextAfter(second), is(third));
}
Also used : Shard(com.amazonaws.services.dynamodbv2.model.Shard) Test(org.junit.Test)

Aggregations

Shard (com.amazonaws.services.dynamodbv2.model.Shard)7 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 DescribeStreamRequest (com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest)1 DescribeStreamResult (com.amazonaws.services.dynamodbv2.model.DescribeStreamResult)1 ExpiredIteratorException (com.amazonaws.services.dynamodbv2.model.ExpiredIteratorException)1 GetRecordsRequest (com.amazonaws.services.dynamodbv2.model.GetRecordsRequest)1 GetRecordsResult (com.amazonaws.services.dynamodbv2.model.GetRecordsResult)1 GetShardIteratorResult (com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult)1 ListStreamsRequest (com.amazonaws.services.dynamodbv2.model.ListStreamsRequest)1 ListStreamsResult (com.amazonaws.services.dynamodbv2.model.ListStreamsResult)1 Record (com.amazonaws.services.dynamodbv2.model.Record)1 ShardIteratorType (com.amazonaws.services.dynamodbv2.model.ShardIteratorType)1 BigInteger (java.math.BigInteger)1 Exchange (org.apache.camel.Exchange)1