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);
}
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));
}
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"));
}
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));
}
Aggregations