You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by sr...@apache.org on 2015/12/01 19:08:50 UTC
[06/50] [abbrv] storm git commit: add tests for ThriftTopologyUtils
add tests for ThriftTopologyUtils
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/9cb86669
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/9cb86669
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/9cb86669
Branch: refs/heads/STORM-1040
Commit: 9cb8666963bf3d00e21e3dfaf406650d5b780721
Parents: b03ce6b
Author: Michael Schonfeld <mi...@schonfeld.org>
Authored: Tue Nov 17 09:09:47 2015 -0500
Committer: Michael Schonfeld <mi...@schonfeld.org>
Committed: Mon Nov 23 18:50:54 2015 -0500
----------------------------------------------------------------------
.../storm/utils/ThriftTopologyUtilsTest.java | 77 ++++++++++++++++++++
1 file changed, 77 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/9cb86669/storm-core/test/jvm/backtype/storm/utils/ThriftTopologyUtilsTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/backtype/storm/utils/ThriftTopologyUtilsTest.java b/storm-core/test/jvm/backtype/storm/utils/ThriftTopologyUtilsTest.java
new file mode 100644
index 0000000..0056538
--- /dev/null
+++ b/storm-core/test/jvm/backtype/storm/utils/ThriftTopologyUtilsTest.java
@@ -0,0 +1,77 @@
+package backtype.storm.utils;
+
+import backtype.storm.generated.*;
+import backtype.storm.hooks.BaseWorkerHook;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Set;
+
+public class ThriftTopologyUtilsTest extends TestCase {
+ @Test
+ public void testIsWorkerHook() {
+ Assert.assertEquals(false, ThriftTopologyUtils.isWorkerHook(StormTopology._Fields.BOLTS));
+ Assert.assertEquals(false, ThriftTopologyUtils.isWorkerHook(StormTopology._Fields.SPOUTS));
+ Assert.assertEquals(false, ThriftTopologyUtils.isWorkerHook(StormTopology._Fields.STATE_SPOUTS));
+ Assert.assertEquals(true, ThriftTopologyUtils.isWorkerHook(StormTopology._Fields.WORKER_HOOKS));
+ }
+
+ @Test
+ public void testGetComponentIdsWithWorkerHook() {
+ StormTopology stormTopology = genereateStormTopology(true);
+ Set<String> componentIds = ThriftTopologyUtils.getComponentIds(stormTopology);
+ Assert.assertEquals(
+ "We expect to get the IDs of the components sans the Worker Hook",
+ ImmutableSet.of("bolt-1", "spout-1"),
+ componentIds);
+ }
+
+ @Test
+ public void testGetComponentIdsWithoutWorkerHook() {
+ StormTopology stormTopology = genereateStormTopology(false);
+ Set<String> componentIds = ThriftTopologyUtils.getComponentIds(stormTopology);
+ Assert.assertEquals(
+ "We expect to get the IDs of the components sans the Worker Hook",
+ ImmutableSet.of("bolt-1", "spout-1"),
+ componentIds);
+ }
+
+ @Test
+ public void testGetComponentCommonWithWorkerHook() {
+ StormTopology stormTopology = genereateStormTopology(true);
+ ComponentCommon componentCommon = ThriftTopologyUtils.getComponentCommon(stormTopology, "bolt-1");
+ Assert.assertEquals(
+ "We expect to get bolt-1's common",
+ new Bolt().get_common(),
+ componentCommon);
+ }
+
+ @Test
+ public void testGetComponentCommonWithoutWorkerHook() {
+ StormTopology stormTopology = genereateStormTopology(false);
+ ComponentCommon componentCommon = ThriftTopologyUtils.getComponentCommon(stormTopology, "bolt-1");
+ Assert.assertEquals(
+ "We expect to get bolt-1's common",
+ new Bolt().get_common(),
+ componentCommon);
+ }
+
+ private StormTopology genereateStormTopology(boolean withWorkerHook) {
+ ImmutableMap<String,SpoutSpec> spouts = ImmutableMap.of("spout-1", new SpoutSpec());
+ ImmutableMap<String,Bolt> bolts = ImmutableMap.of("bolt-1", new Bolt());
+ ImmutableMap<String,StateSpoutSpec> state_spouts = ImmutableMap.of();
+
+ StormTopology stormTopology = new StormTopology(spouts, bolts, state_spouts);
+
+ if(withWorkerHook) {
+ BaseWorkerHook workerHook = new BaseWorkerHook();
+ stormTopology.add_to_worker_hooks(ByteBuffer.wrap(Utils.javaSerialize(workerHook)));
+ }
+
+ return stormTopology;
+ }
+}