Repository: camel Updated Branches: refs/heads/master 0350423d9 -> 0570a6ca3
Fix CS. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/37040b10 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/37040b10 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/37040b10 Branch: refs/heads/master Commit: 37040b10adb4821fe656f506495b20e5b79cb3f7 Parents: 0a25e51 Author: Candle <can...@candle.me.uk> Authored: Mon Dec 21 14:05:21 2015 +0000 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Dec 24 09:45:31 2015 +0100 ---------------------------------------------------------------------- .../component/aws/ddbstream/ShardList.java | 22 ++++++----- .../StringSequenceNumberConverter.java | 2 +- .../aws/ddbstream/DdbStreamEndpointTest.java | 14 +++---- .../ShardListAfterSequenceParametrised.java | 40 ++++++++++++++------ .../ShardListAtSequenceParametrised.java | 40 ++++++++++++++------ .../component/aws/ddbstream/ShardListTest.java | 10 ++--- 6 files changed, 82 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/37040b10/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/ShardList.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/ShardList.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/ShardList.java index 3ae1c4e..0a6e332 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/ShardList.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/ShardList.java @@ -16,20 +16,21 @@ */ package org.apache.camel.component.aws.ddbstream; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import com.amazonaws.services.dynamodbv2.model.Shard; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import com.amazonaws.services.dynamodbv2.model.Shard; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class ShardList { + private final Logger log = LoggerFactory.getLogger(ShardList.class); private final Map<String, Shard> shards = new HashMap<>(); @@ -54,6 +55,8 @@ class ShardList { } Shard first() { + // Potential optimisation: if the two provided sequence numbers are the + // same then we can skip the shard entirely. Need to confirm this with AWS. for (Shard shard : shards.values()) { if (!shards.containsKey(shard.getParentShardId())) { return shard; @@ -99,14 +102,15 @@ class ShardList { } } if (shards.size() > 0) { - return sorted.get(sorted.size()-1); + return sorted.get(sorted.size() - 1); } throw new IllegalStateException("Unable to find a shard with appropriate sequence numbers for " + sequenceNumber + " in " + shards); } /** - * Removes shards that are older than the provided shard. - * Does not remove the provided shard. + * Removes shards that are older than the provided shard. Does not remove + * the provided shard. + * * @param removeBefore */ void removeOlderThan(Shard removeBefore) { @@ -162,4 +166,4 @@ class ShardList { } } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/camel/blob/37040b10/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java index 92bae2b..0048ce0 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/StringSequenceNumberConverter.java @@ -19,7 +19,7 @@ package org.apache.camel.component.aws.ddbstream; import org.apache.camel.Converter; @Converter -public class StringSequenceNumberConverter { +public final class StringSequenceNumberConverter { private StringSequenceNumberConverter() { } http://git-wip-us.apache.org/repos/asf/camel/blob/37040b10/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamEndpointTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamEndpointTest.java index 9e688be..1d3629e 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamEndpointTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamEndpointTest.java @@ -20,30 +20,30 @@ import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams; import org.apache.camel.CamelContext; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.SimpleRegistry; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import org.junit.Test; import org.junit.Before; import org.junit.Rule; +import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class DdbStreamEndpointTest { + @Rule public ExpectedException expectedException = ExpectedException.none(); private CamelContext context; @Mock private SequenceNumberProvider sequenceNumberProvider; @Mock private AmazonDynamoDBStreams amazonDynamoDBStreams; - @Rule public ExpectedException expectedException = ExpectedException.none(); - @Before public void setup() throws Exception { SimpleRegistry registry = new SimpleRegistry(); http://git-wip-us.apache.org/repos/asf/camel/blob/37040b10/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAfterSequenceParametrised.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAfterSequenceParametrised.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAfterSequenceParametrised.java index c33ebe2..f7e6397 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAfterSequenceParametrised.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAfterSequenceParametrised.java @@ -1,18 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.component.aws.ddbstream; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + @RunWith(Parameterized.class) public class ShardListAfterSequenceParametrised { + private ShardList undertest; + + private final String inputSequenceNumber; + private final String expectedShardId; + public ShardListAfterSequenceParametrised(String inputSequenceNumber, String expectedShardId) { + this.inputSequenceNumber = inputSequenceNumber; + this.expectedShardId = expectedShardId; + } @Parameterized.Parameters public static Collection<Object[]> paramaters() { @@ -29,16 +55,6 @@ public class ShardListAfterSequenceParametrised { return results; } - private ShardList undertest; - - private final String inputSequenceNumber; - private final String expectedShardId; - - public ShardListAfterSequenceParametrised(String inputSequenceNumber, String expectedShardId) { - this.inputSequenceNumber = inputSequenceNumber; - this.expectedShardId = expectedShardId; - } - @Before public void setup() throws Exception { undertest = new ShardList(); http://git-wip-us.apache.org/repos/asf/camel/blob/37040b10/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAtSequenceParametrised.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAtSequenceParametrised.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAtSequenceParametrised.java index cf15021..9be5636 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAtSequenceParametrised.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListAtSequenceParametrised.java @@ -1,18 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.component.aws.ddbstream; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + @RunWith(Parameterized.class) public class ShardListAtSequenceParametrised { + private ShardList undertest; + + private final String inputSequenceNumber; + private final String expectedShardId; + public ShardListAtSequenceParametrised(String inputSequenceNumber, String expectedShardId) { + this.inputSequenceNumber = inputSequenceNumber; + this.expectedShardId = expectedShardId; + } @Parameterized.Parameters public static Collection<Object[]> paramaters() { @@ -29,16 +55,6 @@ public class ShardListAtSequenceParametrised { return results; } - private ShardList undertest; - - private final String inputSequenceNumber; - private final String expectedShardId; - - public ShardListAtSequenceParametrised(String inputSequenceNumber, String expectedShardId) { - this.inputSequenceNumber = inputSequenceNumber; - this.expectedShardId = expectedShardId; - } - @Before public void setup() throws Exception { undertest = new ShardList(); http://git-wip-us.apache.org/repos/asf/camel/blob/37040b10/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListTest.java index e181d7e..68dd53d 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/ShardListTest.java @@ -17,15 +17,15 @@ package org.apache.camel.component.aws.ddbstream; -import com.amazonaws.services.dynamodbv2.model.SequenceNumberRange; import java.util.ArrayList; import java.util.List; -import com.amazonaws.services.dynamodbv2.model.Shard; +import com.amazonaws.services.dynamodbv2.model.SequenceNumberRange; +import com.amazonaws.services.dynamodbv2.model.Shard; import org.junit.Test; + import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import org.junit.Ignore; public class ShardListTest { @@ -125,8 +125,8 @@ public class ShardListTest { List<Shard> result = new ArrayList<>(); for (int i = 0; i < shardIdsAndSeqNos.length; i += 3) { String id = shardIdsAndSeqNos[i]; - String seqStart = shardIdsAndSeqNos[i+1]; - String seqEnd = shardIdsAndSeqNos[i+2]; + String seqStart = shardIdsAndSeqNos[i + 1]; + String seqEnd = shardIdsAndSeqNos[i + 2]; result.add(new Shard() .withShardId(id) .withParentShardId(previous)