[ 
https://issues.apache.org/jira/browse/GEODE-8650?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17220860#comment-17220860
 ] 

ASF GitHub Bot commented on GEODE-8650:
---------------------------------------

kirklund commented on a change in pull request #5664:
URL: https://github.com/apache/geode/pull/5664#discussion_r512145587



##########
File path: 
geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedReference.java
##########
@@ -187,47 +197,76 @@ public V get() {
    * @param newValue the new value
    */
   public DistributedReference<V> set(V newValue) {
-    REFERENCE.set(newValue);
+    REFERENCE.get().put(identity, newValue);
     return this;
   }
 
+  @Override
+  protected void before() {
+    invoker().invokeInEveryVMAndController(() -> invokeBefore());
+  }
+
   @Override
   protected void after() {
-    invoker().invokeInEveryVMAndController(this::invokeAfter);
+    invoker().invokeInEveryVMAndController(() -> invokeAfter());
+  }
+
+  protected void afterCreateVM(VM vm) {
+    vm.invoke(() -> invokeBefore());
+  }
+
+  protected void beforeBounceVM(VM vm) {
+    // override if needed
+  }
+
+  protected void afterBounceVM(VM vm) {
+    vm.invoke(() -> invokeBefore());
+  }
+
+  private void invokeBefore() {
+    REFERENCE.compareAndSet(null, new HashMap<>());
+    REFERENCE.get().putIfAbsent(identity, null);
   }
 
   private void invokeAfter() {
-    V value = get();
-    if (value == null) {
+    Map<Integer, Object> references = REFERENCE.getAndSet(null);
+    if (references == null) {
+      return;
+    }
+
+    for (Object object : references.values()) {
+      invokeAfter(object);
+    }
+  }
+
+  private void invokeAfter(Object object) {
+    if (object == null) {
       return;
     }
-    REFERENCE.set(null);
 
     if (autoClose.get()) {
-      autoClose(value);
+      autoClose(object);
     }
   }
 
-  private void autoClose(V value) {
-    if (value instanceof AutoCloseable) {
-      close((AutoCloseable) value);
+  private void autoClose(Object object) {
+    if (object instanceof AutoCloseable) {
+      close((AutoCloseable) object);
 
-    } else if (hasMethod(value.getClass(), "close")) {
-      invokeMethod(value, "close");
+    } else if (object instanceof AtomicBoolean) {
+      toFalse((AtomicBoolean) object);
 
-    } else if (hasMethod(value.getClass(), "disconnect")) {
-      invokeMethod(value, "disconnect");
+    } else if (object instanceof CountDownLatch) {
+      openLatch((CountDownLatch) object);
 
-    } else if (hasMethod(value.getClass(), "stop")) {
-      invokeMethod(value, "stop");
-    }
-  }
+    } else if (hasMethod(object.getClass(), "close")) {
+      invokeMethod(object, "close");

Review comment:
       New commit includes "Rename all CompletionUtils to close". Please review 
again. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Support using multiple DistributedReference Rules in one test
> -------------------------------------------------------------
>
>                 Key: GEODE-8650
>                 URL: https://issues.apache.org/jira/browse/GEODE-8650
>             Project: Geode
>          Issue Type: Wish
>          Components: tests
>            Reporter: Kirk Lund
>            Assignee: Kirk Lund
>            Priority: Major
>              Labels: pull-request-available
>
> Support using multiple DistributedReference Rules in one test.  Right now the 
> Rule only supports having one instance in a test.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to