You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by ka...@apache.org on 2017/03/09 04:58:17 UTC
[1/5] storm git commit: Remove SerializableDeserializer for binary
compatibility with 1.0.x
Repository: storm
Updated Branches:
refs/heads/1.0.x-branch 7336b4fef -> 748ad66da
Remove SerializableDeserializer for binary compatibility with 1.0.x
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/dc78c16d
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/dc78c16d
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/dc78c16d
Branch: refs/heads/1.0.x-branch
Commit: dc78c16dd549297e46d934727e4a4b11a6d63ff4
Parents: a5f73cd
Author: Stig Rohde D�ssing <sd...@it-minds.dk>
Authored: Wed Mar 8 22:55:45 2017 +0100
Committer: Stig Rohde D�ssing <sd...@it-minds.dk>
Committed: Wed Mar 8 22:56:18 2017 +0100
----------------------------------------------------------------------
.../storm/kafka/spout/KafkaSpoutConfig.java | 8 +++----
.../kafka/spout/SerializableDeserializer.java | 25 --------------------
2 files changed, 4 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/dc78c16d/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
index 8aa525b..7c97ac9 100644
--- a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
@@ -105,8 +105,8 @@ public class KafkaSpoutConfig<K, V> implements Serializable {
public static class Builder<K,V> {
private final Map<String, Object> kafkaProps;
- private SerializableDeserializer<K> keyDeserializer;
- private SerializableDeserializer<V> valueDeserializer;
+ private Deserializer<K> keyDeserializer;
+ private Deserializer<V> valueDeserializer;
private long pollTimeoutMs = DEFAULT_POLL_TIMEOUT_MS;
private long offsetCommitPeriodMs = DEFAULT_OFFSET_COMMIT_PERIOD_MS;
private int maxRetries = DEFAULT_MAX_RETRIES;
@@ -164,7 +164,7 @@ public class KafkaSpoutConfig<K, V> implements Serializable {
/**
* Specifying this key deserializer overrides the property key.deserializer
*/
- public Builder<K,V> setKeyDeserializer(SerializableDeserializer<K> keyDeserializer) {
+ public Builder<K,V> setKeyDeserializer(Deserializer<K> keyDeserializer) {
this.keyDeserializer = keyDeserializer;
return this;
}
@@ -172,7 +172,7 @@ public class KafkaSpoutConfig<K, V> implements Serializable {
/**
* Specifying this value deserializer overrides the property value.deserializer
*/
- public Builder<K,V> setValueDeserializer(SerializableDeserializer<V> valueDeserializer) {
+ public Builder<K,V> setValueDeserializer(Deserializer<V> valueDeserializer) {
this.valueDeserializer = valueDeserializer;
return this;
}
http://git-wip-us.apache.org/repos/asf/storm/blob/dc78c16d/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java
deleted file mode 100644
index eb76a90..0000000
--- a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2016 The Apache Software Foundation.
- *
- * Licensed 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.storm.kafka.spout;
-
-import java.io.Serializable;
-import org.apache.kafka.common.serialization.Deserializer;
-
-/**
- * @param <T> The type this deserializer deserializes to.
- */
-public interface SerializableDeserializer<T> extends Deserializer<T>, Serializable {
-}
[5/5] storm git commit: STORM-2104: CHANGELOG
Posted by ka...@apache.org.
STORM-2104: CHANGELOG
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/748ad66d
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/748ad66d
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/748ad66d
Branch: refs/heads/1.0.x-branch
Commit: 748ad66da7619febfafd7ad2df35c3c4574fafaf
Parents: 06bfcd6
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Thu Mar 9 13:58:07 2017 +0900
Committer: Jungtaek Lim <ka...@gmail.com>
Committed: Thu Mar 9 13:58:07 2017 +0900
----------------------------------------------------------------------
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/748ad66d/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5f5a95d..f7a96ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
\ufeff## 1.0.4
+ * STORM-2104: New Kafka spout crashes if partitions are reassigned while tuples are in-flight
* STORM-2396: setting interrupted status back before throwing a RuntimeException
* STORM-2395: storm.cmd supervisor calls the wrong class name
* STORM-2385: pacemaker_state_factory.clj does not compile on branch-1.0.x
[3/5] storm git commit: STORM-2104: More graceful handling of
acked/failed tuples after partition reassignment in new Kafka spout
Posted by ka...@apache.org.
STORM-2104: More graceful handling of acked/failed tuples after partition reassignment in new Kafka spout
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/eb6677f5
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/eb6677f5
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/eb6677f5
Branch: refs/heads/1.0.x-branch
Commit: eb6677f55289be5cf5b227aba61c985fdeea450d
Parents: a25d53c
Author: Stig Rohde D�ssing <st...@gmail.com>
Authored: Tue Sep 20 13:53:55 2016 +0200
Committer: Stig Rohde D�ssing <sd...@it-minds.dk>
Committed: Wed Mar 8 22:56:18 2017 +0100
----------------------------------------------------------------------
external/storm-kafka-client/pom.xml | 10 +-
.../apache/storm/kafka/spout/KafkaSpout.java | 46 +++--
.../storm/kafka/spout/KafkaSpoutConfig.java | 8 +-
.../kafka/spout/SerializableDeserializer.java | 25 +++
.../spout/internal/KafkaConsumerFactory.java | 27 +++
.../internal/KafkaConsumerFactoryDefault.java | 29 ++++
.../kafka/spout/KafkaSpoutRebalanceTest.java | 166 +++++++++++++++++++
.../SingleTopicKafkaSpoutConfiguration.java | 94 +++++++++++
.../builders/TopicKeyValueTupleBuilder.java | 41 +++++
9 files changed, 429 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/pom.xml
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/pom.xml b/external/storm-kafka-client/pom.xml
index 089010b..720db2b 100644
--- a/external/storm-kafka-client/pom.xml
+++ b/external/storm-kafka-client/pom.xml
@@ -56,13 +56,19 @@
<!--test dependencies -->
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ <version>${mockito.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
index ebaa2b1..b4ccedd 100644
--- a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
@@ -51,6 +51,8 @@ import static org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrat
import static org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.LATEST;
import static org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.UNCOMMITTED_EARLIEST;
import static org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.UNCOMMITTED_LATEST;
+import org.apache.storm.kafka.spout.internal.KafkaConsumerFactory;
+import org.apache.storm.kafka.spout.internal.KafkaConsumerFactoryDefault;
public class KafkaSpout<K, V> extends BaseRichSpout {
private static final Logger LOG = LoggerFactory.getLogger(KafkaSpout.class);
@@ -61,6 +63,7 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
// Kafka
private final KafkaSpoutConfig<K, V> kafkaSpoutConfig;
+ private final KafkaConsumerFactory kafkaConsumerFactory;
private transient KafkaConsumer<K, V> kafkaConsumer;
private transient boolean consumerAutoCommitMode;
@@ -83,8 +86,14 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
public KafkaSpout(KafkaSpoutConfig<K, V> kafkaSpoutConfig) {
+ this(kafkaSpoutConfig, new KafkaConsumerFactoryDefault());
+ }
+
+ //This constructor is here for testing
+ KafkaSpout(KafkaSpoutConfig<K, V> kafkaSpoutConfig, KafkaConsumerFactory<K, V> kafkaConsumerFactory) {
this.kafkaSpoutConfig = kafkaSpoutConfig; // Pass in configuration
this.kafkaSpoutStreams = kafkaSpoutConfig.getKafkaSpoutStreams();
+ this.kafkaConsumerFactory = kafkaConsumerFactory;
}
@Override
@@ -144,6 +153,10 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
}
retryService.retainAll(partitions);
+
+ //Emitted messages for partitions that are no longer assigned to this spout can't be acked, and they shouldn't be retried. Remove them from emitted.
+ Set<TopicPartition> partitionsSet = new HashSet(partitions);
+ emitted.removeIf((msgId) -> !partitionsSet.contains(msgId.getTopicPartition()));
for (TopicPartition tp : partitions) {
final OffsetAndMetadata committedOffset = kafkaConsumer.committed(tp);
@@ -281,15 +294,18 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
LOG.trace("Tuple for record [{}] has already been acked. Skipping", record);
} else if (emitted.contains(msgId)) { // has been emitted and it's pending ack or fail
LOG.trace("Tuple for record [{}] has already been emitted. Skipping", record);
- } else if (!retryService.isScheduled(msgId) || retryService.isReady(msgId)) { // not scheduled <=> never failed (i.e. never emitted) or ready to be retried
- final List<Object> tuple = tuplesBuilder.buildTuple(record);
- kafkaSpoutStreams.emit(collector, tuple, msgId);
- emitted.add(msgId);
- numUncommittedOffsets++;
- if (retryService.isReady(msgId)) { // has failed. Is it ready for retry ?
- retryService.remove(msgId); // re-emitted hence remove from failed
+ } else {
+ boolean isScheduled = retryService.isScheduled(msgId);
+ if (!isScheduled || retryService.isReady(msgId)) { // not scheduled <=> never failed (i.e. never emitted) or ready to be retried
+ final List<Object> tuple = tuplesBuilder.buildTuple(record);
+ kafkaSpoutStreams.emit(collector, tuple, msgId);
+ emitted.add(msgId);
+ numUncommittedOffsets++;
+ if (isScheduled) { // Was scheduled for retry, now being re-emitted. Remove from schedule.
+ retryService.remove(msgId);
+ }
+ LOG.trace("Emitted tuple [{}] for record [{}]", tuple, record);
}
- LOG.trace("Emitted tuple [{}] for record [{}]", tuple, record);
}
}
@@ -323,6 +339,11 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
@Override
public void ack(Object messageId) {
final KafkaSpoutMessageId msgId = (KafkaSpoutMessageId) messageId;
+ if(!emitted.contains(msgId)) {
+ LOG.debug("Received ack for tuple this spout is no longer tracking. Partitions may have been reassigned. Ignoring message [{}]", msgId);
+ return;
+ }
+
if (!consumerAutoCommitMode) { // Only need to keep track of acked tuples if commits are not done automatically
acked.get(msgId.getTopicPartition()).add(msgId);
}
@@ -334,8 +355,12 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
@Override
public void fail(Object messageId) {
final KafkaSpoutMessageId msgId = (KafkaSpoutMessageId) messageId;
- emitted.remove(msgId);
+ if(!emitted.contains(msgId)) {
+ LOG.debug("Received fail for tuple this spout is no longer tracking. Partitions may have been reassigned. Ignoring message [{}]", msgId);
+ return;
+ }
if (msgId.numFails() < maxRetries) {
+ emitted.remove(msgId);
msgId.incrementNumFails();
retryService.schedule(msgId);
} else { // limit to max number of retries
@@ -352,8 +377,7 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
}
private void subscribeKafkaConsumer() {
- kafkaConsumer = new KafkaConsumer<>(kafkaSpoutConfig.getKafkaProps(),
- kafkaSpoutConfig.getKeyDeserializer(), kafkaSpoutConfig.getValueDeserializer());
+ kafkaConsumer = kafkaConsumerFactory.createConsumer(kafkaSpoutConfig);
if (kafkaSpoutStreams instanceof KafkaSpoutStreamsNamedTopics) {
final List<String> topics = ((KafkaSpoutStreamsNamedTopics) kafkaSpoutStreams).getTopics();
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
index 7c97ac9..8aa525b 100644
--- a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpoutConfig.java
@@ -105,8 +105,8 @@ public class KafkaSpoutConfig<K, V> implements Serializable {
public static class Builder<K,V> {
private final Map<String, Object> kafkaProps;
- private Deserializer<K> keyDeserializer;
- private Deserializer<V> valueDeserializer;
+ private SerializableDeserializer<K> keyDeserializer;
+ private SerializableDeserializer<V> valueDeserializer;
private long pollTimeoutMs = DEFAULT_POLL_TIMEOUT_MS;
private long offsetCommitPeriodMs = DEFAULT_OFFSET_COMMIT_PERIOD_MS;
private int maxRetries = DEFAULT_MAX_RETRIES;
@@ -164,7 +164,7 @@ public class KafkaSpoutConfig<K, V> implements Serializable {
/**
* Specifying this key deserializer overrides the property key.deserializer
*/
- public Builder<K,V> setKeyDeserializer(Deserializer<K> keyDeserializer) {
+ public Builder<K,V> setKeyDeserializer(SerializableDeserializer<K> keyDeserializer) {
this.keyDeserializer = keyDeserializer;
return this;
}
@@ -172,7 +172,7 @@ public class KafkaSpoutConfig<K, V> implements Serializable {
/**
* Specifying this value deserializer overrides the property value.deserializer
*/
- public Builder<K,V> setValueDeserializer(Deserializer<V> valueDeserializer) {
+ public Builder<K,V> setValueDeserializer(SerializableDeserializer<V> valueDeserializer) {
this.valueDeserializer = valueDeserializer;
return this;
}
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java
new file mode 100644
index 0000000..eb76a90
--- /dev/null
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/SerializableDeserializer.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.storm.kafka.spout;
+
+import java.io.Serializable;
+import org.apache.kafka.common.serialization.Deserializer;
+
+/**
+ * @param <T> The type this deserializer deserializes to.
+ */
+public interface SerializableDeserializer<T> extends Deserializer<T>, Serializable {
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactory.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactory.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactory.java
new file mode 100644
index 0000000..0b253b4
--- /dev/null
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactory.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.storm.kafka.spout.internal;
+
+import java.io.Serializable;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.storm.kafka.spout.KafkaSpoutConfig;
+
+/**
+ * This is here to enable testing
+ */
+public interface KafkaConsumerFactory<K, V> extends Serializable {
+ public KafkaConsumer<K,V> createConsumer(KafkaSpoutConfig<K, V> kafkaSpoutConfig);
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactoryDefault.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactoryDefault.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactoryDefault.java
new file mode 100644
index 0000000..7900388
--- /dev/null
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/internal/KafkaConsumerFactoryDefault.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.storm.kafka.spout.internal;
+
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.storm.kafka.spout.KafkaSpoutConfig;
+
+public class KafkaConsumerFactoryDefault<K, V> implements KafkaConsumerFactory<K, V> {
+
+ @Override
+ public KafkaConsumer<K, V> createConsumer(KafkaSpoutConfig<K, V> kafkaSpoutConfig) {
+ return new KafkaConsumer<>(kafkaSpoutConfig.getKafkaProps(),
+ kafkaSpoutConfig.getKeyDeserializer(), kafkaSpoutConfig.getValueDeserializer());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
new file mode 100644
index 0000000..3e077ab
--- /dev/null
+++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.storm.kafka.spout;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.consumer.OffsetAndMetadata;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.storm.kafka.spout.builders.SingleTopicKafkaSpoutConfiguration;
+import static org.apache.storm.kafka.spout.builders.SingleTopicKafkaSpoutConfiguration.getKafkaSpoutStreams;
+import org.apache.storm.kafka.spout.internal.KafkaConsumerFactory;
+import org.apache.storm.spout.SpoutOutputCollector;
+import org.apache.storm.task.TopologyContext;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.when;
+import org.junit.Before;
+import org.mockito.Captor;
+import static org.mockito.Mockito.reset;
+import org.mockito.MockitoAnnotations;
+import static org.apache.storm.kafka.spout.builders.SingleTopicKafkaSpoutConfiguration.getKafkaSpoutConfig;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.hasKey;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+public class KafkaSpoutRebalanceTest {
+
+ @Captor
+ private ArgumentCaptor<Map<TopicPartition, OffsetAndMetadata>> commitCapture;
+
+ private TopologyContext contextMock;
+ private SpoutOutputCollector collectorMock;
+ private Map conf;
+ private KafkaConsumer<String, String> consumerMock;
+ private KafkaConsumerFactory<String, String> consumerFactoryMock;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ contextMock = mock(TopologyContext.class);
+ collectorMock = mock(SpoutOutputCollector.class);
+ conf = new HashMap<>();
+ consumerMock = mock(KafkaConsumer.class);
+ consumerFactoryMock = (kafkaSpoutConfig) -> consumerMock;
+ }
+
+ //Returns messageIds in order of emission
+ private List<KafkaSpoutMessageId> emitOneMessagePerPartitionThenRevokeOnePartition(KafkaSpout<String, String> spout, TopicPartition partitionThatWillBeRevoked, TopicPartition assignedPartition) {
+ //Setup spout with mock consumer so we can get at the rebalance listener
+ spout.open(conf, contextMock, collectorMock);
+ spout.activate();
+
+ ArgumentCaptor<ConsumerRebalanceListener> rebalanceListenerCapture = ArgumentCaptor.forClass(ConsumerRebalanceListener.class);
+ verify(consumerMock).subscribe(anyCollection(), rebalanceListenerCapture.capture());
+
+ //Assign partitions to the spout
+ ConsumerRebalanceListener consumerRebalanceListener = rebalanceListenerCapture.getValue();
+ List<TopicPartition> assignedPartitions = new ArrayList<>();
+ assignedPartitions.add(partitionThatWillBeRevoked);
+ assignedPartitions.add(assignedPartition);
+ consumerRebalanceListener.onPartitionsAssigned(assignedPartitions);
+
+ //Make the consumer return a single message for each partition
+ Map<TopicPartition, List<ConsumerRecord<String, String>>> firstPartitionRecords = new HashMap<>();
+ firstPartitionRecords.put(partitionThatWillBeRevoked, Collections.singletonList(new ConsumerRecord(partitionThatWillBeRevoked.topic(), partitionThatWillBeRevoked.partition(), 0L, "key", "value")));
+ Map<TopicPartition, List<ConsumerRecord<String, String>>> secondPartitionRecords = new HashMap<>();
+ secondPartitionRecords.put(assignedPartition, Collections.singletonList(new ConsumerRecord(assignedPartition.topic(), assignedPartition.partition(), 0L, "key", "value")));
+ when(consumerMock.poll(anyLong()))
+ .thenReturn(new ConsumerRecords(firstPartitionRecords))
+ .thenReturn(new ConsumerRecords(secondPartitionRecords))
+ .thenReturn(new ConsumerRecords(Collections.emptyMap()));
+
+ //Emit the messages
+ spout.nextTuple();
+ ArgumentCaptor<KafkaSpoutMessageId> messageIdForRevokedPartition = ArgumentCaptor.forClass(KafkaSpoutMessageId.class);
+ verify(collectorMock).emit(anyObject(), anyObject(), messageIdForRevokedPartition.capture());
+ reset(collectorMock);
+ spout.nextTuple();
+ ArgumentCaptor<KafkaSpoutMessageId> messageIdForAssignedPartition = ArgumentCaptor.forClass(KafkaSpoutMessageId.class);
+ verify(collectorMock).emit(anyObject(), anyObject(), messageIdForAssignedPartition.capture());
+
+ //Now rebalance
+ consumerRebalanceListener.onPartitionsRevoked(assignedPartitions);
+ consumerRebalanceListener.onPartitionsAssigned(Collections.singleton(assignedPartition));
+
+ List<KafkaSpoutMessageId> emittedMessageIds = new ArrayList<>();
+ emittedMessageIds.add(messageIdForRevokedPartition.getValue());
+ emittedMessageIds.add(messageIdForAssignedPartition.getValue());
+ return emittedMessageIds;
+ }
+
+ @Test
+ public void spoutMustIgnoreAcksForTuplesItIsNotAssignedAfterRebalance() throws Exception {
+ //Acking tuples for partitions that are no longer assigned is useless since the spout will not be allowed to commit them
+ KafkaSpout<String, String> spout = new KafkaSpout<>(getKafkaSpoutConfig(getKafkaSpoutStreams(), -1, 10), consumerFactoryMock);
+ String topic = SingleTopicKafkaSpoutConfiguration.TOPIC;
+ TopicPartition partitionThatWillBeRevoked = new TopicPartition(topic, 1);
+ TopicPartition assignedPartition = new TopicPartition(topic, 2);
+
+ //Emit a message on each partition and revoke the first partition
+ List<KafkaSpoutMessageId> emittedMessageIds = emitOneMessagePerPartitionThenRevokeOnePartition(spout, partitionThatWillBeRevoked, assignedPartition);
+
+ //Ack both emitted tuples
+ spout.ack(emittedMessageIds.get(0));
+ spout.ack(emittedMessageIds.get(1));
+
+ //Ensure the commit timer has expired
+ Thread.sleep(510);
+
+ //Make the spout commit any acked tuples
+ spout.nextTuple();
+ //Verify that it only committed the message on the assigned partition
+ verify(consumerMock).commitSync(commitCapture.capture());
+
+ Map<TopicPartition, OffsetAndMetadata> commitCaptureMap = commitCapture.getValue();
+ assertThat(commitCaptureMap, hasKey(assignedPartition));
+ assertThat(commitCaptureMap, not(hasKey(partitionThatWillBeRevoked)));
+ }
+
+ @Test
+ public void spoutMustIgnoreFailsForTuplesItIsNotAssignedAfterRebalance() throws Exception {
+ //Failing tuples for partitions that are no longer assigned is useless since the spout will not be allowed to commit them if they later pass
+ KafkaSpoutRetryService retryServiceMock = mock(KafkaSpoutRetryService.class);
+ KafkaSpout<String, String> spout = new KafkaSpout<>(getKafkaSpoutConfig(getKafkaSpoutStreams(), -1, 10, retryServiceMock), consumerFactoryMock);
+ String topic = SingleTopicKafkaSpoutConfiguration.TOPIC;
+ TopicPartition partitionThatWillBeRevoked = new TopicPartition(topic, 1);
+ TopicPartition assignedPartition = new TopicPartition(topic, 2);
+
+ //Emit a message on each partition and revoke the first partition
+ List<KafkaSpoutMessageId> emittedMessageIds = emitOneMessagePerPartitionThenRevokeOnePartition(spout, partitionThatWillBeRevoked, assignedPartition);
+
+ //Fail both emitted tuples
+ spout.fail(emittedMessageIds.get(0));
+ spout.fail(emittedMessageIds.get(1));
+
+ //Check that only the tuple on the currently assigned partition is retried
+ verify(retryServiceMock, never()).schedule(emittedMessageIds.get(0));
+ verify(retryServiceMock).schedule(emittedMessageIds.get(1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/SingleTopicKafkaSpoutConfiguration.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/SingleTopicKafkaSpoutConfiguration.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/SingleTopicKafkaSpoutConfiguration.java
new file mode 100644
index 0000000..95b2199
--- /dev/null
+++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/SingleTopicKafkaSpoutConfiguration.java
@@ -0,0 +1,94 @@
+/*
+ * 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.storm.kafka.spout.builders;
+
+import org.apache.storm.Config;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.kafka.spout.*;
+import org.apache.storm.kafka.spout.test.KafkaSpoutTestBolt;
+import org.apache.storm.topology.TopologyBuilder;
+import org.apache.storm.tuple.Fields;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.EARLIEST;
+
+public class SingleTopicKafkaSpoutConfiguration {
+
+ public static final String STREAM = "test_stream";
+ public static final String TOPIC = "test";
+
+ public static Config getConfig() {
+ Config config = new Config();
+ config.setDebug(true);
+ return config;
+ }
+
+ public static StormTopology getTopologyKafkaSpout(int port) {
+ final TopologyBuilder tp = new TopologyBuilder();
+ tp.setSpout("kafka_spout", new KafkaSpout<>(getKafkaSpoutConfig(getKafkaSpoutStreams(), port)), 1);
+ tp.setBolt("kafka_bolt", new KafkaSpoutTestBolt()).shuffleGrouping("kafka_spout", STREAM);
+ return tp.createTopology();
+ }
+
+ public static KafkaSpoutConfig<String, String> getKafkaSpoutConfig(KafkaSpoutStreams kafkaSpoutStreams, int port) {
+ return getKafkaSpoutConfig(kafkaSpoutStreams, port, 10_000);
+ }
+
+ public static KafkaSpoutConfig<String, String> getKafkaSpoutConfig(KafkaSpoutStreams kafkaSpoutStreams, int port, long offsetCommitPeriodMs) {
+ return getKafkaSpoutConfig(kafkaSpoutStreams, port, offsetCommitPeriodMs, getRetryService());
+ }
+
+ public static KafkaSpoutConfig<String, String> getKafkaSpoutConfig(KafkaSpoutStreams kafkaSpoutStreams, int port, long offsetCommitPeriodMs, KafkaSpoutRetryService retryService) {
+ return new KafkaSpoutConfig.Builder<>(getKafkaConsumerProps(port), kafkaSpoutStreams, getTuplesBuilder(), retryService)
+ .setOffsetCommitPeriodMs(offsetCommitPeriodMs)
+ .setFirstPollOffsetStrategy(EARLIEST)
+ .setMaxUncommittedOffsets(250)
+ .setPollTimeoutMs(1000)
+ .build();
+ }
+
+ protected static KafkaSpoutRetryService getRetryService() {
+ return new KafkaSpoutRetryExponentialBackoff(KafkaSpoutRetryExponentialBackoff.TimeInterval.microSeconds(0),
+ KafkaSpoutRetryExponentialBackoff.TimeInterval.milliSeconds(0), Integer.MAX_VALUE, KafkaSpoutRetryExponentialBackoff.TimeInterval.milliSeconds(0));
+
+ }
+
+ protected static Map<String, Object> getKafkaConsumerProps(int port) {
+ Map<String, Object> props = new HashMap<>();
+ props.put(KafkaSpoutConfig.Consumer.BOOTSTRAP_SERVERS, "127.0.0.1:" + port);
+ props.put(KafkaSpoutConfig.Consumer.GROUP_ID, "kafkaSpoutTestGroup");
+ props.put(KafkaSpoutConfig.Consumer.KEY_DESERIALIZER, "org.apache.kafka.common.serialization.StringDeserializer");
+ props.put(KafkaSpoutConfig.Consumer.VALUE_DESERIALIZER, "org.apache.kafka.common.serialization.StringDeserializer");
+ props.put("max.poll.records", "5");
+ return props;
+ }
+
+ protected static KafkaSpoutTuplesBuilder<String, String> getTuplesBuilder() {
+ return new KafkaSpoutTuplesBuilderNamedTopics.Builder<>(
+ new TopicKeyValueTupleBuilder<String, String>(TOPIC))
+ .build();
+ }
+
+ public static KafkaSpoutStreams getKafkaSpoutStreams() {
+ final Fields outputFields = new Fields("topic", "key", "value");
+ return new KafkaSpoutStreamsNamedTopics.Builder(outputFields, STREAM, new String[]{TOPIC}) // contents of topics test sent to test_stream
+ .build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/storm/blob/eb6677f5/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
new file mode 100644
index 0000000..492b79d
--- /dev/null
+++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
@@ -0,0 +1,41 @@
+
+/*
+ * 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.storm.kafka.spout.builders;
+
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.storm.kafka.spout.KafkaSpoutTupleBuilder;
+import org.apache.storm.tuple.Values;
+
+import java.util.List;
+
+public class TopicKeyValueTupleBuilder<K, V> extends KafkaSpoutTupleBuilder<K,V> {
+ /**
+ * @param topics list of topics that use this implementation to build tuples
+ */
+ public TopicKeyValueTupleBuilder(String... topics) {
+ super(topics);
+ }
+
+ @Override
+ public List<Object> buildTuple(ConsumerRecord<K, V> consumerRecord) {
+ return new Values(consumerRecord.topic(),
+ consumerRecord.key(),
+ consumerRecord.value());
+ }
+}
[4/5] storm git commit: Merge branch 'STORM-2104-1.0.x' of
https://github.com/srdo/storm into STORM-2104-1.0.x-merge
Posted by ka...@apache.org.
Merge branch 'STORM-2104-1.0.x' of https://github.com/srdo/storm into STORM-2104-1.0.x-merge
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/06bfcd68
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/06bfcd68
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/06bfcd68
Branch: refs/heads/1.0.x-branch
Commit: 06bfcd685265ca35ffed5887b63060e7e42edc8d
Parents: 7336b4f dc78c16
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Thu Mar 9 13:57:34 2017 +0900
Committer: Jungtaek Lim <ka...@gmail.com>
Committed: Thu Mar 9 13:57:34 2017 +0900
----------------------------------------------------------------------
external/storm-kafka-client/pom.xml | 10 +-
.../apache/storm/kafka/spout/KafkaSpout.java | 52 ++++--
.../spout/internal/KafkaConsumerFactory.java | 27 +++
.../internal/KafkaConsumerFactoryDefault.java | 29 +++
.../kafka/spout/KafkaSpoutRebalanceTest.java | 180 +++++++++++++++++++
.../SingleTopicKafkaSpoutConfiguration.java | 94 ++++++++++
.../builders/TopicKeyValueTupleBuilder.java | 40 +++++
7 files changed, 419 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
[2/5] storm git commit: STORM-2104: Rewrite a few parts to be
compatible with Java 7
Posted by ka...@apache.org.
STORM-2104: Rewrite a few parts to be compatible with Java 7
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/a5f73cdd
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/a5f73cdd
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/a5f73cdd
Branch: refs/heads/1.0.x-branch
Commit: a5f73cddc4e07d042ddb0f97a0c671080779dcda
Parents: eb6677f
Author: Stig Rohde D�ssing <sd...@it-minds.dk>
Authored: Thu Dec 8 19:34:07 2016 +0100
Committer: Stig Rohde D�ssing <sd...@it-minds.dk>
Committed: Wed Mar 8 22:56:18 2017 +0100
----------------------------------------------------------------------
.../apache/storm/kafka/spout/KafkaSpout.java | 8 +++++-
.../kafka/spout/KafkaSpoutRebalanceTest.java | 26 +++++++++++++++-----
.../builders/TopicKeyValueTupleBuilder.java | 1 -
3 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/a5f73cdd/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
index b4ccedd..c72e70b 100644
--- a/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
+++ b/external/storm-kafka-client/src/main/java/org/apache/storm/kafka/spout/KafkaSpout.java
@@ -156,7 +156,13 @@ public class KafkaSpout<K, V> extends BaseRichSpout {
//Emitted messages for partitions that are no longer assigned to this spout can't be acked, and they shouldn't be retried. Remove them from emitted.
Set<TopicPartition> partitionsSet = new HashSet(partitions);
- emitted.removeIf((msgId) -> !partitionsSet.contains(msgId.getTopicPartition()));
+ Iterator<KafkaSpoutMessageId> msgIdIterator = emitted.iterator();
+ while (msgIdIterator.hasNext()) {
+ KafkaSpoutMessageId msgId = msgIdIterator.next();
+ if (!partitionsSet.contains(msgId.getTopicPartition())) {
+ msgIdIterator.remove();
+ }
+ }
for (TopicPartition tp : partitions) {
final OffsetAndMetadata committedOffset = kafkaConsumer.committed(tp);
http://git-wip-us.apache.org/repos/asf/storm/blob/a5f73cdd/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
index 3e077ab..a554a3b 100644
--- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
+++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutRebalanceTest.java
@@ -27,24 +27,33 @@ import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.apache.storm.kafka.spout.builders.SingleTopicKafkaSpoutConfiguration;
+
import static org.apache.storm.kafka.spout.builders.SingleTopicKafkaSpoutConfiguration.getKafkaSpoutStreams;
+
import org.apache.storm.kafka.spout.internal.KafkaConsumerFactory;
import org.apache.storm.spout.SpoutOutputCollector;
import org.apache.storm.task.TopologyContext;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+
import static org.mockito.Matchers.anyCollection;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.when;
+
import org.junit.Before;
import org.mockito.Captor;
+
import static org.mockito.Mockito.reset;
+
import org.mockito.MockitoAnnotations;
+
import static org.apache.storm.kafka.spout.builders.SingleTopicKafkaSpoutConfiguration.getKafkaSpoutConfig;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.hasKey;
import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyList;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -67,7 +76,12 @@ public class KafkaSpoutRebalanceTest {
collectorMock = mock(SpoutOutputCollector.class);
conf = new HashMap<>();
consumerMock = mock(KafkaConsumer.class);
- consumerFactoryMock = (kafkaSpoutConfig) -> consumerMock;
+ consumerFactoryMock = new KafkaConsumerFactory<String, String>(){
+ @Override
+ public KafkaConsumer<String, String> createConsumer(KafkaSpoutConfig<String, String> kafkaSpoutConfig) {
+ return consumerMock;
+ }
+ };
}
//Returns messageIds in order of emission
@@ -77,7 +91,7 @@ public class KafkaSpoutRebalanceTest {
spout.activate();
ArgumentCaptor<ConsumerRebalanceListener> rebalanceListenerCapture = ArgumentCaptor.forClass(ConsumerRebalanceListener.class);
- verify(consumerMock).subscribe(anyCollection(), rebalanceListenerCapture.capture());
+ verify(consumerMock).subscribe(anyList(), rebalanceListenerCapture.capture());
//Assign partitions to the spout
ConsumerRebalanceListener consumerRebalanceListener = rebalanceListenerCapture.getValue();
@@ -88,9 +102,9 @@ public class KafkaSpoutRebalanceTest {
//Make the consumer return a single message for each partition
Map<TopicPartition, List<ConsumerRecord<String, String>>> firstPartitionRecords = new HashMap<>();
- firstPartitionRecords.put(partitionThatWillBeRevoked, Collections.singletonList(new ConsumerRecord(partitionThatWillBeRevoked.topic(), partitionThatWillBeRevoked.partition(), 0L, "key", "value")));
+ firstPartitionRecords.put(partitionThatWillBeRevoked, Collections.singletonList(new ConsumerRecord<>(partitionThatWillBeRevoked.topic(), partitionThatWillBeRevoked.partition(), 0L, "key", "value")));
Map<TopicPartition, List<ConsumerRecord<String, String>>> secondPartitionRecords = new HashMap<>();
- secondPartitionRecords.put(assignedPartition, Collections.singletonList(new ConsumerRecord(assignedPartition.topic(), assignedPartition.partition(), 0L, "key", "value")));
+ secondPartitionRecords.put(assignedPartition, Collections.singletonList(new ConsumerRecord<>(assignedPartition.topic(), assignedPartition.partition(), 0L, "key", "value")));
when(consumerMock.poll(anyLong()))
.thenReturn(new ConsumerRecords(firstPartitionRecords))
.thenReturn(new ConsumerRecords(secondPartitionRecords))
@@ -99,11 +113,11 @@ public class KafkaSpoutRebalanceTest {
//Emit the messages
spout.nextTuple();
ArgumentCaptor<KafkaSpoutMessageId> messageIdForRevokedPartition = ArgumentCaptor.forClass(KafkaSpoutMessageId.class);
- verify(collectorMock).emit(anyObject(), anyObject(), messageIdForRevokedPartition.capture());
+ verify(collectorMock).emit(anyString(), anyList(), messageIdForRevokedPartition.capture());
reset(collectorMock);
spout.nextTuple();
ArgumentCaptor<KafkaSpoutMessageId> messageIdForAssignedPartition = ArgumentCaptor.forClass(KafkaSpoutMessageId.class);
- verify(collectorMock).emit(anyObject(), anyObject(), messageIdForAssignedPartition.capture());
+ verify(collectorMock).emit(anyString(), anyList(), messageIdForAssignedPartition.capture());
//Now rebalance
consumerRebalanceListener.onPartitionsRevoked(assignedPartitions);
http://git-wip-us.apache.org/repos/asf/storm/blob/a5f73cdd/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
index 492b79d..4f20b58 100644
--- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
+++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/builders/TopicKeyValueTupleBuilder.java
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file