Explorar el Código

ZOOKEEPER-4519: Add closeSocket method to Testable interface

This is backwards compatible, since the new method on the `Testable` interface defaults to a no-op.

Author: Houston Putman <houston@apache.org>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, maoling <maoling@apache.org>

Closes #1863 from HoustonPutman/zk-testable-socket-close and squashes the following commits:

1f9d814f5 [Houston Putman] Fix style
475c9f516 [Houston Putman] ZOOKEEPER-4519: Add closeSocket method to Testable interface
Houston Putman hace 3 años
padre
commit
6f0052d841

+ 7 - 0
zookeeper-server/src/main/java/org/apache/zookeeper/Testable.java

@@ -18,6 +18,8 @@
 
 package org.apache.zookeeper;
 
+import java.io.IOException;
+
 /**
  * Abstraction that exposes various methods useful for testing ZooKeeper
  */
@@ -35,4 +37,9 @@ public interface Testable {
      */
     void queueEvent(WatchedEvent event);
 
+    /**
+     * Close the ClientCnxn socket for testing purposes
+     */
+    default void closeSocket() throws IOException { }
+
 }

+ 7 - 0
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperTestable.java

@@ -18,6 +18,7 @@
 
 package org.apache.zookeeper;
 
+import java.io.IOException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,4 +48,10 @@ class ZooKeeperTestable implements Testable {
         clientCnxn.eventThread.queueEvent(event);
     }
 
+    @Override
+    public void closeSocket() throws IOException {
+        LOG.info("closeSocket() called");
+        clientCnxn.sendThread.testableCloseSocket();
+    }
+
 }