incubator-s4-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject [4/7] git commit: Fixed module loader tests + code that should not have been commented
Date Wed, 23 Jan 2013 22:35:05 GMT
Fixed module loader tests + code that should not have been commented


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/a941dfd0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/a941dfd0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/a941dfd0

Branch: refs/heads/dev
Commit: a941dfd0e60bf5686c2b836d78c0106a9a7a1d86
Parents: 2ecb531
Author: Matthieu Morel <mmorel@apache.org>
Authored: Mon Jan 21 18:44:43 2013 +0100
Committer: Matthieu Morel <mmorel@apache.org>
Committed: Mon Jan 21 19:01:41 2013 +0100

----------------------------------------------------------------------
 .../org/apache/s4/base/util/S4RLoaderFactory.java  |    2 +-
 .../core/moduleloader/ModuleLoaderTestUtils.java   |  109 ++++++++++++++
 .../s4/core/moduleloader/TestModuleLoader.java     |  117 +--------------
 .../core/moduleloader/TestModuleLoaderRemote.java  |   19 ++-
 4 files changed, 128 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/a941dfd0/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoaderFactory.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoaderFactory.java
b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoaderFactory.java
index 527c57f..0a2a5c2 100644
--- a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoaderFactory.java
+++ b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoaderFactory.java
@@ -69,7 +69,7 @@ public class S4RLoaderFactory {
         File s4rDir = null;
         if (tmpDir == null) {
             s4rDir = Files.createTempDir();
-            // s4rDir.deleteOnExit();
+            s4rDir.deleteOnExit();
             logger.warn(
                     "s4.tmp.dir not specified, using temporary directory [{}] for unpacking
S4R. You may want to specify a parent non-temporary directory.",
                     s4rDir.getAbsolutePath());

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/a941dfd0/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/ModuleLoaderTestUtils.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/ModuleLoaderTestUtils.java
b/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/ModuleLoaderTestUtils.java
new file mode 100644
index 0000000..3b95334
--- /dev/null
+++ b/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/ModuleLoaderTestUtils.java
@@ -0,0 +1,109 @@
+package org.apache.s4.core.moduleloader;
+
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+import org.apache.s4.base.Emitter;
+import org.apache.s4.base.Event;
+import org.apache.s4.base.EventMessage;
+import org.apache.s4.base.SerializerDeserializer;
+import org.apache.s4.comm.DefaultCommModule;
+import org.apache.s4.comm.tcp.TCPEmitter;
+import org.apache.s4.comm.topology.ZkClient;
+import org.apache.s4.core.BaseModule;
+import org.apache.s4.core.S4Node;
+import org.apache.s4.core.util.AppConfig;
+import org.apache.s4.deploy.DeploymentUtils;
+import org.apache.s4.fixtures.CommTestUtils;
+import org.apache.s4.fixtures.CoreTestUtils;
+import org.apache.s4.wordcount.WordCountApp;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.ZooKeeper;
+
+import com.beust.jcommander.internal.Lists;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.Resources;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class ModuleLoaderTestUtils {
+
+    private static final int NB_MESSAGES = 10;
+
+    public static Process testModuleLoader(boolean fork) throws Exception {
+
+        Process forkedS4Node = null;
+        // build custom-modules.jar
+        File gradlewFile = CoreTestUtils.findGradlewInRootDir();
+
+        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/custom-modules/build.gradle"), "clean", new String[0]);
+
+        File modulesJarFile = new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/custom-modules/build/libs/app/custom-modules.jar");
+
+        Assert.assertFalse(modulesJarFile.exists());
+
+        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
+                + "/test-apps/custom-modules/build.gradle"), "jar", new String[0]);
+
+        // make sure it is created
+        Assert.assertTrue(modulesJarFile.exists());
+
+        // pass it as a configuration
+        DeploymentUtils.initAppConfig(
+                new AppConfig.Builder().appClassName(WordCountApp.class.getName())
+                        .customModulesURIs(ImmutableList.of(modulesJarFile.toURI().toString()))
+                        .customModulesNames(ImmutableList.of("org.apache.s4.TestListenerModule")).build(),
"cluster1",
+                true, "localhost:2181");
+        if (fork) {
+            forkedS4Node = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1" });
+        } else {
+            S4Node.main(new String[] { "-c", "cluster1" });
+        }
+
+        Injector injector = Guice.createInjector(new BaseModule(Resources.getResource("default.s4.base.properties")
+                .openStream(), "cluster1"), new DefaultCommModule(Resources.getResource("default.s4.comm.properties")
+                .openStream()));
+
+        Emitter emitter = injector.getInstance(TCPEmitter.class);
+        List<Long> messages = Lists.newArrayList();
+        for (int i = 0; i < NB_MESSAGES; i++) {
+            messages.add(System.currentTimeMillis());
+        }
+
+        ZkClient zkClient = new ZkClient("localhost:2181");
+        zkClient.create("/test", 0, CreateMode.PERSISTENT);
+
+        final ZooKeeper zk = CommTestUtils.createZkClient();
+        final CountDownLatch signalMessagesReceived = new CountDownLatch(1);
+
+        // watch for last message in test data sequence
+        CoreTestUtils.watchAndSignalCreation("/test/data" + Strings.padStart(String.valueOf(NB_MESSAGES
- 1), 10, '0'),
+                signalMessagesReceived, zk);
+
+        for (Long message : messages) {
+            Event event = new Event();
+            event.put("message", long.class, message);
+            emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
+                    .serialize(event)));
+        }
+
+        // check sequential nodes in zk with correct data
+        Assert.assertTrue(signalMessagesReceived.await(10, TimeUnit.SECONDS));
+        List<String> children = zkClient.getChildren("/test");
+        for (String child : children) {
+            Long data = zkClient.readData("/test/" + child);
+            Assert.assertTrue(messages.contains(data));
+        }
+
+        return forkedS4Node;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/a941dfd0/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoader.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoader.java
b/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoader.java
index 5113a62..a1ee016 100644
--- a/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoader.java
+++ b/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoader.java
@@ -1,131 +1,18 @@
 package org.apache.s4.core.moduleloader;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import junit.framework.Assert;
-
-import org.apache.s4.base.Emitter;
-import org.apache.s4.base.Event;
-import org.apache.s4.base.EventMessage;
-import org.apache.s4.base.SerializerDeserializer;
-import org.apache.s4.comm.DefaultCommModule;
-import org.apache.s4.comm.tcp.TCPEmitter;
-import org.apache.s4.comm.topology.ZkClient;
-import org.apache.s4.core.BaseModule;
-import org.apache.s4.core.S4Node;
-import org.apache.s4.core.util.AppConfig;
-import org.apache.s4.deploy.DeploymentUtils;
-import org.apache.s4.fixtures.CommTestUtils;
-import org.apache.s4.fixtures.CoreTestUtils;
 import org.apache.s4.fixtures.ZkBasedTest;
-import org.apache.s4.wordcount.WordCountApp;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.ZooKeeper;
-import org.junit.After;
 import org.junit.Test;
 
-import com.beust.jcommander.internal.Lists;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-import com.google.common.io.Resources;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-
 public class TestModuleLoader extends ZkBasedTest {
 
-    private static final int NB_MESSAGES = 10;
-    private Process forkS4Node;
-    private TCPEmitter emitter;
-    private Injector injector;
-
     public TestModuleLoader() {
+        // need 2 partitions: 1 for the test emitter, 1 for the S4 node
         super(2);
     }
 
     @Test
     public void testLocal() throws Exception {
-        testModuleLoader(false);
-    }
-
-    protected void testModuleLoader(boolean fork) throws Exception {
-
-        // build custom-modules.jar
-        File gradlewFile = CoreTestUtils.findGradlewInRootDir();
-
-        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
-                + "/test-apps/custom-modules/build.gradle"), "clean", new String[0]);
-
-        File modulesJarFile = new File(gradlewFile.getParentFile().getAbsolutePath()
-                + "/test-apps/custom-modules/build/libs/app/custom-modules.jar");
-
-        Assert.assertFalse(modulesJarFile.exists());
-
-        CoreTestUtils.callGradleTask(new File(gradlewFile.getParentFile().getAbsolutePath()
-                + "/test-apps/custom-modules/build.gradle"), "jar", new String[0]);
-
-        // make sure it is created
-        Assert.assertTrue(modulesJarFile.exists());
-
-        // pass it as a configuration
-        DeploymentUtils.initAppConfig(
-                new AppConfig.Builder().appClassName(WordCountApp.class.getName())
-                        .customModulesURIs(ImmutableList.of(modulesJarFile.toURI().toString()))
-                        .customModulesNames(ImmutableList.of("org.apache.s4.TestListenerModule")).build(),
"cluster1",
-                true, "localhost:2181");
-        if (fork) {
-            forkS4Node = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1" });
-        } else {
-            S4Node.main(new String[] { "-c", "cluster1" });
-        }
-
-        // injector = Guice.createInjector(new BaseModule(
-        // Resources.getResource("default.s4.base.properties").openStream(), "cluster1"),
-        // new CommModuleWithoutListener(Resources.getResource("default.s4.comm.properties").openStream()));
-
-        injector = Guice.createInjector(new BaseModule(
-                Resources.getResource("default.s4.base.properties").openStream(), "cluster1"),
new DefaultCommModule(
-                Resources.getResource("default.s4.comm.properties").openStream()));
-
-        Emitter emitter = injector.getInstance(TCPEmitter.class);
-        List<Long> messages = Lists.newArrayList();
-        for (int i = 0; i < NB_MESSAGES; i++) {
-            messages.add(System.currentTimeMillis());
-        }
-
-        ZkClient zkClient = new ZkClient("localhost:2181");
-        zkClient.create("/test", 0, CreateMode.PERSISTENT);
-
-        final ZooKeeper zk = CommTestUtils.createZkClient();
-        final CountDownLatch signalMessagesReceived = new CountDownLatch(1);
-
-        // watch for last message in test data sequence
-        CoreTestUtils.watchAndSignalCreation("/test/data" + Strings.padStart(String.valueOf(NB_MESSAGES
- 1), 10, '0'),
-                signalMessagesReceived, zk);
-
-        for (Long message : messages) {
-            Event event = new Event();
-            event.put("message", long.class, message);
-            emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
-                    .serialize(event)));
-        }
-
-        // check sequential nodes in zk with correct data
-        Assert.assertTrue(signalMessagesReceived.await(10, TimeUnit.SECONDS));
-        List<String> children = zkClient.getChildren("/test");
-        for (String child : children) {
-            Long data = zkClient.readData("/test/" + child);
-            Assert.assertTrue(messages.contains(data));
-        }
-
-    }
-
-    @After
-    public void cleanUp() throws IOException, InterruptedException {
-        CoreTestUtils.killS4App(forkS4Node);
+        ModuleLoaderTestUtils.testModuleLoader(false);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/a941dfd0/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoaderRemote.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoaderRemote.java
b/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoaderRemote.java
index 0ebbe8b..6f57ef6 100644
--- a/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoaderRemote.java
+++ b/subprojects/s4-core/src/test/java/org/apache/s4/core/moduleloader/TestModuleLoaderRemote.java
@@ -1,12 +1,25 @@
 package org.apache.s4.core.moduleloader;
 
+import java.io.IOException;
+
+import org.apache.s4.fixtures.CoreTestUtils;
+import org.apache.s4.fixtures.ZkBasedTest;
+import org.junit.After;
 import org.junit.Test;
 
-// separated from its parent in order to start with clean environment with forked tests
-public class TestModuleLoaderRemote extends TestModuleLoader {
+// uses a separate class from TestModuleLoader in order to use a clean environment (tests
are assumed to forked)
+public class TestModuleLoaderRemote extends ZkBasedTest {
+
+    private Process forkedS4Node;
 
     @Test
     public void testRemote() throws Exception {
-        testModuleLoader(true);
+        forkedS4Node = ModuleLoaderTestUtils.testModuleLoader(true);
     }
+
+    @After
+    public void cleanUp() throws IOException, InterruptedException {
+        CoreTestUtils.killS4App(forkedS4Node);
+    }
+
 }


Mime
View raw message