You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@twill.apache.org by ch...@apache.org on 2014/06/18 20:34:37 UTC

git commit: (TWILL-86) Rename ServiceDiscoveryTest to ServiceDiscoveryTestRun to avoid the test being executed twice, one by itself and one by YarnTestSuite.

Repository: incubator-twill
Updated Branches:
  refs/heads/master c3eead1cd -> 36b9df175


(TWILL-86) Rename ServiceDiscoveryTest to ServiceDiscoveryTestRun to avoid the test being executed twice, one by itself and one by YarnTestSuite.

Signed-off-by: Terence Yim <te...@continuuity.com>


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

Branch: refs/heads/master
Commit: 36b9df175cd41ae5733f50f89e2f842e0e6d2c1e
Parents: c3eead1
Author: Terence Yim <te...@continuuity.com>
Authored: Wed Jun 18 11:14:09 2014 -0700
Committer: Terence Yim <te...@continuuity.com>
Committed: Wed Jun 18 11:34:05 2014 -0700

----------------------------------------------------------------------
 .../apache/twill/yarn/ServiceDiscoveryTest.java | 129 -------------------
 .../twill/yarn/ServiceDiscoveryTestRun.java     | 129 +++++++++++++++++++
 .../org/apache/twill/yarn/YarnTestSuite.java    |   2 +-
 3 files changed, 130 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-twill/blob/36b9df17/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTest.java b/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTest.java
deleted file mode 100644
index 77bc181..0000000
--- a/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.twill.yarn;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.Service;
-import org.apache.twill.api.AbstractTwillRunnable;
-import org.apache.twill.api.TwillApplication;
-import org.apache.twill.api.TwillContext;
-import org.apache.twill.api.TwillController;
-import org.apache.twill.api.TwillRunner;
-import org.apache.twill.api.TwillSpecification;
-import org.apache.twill.api.logging.PrinterLogHandler;
-import org.apache.twill.common.Services;
-import org.apache.twill.common.Threads;
-import org.apache.twill.discovery.Discoverable;
-import org.apache.twill.discovery.ServiceDiscovered;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.PrintWriter;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * Test for ability to discover existence of services through {@link TwillContext}.
- */
-public final class ServiceDiscoveryTest extends BaseYarnTest {
-
-  @Test
-  public void testServiceDiscovery() throws InterruptedException, ExecutionException, TimeoutException {
-    TwillRunner twillRunner = YarnTestUtils.getTwillRunner();
-    TwillController controller = twillRunner
-      .prepare(new ServiceApplication())
-      .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
-      .withArguments("r1", "12345")
-      .withArguments("r2", "45678")
-      .start();
-
-    ListenableFuture<Service.State> completion = Services.getCompletionFuture(controller);
-    try {
-      completion.get(60, TimeUnit.SECONDS);
-    } finally {
-      controller.stopAndWait();
-    }
-  }
-
-  /**
-   * An application that contains two {@link ServiceRunnable}.
-   */
-  public static final class ServiceApplication implements TwillApplication {
-
-    @Override
-    public TwillSpecification configure() {
-      return TwillSpecification.Builder.with()
-        .setName("ServiceApp")
-        .withRunnable()
-          .add("r1", new ServiceRunnable()).noLocalFiles()
-          .add("r2", new ServiceRunnable()).noLocalFiles()
-        .anyOrder()
-        .build();
-    }
-  }
-
-  /**
-   * A Runnable that will announce on service and wait for announcement from another instance in the same service.
-   */
-  public static final class ServiceRunnable extends AbstractTwillRunnable {
-
-    private static final Logger LOG = LoggerFactory.getLogger(ServiceRunnable.class);
-    private static final String SERVICE_NAME = "service";
-    private volatile Thread runThread;
-
-    @Override
-    public void run() {
-      this.runThread = Thread.currentThread();
-      final int port = Integer.parseInt(getContext().getArguments()[0]);
-      getContext().announce(SERVICE_NAME, port);
-
-      final CountDownLatch discoveredLatch = new CountDownLatch(1);
-
-      ServiceDiscovered serviceDiscovered = getContext().discover(SERVICE_NAME);
-      serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
-        @Override
-        public void onChange(ServiceDiscovered serviceDiscovered) {
-          // Try to find a discoverable that is not this instance
-          for (Discoverable discoverable : serviceDiscovered) {
-            int discoveredPort = discoverable.getSocketAddress().getPort();
-            if (SERVICE_NAME.equals(discoverable.getName()) && discoveredPort != port) {
-              LOG.info("{}: Service discovered at {}", getContext().getSpecification().getName(), discoveredPort);
-              discoveredLatch.countDown();
-            }
-          }
-        }
-      }, Threads.SAME_THREAD_EXECUTOR);
-
-      try {
-        discoveredLatch.await();
-      } catch (InterruptedException e) {
-        LOG.warn("Interrupted.", e);
-      }
-    }
-
-    @Override
-    public void stop() {
-      if (runThread != null) {
-        runThread.interrupt();
-      }
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-twill/blob/36b9df17/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTestRun.java
----------------------------------------------------------------------
diff --git a/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTestRun.java b/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTestRun.java
new file mode 100644
index 0000000..12256df
--- /dev/null
+++ b/twill-yarn/src/test/java/org/apache/twill/yarn/ServiceDiscoveryTestRun.java
@@ -0,0 +1,129 @@
+/*
+ * 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.twill.yarn;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.Service;
+import org.apache.twill.api.AbstractTwillRunnable;
+import org.apache.twill.api.TwillApplication;
+import org.apache.twill.api.TwillContext;
+import org.apache.twill.api.TwillController;
+import org.apache.twill.api.TwillRunner;
+import org.apache.twill.api.TwillSpecification;
+import org.apache.twill.api.logging.PrinterLogHandler;
+import org.apache.twill.common.Services;
+import org.apache.twill.common.Threads;
+import org.apache.twill.discovery.Discoverable;
+import org.apache.twill.discovery.ServiceDiscovered;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.PrintWriter;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Test for ability to discover existence of services through {@link TwillContext}.
+ */
+public final class ServiceDiscoveryTestRun extends BaseYarnTest {
+
+  @Test
+  public void testServiceDiscovery() throws InterruptedException, ExecutionException, TimeoutException {
+    TwillRunner twillRunner = YarnTestUtils.getTwillRunner();
+    TwillController controller = twillRunner
+      .prepare(new ServiceApplication())
+      .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
+      .withArguments("r1", "12345")
+      .withArguments("r2", "45678")
+      .start();
+
+    ListenableFuture<Service.State> completion = Services.getCompletionFuture(controller);
+    try {
+      completion.get(60, TimeUnit.SECONDS);
+    } finally {
+      controller.stopAndWait();
+    }
+  }
+
+  /**
+   * An application that contains two {@link ServiceRunnable}.
+   */
+  public static final class ServiceApplication implements TwillApplication {
+
+    @Override
+    public TwillSpecification configure() {
+      return TwillSpecification.Builder.with()
+        .setName("ServiceApp")
+        .withRunnable()
+          .add("r1", new ServiceRunnable()).noLocalFiles()
+          .add("r2", new ServiceRunnable()).noLocalFiles()
+        .anyOrder()
+        .build();
+    }
+  }
+
+  /**
+   * A Runnable that will announce on service and wait for announcement from another instance in the same service.
+   */
+  public static final class ServiceRunnable extends AbstractTwillRunnable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ServiceRunnable.class);
+    private static final String SERVICE_NAME = "service";
+    private volatile Thread runThread;
+
+    @Override
+    public void run() {
+      this.runThread = Thread.currentThread();
+      final int port = Integer.parseInt(getContext().getArguments()[0]);
+      getContext().announce(SERVICE_NAME, port);
+
+      final CountDownLatch discoveredLatch = new CountDownLatch(1);
+
+      ServiceDiscovered serviceDiscovered = getContext().discover(SERVICE_NAME);
+      serviceDiscovered.watchChanges(new ServiceDiscovered.ChangeListener() {
+        @Override
+        public void onChange(ServiceDiscovered serviceDiscovered) {
+          // Try to find a discoverable that is not this instance
+          for (Discoverable discoverable : serviceDiscovered) {
+            int discoveredPort = discoverable.getSocketAddress().getPort();
+            if (SERVICE_NAME.equals(discoverable.getName()) && discoveredPort != port) {
+              LOG.info("{}: Service discovered at {}", getContext().getSpecification().getName(), discoveredPort);
+              discoveredLatch.countDown();
+            }
+          }
+        }
+      }, Threads.SAME_THREAD_EXECUTOR);
+
+      try {
+        discoveredLatch.await();
+      } catch (InterruptedException e) {
+        LOG.warn("Interrupted.", e);
+      }
+    }
+
+    @Override
+    public void stop() {
+      if (runThread != null) {
+        runThread.interrupt();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-twill/blob/36b9df17/twill-yarn/src/test/java/org/apache/twill/yarn/YarnTestSuite.java
----------------------------------------------------------------------
diff --git a/twill-yarn/src/test/java/org/apache/twill/yarn/YarnTestSuite.java b/twill-yarn/src/test/java/org/apache/twill/yarn/YarnTestSuite.java
index c981200..b8a3915 100644
--- a/twill-yarn/src/test/java/org/apache/twill/yarn/YarnTestSuite.java
+++ b/twill-yarn/src/test/java/org/apache/twill/yarn/YarnTestSuite.java
@@ -34,7 +34,7 @@ import org.junit.runners.Suite;
                       ProvisionTimeoutTestRun.class,
                       LogHandlerTestRun.class,
                       SessionExpireTestRun.class,
-                      ServiceDiscoveryTest.class,
+                      ServiceDiscoveryTestRun.class,
                       DebugTestRun.class
                     })
 public final class YarnTestSuite {