geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [16/54] [abbrv] incubator-geode git commit: GEODE-1097 allow Lambda invocations to be named so that they show up in test logs
Date Mon, 21 Mar 2016 20:39:47 GMT
GEODE-1097 allow Lambda invocations to be named so that they show up in test logs

This adds variants of VM.invoke() and VM.invokeAsync() that take a String name
for the invocation that will be logged during dunit testing.


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

Branch: refs/heads/feature/GEODE-17-2
Commit: 22ab27067c74eae5b2af799d6453dad461f98eec
Parents: ce8d087
Author: Bruce Schuchardt <bschuchardt@pivotal.io>
Authored: Tue Mar 15 10:58:06 2016 -0700
Committer: Bruce Schuchardt <bschuchardt@pivotal.io>
Committed: Tue Mar 15 10:59:17 2016 -0700

----------------------------------------------------------------------
 .../cache30/ClientMembershipDUnitTest.java      | 14 +++--
 .../gemfire/test/dunit/NamedCallable.java       | 26 +++++++++
 .../gemfire/test/dunit/NamedRunnable.java       | 26 +++++++++
 .../com/gemstone/gemfire/test/dunit/VM.java     | 61 ++++++++++++++++++++
 .../test/dunit/tests/BasicDUnitTest.java        | 24 ++++++++
 5 files changed, 146 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22ab2706/geode-core/src/test/java/com/gemstone/gemfire/cache30/ClientMembershipDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/ClientMembershipDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/cache30/ClientMembershipDUnitTest.java
index d4678ca..19ce28d 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/ClientMembershipDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/ClientMembershipDUnitTest.java
@@ -804,10 +804,11 @@ public class ClientMembershipDUnitTest extends ClientServerTestCase
{
     });
     
     // gather details for later creation of ConnectionPool...
-    ports[0] = vm0.invoke(() -> ClientMembershipDUnitTest.getTestClientMembershipEventsInClient_port());
+    ports[0] = vm0.invoke("getTestClientMembershipEventsInClient_port",
+        () -> ClientMembershipDUnitTest.getTestClientMembershipEventsInClient_port());
     assertTrue(ports[0] != 0);
 
-    DistributedMember serverMember = (DistributedMember) vm0.invoke(() -> ClientMembershipDUnitTest.getDistributedMember());
+    DistributedMember serverMember = (DistributedMember) vm0.invoke("get distributed member",
() -> ClientMembershipDUnitTest.getDistributedMember());
 
     String serverMemberId = serverMember.toString();
 
@@ -1440,7 +1441,8 @@ public class ClientMembershipDUnitTest extends ClientServerTestCase
{
             getDistributedMember());
         }
       });
-      ports[whichVM] = vm.invoke(() -> ClientMembershipDUnitTest.getTestGetConnectedServers_port());
+      ports[whichVM] = vm.invoke("getTestGetConnectedServers_port",
+          () -> ClientMembershipDUnitTest.getTestGetConnectedServers_port());
       assertTrue(ports[whichVM] != 0);
     }
     
@@ -1555,7 +1557,8 @@ public class ClientMembershipDUnitTest extends ClientServerTestCase
{
             getMemberId());
         }
       });
-      ports[whichVM] = vm.invoke(() -> ClientMembershipDUnitTest.getTestGetNotifiedClients_port());
+      ports[whichVM] = vm.invoke("getTestGetNotifiedClients_port",
+          () -> ClientMembershipDUnitTest.getTestGetNotifiedClients_port());
       assertTrue(ports[whichVM] != 0);
     }
     
@@ -1599,7 +1602,8 @@ public class ClientMembershipDUnitTest extends ClientServerTestCase
{
           }
         }
       });
-      clientCounts[whichVM] = vm.invoke(() -> ClientMembershipDUnitTest.getTestGetNotifiedClients_clientCount());
+      clientCounts[whichVM] = vm.invoke("getTestGetNotifiedClients_clientCount",
+          () -> ClientMembershipDUnitTest.getTestGetNotifiedClients_clientCount());
     }
     
     // only one server should have a notifier for this client...

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22ab2706/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedCallable.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedCallable.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedCallable.java
new file mode 100755
index 0000000..66a3f38
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedCallable.java
@@ -0,0 +1,26 @@
+package com.gemstone.gemfire.test.dunit;
+
+
+public class NamedCallable<T> implements SerializableCallableIF<T> {
+
+  private static final long serialVersionUID = -4417299628656632541L;
+
+  String name;
+  SerializableCallableIF<T> delegate;
+  
+  public NamedCallable(String name, SerializableCallableIF<T> delegate) {
+    this.name = name;
+    this.delegate = delegate;
+  }
+  
+  @Override
+  public T call() throws Exception {
+    return delegate.call();
+  }
+  
+  @Override
+  public String toString() {
+    return ("callable("+name+")");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22ab2706/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedRunnable.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedRunnable.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedRunnable.java
new file mode 100755
index 0000000..8a7fe28
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NamedRunnable.java
@@ -0,0 +1,26 @@
+package com.gemstone.gemfire.test.dunit;
+
+
+public class NamedRunnable implements SerializableRunnableIF {
+
+  private static final long serialVersionUID = -2786841298145567914L;
+
+  String name;
+  SerializableRunnableIF delegate;
+  
+  public NamedRunnable(String name, SerializableRunnableIF delegate) {
+    this.name = name;
+    this.delegate = delegate;
+  }
+  
+  @Override
+  public void run() throws Exception {
+    delegate.run();
+  }
+  
+  @Override
+  public String toString() {
+    return ("runnable("+name+")");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22ab2706/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java
index 122aa0e..8e408dc 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/VM.java
@@ -246,6 +246,37 @@ public class VM implements Serializable {
   }
   
   /**
+   * Invokes the <code>run</code> method of a {@link Runnable} in this
+   * VM.  Recall that <code>run</code> takes no arguments and has no
+   * return value.  The Runnable is wrapped in a NamedRunnable having
+   * the given name so it shows up in dunit logs.
+   *
+   * @param r
+   *        The <code>Runnable</code> to be run
+   * @param name the name of the runnable, which will be logged in dunit output
+   *
+   * @see SerializableRunnable
+   */
+  public AsyncInvocation invokeAsync(String name, SerializableRunnableIF r) {
+    NamedRunnable nr = new NamedRunnable(name, r);
+    return invokeAsync(r, "run", new Object[0]);
+  }
+  
+  /**
+   * Invokes the <code>call</code> method of a {@link Runnable} in this
+   * VM.  
+   *
+   * @param c
+   *        The <code>Callable</code> to be run
+   * @param name the name of the callable, which will be logged in dunit output
+   *
+   * @see SerializableCallable
+   */
+  public <T> AsyncInvocation<T> invokeAsync(String name, SerializableCallableIF<T>
c) {
+    return invokeAsync(new NamedCallable(name, c), "call", new Object[0]);
+  }
+
+  /**
    * Invokes the <code>call</code> method of a {@link Runnable} in this
    * VM.  
    *
@@ -265,6 +296,21 @@ public class VM implements Serializable {
    *
    * @param r
    *        The <code>Runnable</code> to be run
+   * @param name the name of the runnable, which will be logged in dunit output
+   *
+   * @see SerializableRunnable
+   */
+  public void invoke(String name, SerializableRunnableIF r) {
+    invoke(new NamedRunnable(name, r), "run");
+  }
+
+  /**
+   * Invokes the <code>run</code> method of a {@link Runnable} in this
+   * VM.  Recall that <code>run</code> takes no arguments and has no
+   * return value.
+   *
+   * @param r
+   *        The <code>Runnable</code> to be run
    *
    * @see SerializableRunnable
    */
@@ -279,6 +325,21 @@ public class VM implements Serializable {
    *
    * @param c
    *        The <code>Callable</code> to be run
+   * @param name the name of the callable, which will be logged in dunit output
+   *
+   * @see SerializableCallable
+   */
+  public <T>  T invoke(String name, SerializableCallableIF<T> c) {
+    return (T) invoke(new NamedCallable(name, c), "call");
+  }
+  
+  /**
+   * Invokes the <code>run</code> method of a {@link Runnable} in this
+   * VM.  Recall that <code>run</code> takes no arguments and has no
+   * return value.
+   *
+   * @param c
+   *        The <code>Callable</code> to be run
    *
    * @see SerializableCallable
    */

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22ab2706/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
index 068e81b..195d5f4 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
@@ -83,6 +83,30 @@ public class BasicDUnitTest extends DistributedTestCase {
     
   }
 
+  public void testInvokeWithNamedLambda() {
+    Host host = Host.getHost(0);
+    VM vm0 = host.getVM(0);
+    VM vm1 = host.getVM(1);
+    
+    int vm0Num = vm0.invoke("getVMID", () -> DUnitEnv.get().getVMID());
+    int vm1Num = vm1.invoke("getVMID", () -> DUnitEnv.get().getVMID());
+    
+    assertEquals(0, vm0Num);
+    assertEquals(1, vm1Num);
+    
+  }
+  
+  public void testInvokeNamedLambdaAsync() throws Throwable {
+    Host host = Host.getHost(0);
+    VM vm0 = host.getVM(0);
+    
+    AsyncInvocation<Integer> async0 = vm0.invokeAsync("getVMID", () -> DUnitEnv.get().getVMID());
+    int vm0num = async0.getResult();
+    
+    assertEquals(0, vm0num);
+    
+  }
+
   static class BasicTestException extends RuntimeException {
     BasicTestException() {
       this("Test exception.  Please ignore.");


Mime
View raw message