Bill commented on a change in pull request #5987:
URL: https://github.com/apache/geode/pull/5987#discussion_r571213320



##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/internal/net/SocketCloserIntegrationTest.java
##########
@@ -113,26 +113,34 @@ public void testAsync() {
    * Verify that requesting an asyncClose on an already closed socket is a 
noop.
    */
   @Test
-  public void testClosedSocket() throws Exception {
-    final AtomicBoolean runnableCalled = new AtomicBoolean();
+  public void testOpenSocketCloser() {
+    final AtomicBoolean beforeSocketCloseRunnableWasCalled = new 
AtomicBoolean();
+    final AtomicBoolean afterSocketCloseRunnableWasCalled = new 
AtomicBoolean();
 
-    Socket s = createClosableSocket();
-    s.close();
-    this.socketCloser.asyncClose(s, "A", () -> runnableCalled.set(true));
-    await().until(() -> !runnableCalled.get());
+    final Socket closableSocket = createClosableSocket();
+    this.socketCloser.asyncClose(closableSocket, "A",

Review comment:
       no `this` needed

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/internal/net/SocketCloserIntegrationTest.java
##########
@@ -113,26 +113,34 @@ public void testAsync() {
    * Verify that requesting an asyncClose on an already closed socket is a 
noop.
    */
   @Test
-  public void testClosedSocket() throws Exception {
-    final AtomicBoolean runnableCalled = new AtomicBoolean();
+  public void testOpenSocketCloser() {
+    final AtomicBoolean beforeSocketCloseRunnableWasCalled = new 
AtomicBoolean();
+    final AtomicBoolean afterSocketCloseRunnableWasCalled = new 
AtomicBoolean();
 
-    Socket s = createClosableSocket();
-    s.close();
-    this.socketCloser.asyncClose(s, "A", () -> runnableCalled.set(true));
-    await().until(() -> !runnableCalled.get());
+    final Socket closableSocket = createClosableSocket();
+    this.socketCloser.asyncClose(closableSocket, "A",
+        () -> beforeSocketCloseRunnableWasCalled.set(true),
+        () -> afterSocketCloseRunnableWasCalled.set(true));
+    await().until(() -> beforeSocketCloseRunnableWasCalled.get());
+    await().until(() -> closableSocket.isClosed());
+    await().until(() -> afterSocketCloseRunnableWasCalled.get());
   }
 
   /**
    * Verify that a closed SocketCloser will still close an open socket
    */
   @Test
   public void testClosedSocketCloser() {
-    final AtomicBoolean runnableCalled = new AtomicBoolean();
+    final AtomicBoolean beforeSocketCloseRunnableWasCalled = new 
AtomicBoolean();
+    final AtomicBoolean afterSocketCloseRunnableWasCalled = new 
AtomicBoolean();
 
     final Socket closableSocket = createClosableSocket();
     this.socketCloser.close();
-    this.socketCloser.asyncClose(closableSocket, "A", () -> 
runnableCalled.set(true));
-    await()
-        .until(() -> runnableCalled.get() && closableSocket.isClosed());
+    this.socketCloser.asyncClose(closableSocket, "A",

Review comment:
       no `this` needed

##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/CacheClientProxy.java
##########
@@ -954,7 +954,9 @@ private boolean closeSocket() {
     String remoteHostAddress = this._remoteHostAddress;
     if (this._socketClosed.compareAndSet(false, true) && remoteHostAddress != 
null) {
       // Only one thread is expected to close the socket
-      this._cacheClientNotifier.getSocketCloser().asyncClose(this._socket, 
remoteHostAddress, null);
+      this._cacheClientNotifier.getSocketCloser().asyncClose(this._socket, 
remoteHostAddress,
+          () -> {
+          });

Review comment:
       no `this`

##########
File path: 
geode-core/src/main/java/org/apache/geode/internal/util/CompletedFuture.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.geode.internal.util;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * CompletedFuture is a Future that reports that it has finished.
+ * It's intended to be used as the initial value of a Future variable
+ * instead of using null.
+ *
+ * @param <T>
+ */
+public class CompletedFuture<T> implements Future<T> {

Review comment:
       Rather than our own class, why not use 
`CompletableFuture.completedFuture(value)`?

##########
File path: 
geode-core/src/main/java/org/apache/geode/distributed/internal/LonerDistributionManager.java
##########
@@ -1054,14 +1055,12 @@ public boolean awaitTermination(long timeout, TimeUnit 
unit) throws InterruptedE
 
     @Override
     public <T> Future<T> submit(final Callable<T> task) {
-      Exception ex = null;
-      T result = null;
       try {
-        result = task.call();
+        T result = task.call();
+        return new CompletedFuture<T>(result);
       } catch (Exception e) {
-        ex = e;
+        return new CompletedFuture<T>(e);

Review comment:
       cleaner!




----------------------------------------------------------------
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:
[email protected]


Reply via email to