diff options
author | tison <wander4096@gmail.com> | 2022-06-27 08:19:39 +0200 |
---|---|---|
committer | Mate Szalay-Beko <symat@apache.com> | 2022-06-27 08:19:39 +0200 |
commit | de7c5869d372e46af43979134d0e30b49d2319b1 (patch) | |
tree | 7596ae130b7f55f923442fe63cb428cee6fd2628 /zookeeper-server/src/test/java/org/apache/zookeeper | |
parent | b34e1716e8fa430690252288f2e15c38fe65f325 (diff) | |
download | zookeeper-de7c5869d372e46af43979134d0e30b49d2319b1.tar.gz |
ZOOKEEPER-4492: Merge readOnly field into ConnectRequest and Response
According to [this comment in ZOOKEEPER-102](https://issues.apache.org/jira/browse/ZOOKEEPER-102?focusedCommentId=16977000&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16977000) I introduce a `Protocol` abstraction and going to moving all wire protocol concept into `cnxn` and this scope, so that client and server's business logics handle only deserialized/real record.
cc eolivelli maoling Randgalt
This supersedes #1832.
Author: tison <wander4096@gmail.com>
Reviewers: Enrico Olivelli <eolivelli@apache.org>, Mate Szalay-Beko <symat@apache.org>
Closes #1837 from tisonkun/protocol
Diffstat (limited to 'zookeeper-server/src/test/java/org/apache/zookeeper')
7 files changed, 10 insertions, 33 deletions
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/MockPacket.java b/zookeeper-server/src/test/java/org/apache/zookeeper/MockPacket.java index 9d880fd39..e4e6548ea 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/MockPacket.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/MockPacket.java @@ -35,16 +35,6 @@ public class MockPacket extends ClientCnxn.Packet { super(requestHeader, replyHeader, request, response, watchRegistration); } - public MockPacket( - RequestHeader requestHeader, - ReplyHeader replyHeader, - Record request, - Record response, - WatchRegistration watchRegistration, - boolean readOnly) { - super(requestHeader, replyHeader, request, response, watchRegistration, readOnly); - } - public ByteBuffer createAndReturnBB() { createBB(); return this.bb; diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerCreationTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerCreationTest.java index 03f6113de..ac46b4e0f 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerCreationTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerCreationTest.java @@ -48,7 +48,6 @@ public class ZooKeeperServerCreationTest { zks.setZKDatabase(new ZKDatabase(fileTxnSnapLog)); zks.createSessionTracker(); - ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); ServerCnxn cnxn = new MockServerCnxn(); ConnectRequest connReq = new ConnectRequest(); diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerTest.java index bd1412069..4d41dac1a 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperServerTest.java @@ -162,10 +162,9 @@ public class ZooKeeperServerTest extends ZKTestCase { output.put((byte) 1); output.flip(); - ServerCnxn.CloseRequestException e = assertThrows(ServerCnxn.CloseRequestException.class, () -> { - final NIOServerCnxn nioServerCnxn = mock(NIOServerCnxn.class); - zooKeeperServer.processConnectRequest(nioServerCnxn, output); - }); + ServerCnxn.CloseRequestException e = assertThrows( + ServerCnxn.CloseRequestException.class, + () -> zooKeeperServer.processConnectRequest(new MockServerCnxn(), output)); assertEquals(e.getReason(), ServerCnxn.DisconnectReason.CLIENT_ZXID_AHEAD); } diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServerTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServerTest.java index 165dbdca1..3ee6016f0 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServerTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServerTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import java.nio.ByteBuffer; -import org.apache.zookeeper.server.NIOServerCnxn; +import org.apache.zookeeper.server.MockServerCnxn; import org.apache.zookeeper.server.ServerCnxn; import org.apache.zookeeper.server.ZKDatabase; import org.apache.zookeeper.server.ZooKeeperServer; @@ -55,8 +55,7 @@ public class ReadOnlyZooKeeperServerTest { output.flip(); ServerCnxn.CloseRequestException e = assertThrows(ServerCnxn.CloseRequestException.class, () -> { - final NIOServerCnxn nioServerCnxn = mock(NIOServerCnxn.class); - readOnlyZooKeeperServer.processConnectRequest(nioServerCnxn, output); + readOnlyZooKeeperServer.processConnectRequest(new MockServerCnxn(), output); }); assertEquals(e.getReason(), ServerCnxn.DisconnectReason.NOT_READ_ONLY_CLIENT); } diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java index 70f1844ea..2fadcf36f 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java @@ -255,8 +255,8 @@ public class WatchLeakTest { Random r = new Random(SESSION_ID ^ superSecret); byte[] p = new byte[16]; r.nextBytes(p); - ConnectRequest conReq = new ConnectRequest(0, 1L, 30000, SESSION_ID, p); - MockPacket packet = new MockPacket(null, null, conReq, null, null, false); + ConnectRequest conReq = new ConnectRequest(0, 1L, 30000, SESSION_ID, p, false); + MockPacket packet = new MockPacket(null, null, conReq, null, null); return packet.createAndReturnBB(); } diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java index f7c7a9534..0034fd6d0 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java @@ -51,18 +51,16 @@ public class MaxCnxnsTest extends ClientBase { } public void run() { - SocketChannel sChannel = null; - try { + try (SocketChannel sChannel = SocketChannel.open()) { /* * For future unwary socket programmers: although connect 'blocks' it * does not require an accept on the server side to return. Therefore * you can not assume that all the sockets are connected at the end of * this for loop. */ - sChannel = SocketChannel.open(); sChannel.connect(new InetSocketAddress(host, port)); // Construct a connection request - ConnectRequest conReq = new ConnectRequest(0, 0, 10000, 0, "password".getBytes()); + ConnectRequest conReq = new ConnectRequest(0, 0, 10000, 0, "password".getBytes(), false); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); boa.writeInt(-1, "len"); @@ -95,14 +93,6 @@ public class MaxCnxnsTest extends ClientBase { } } catch (IOException io) { // "Connection reset by peer" - } finally { - if (sChannel != null) { - try { - sChannel.close(); - } catch (Exception e) { - // Do nothing - } - } } } diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionInvalidationTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionInvalidationTest.java index a9229d2b1..1e7870bd2 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionInvalidationTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionInvalidationTest.java @@ -53,7 +53,7 @@ public class SessionInvalidationTest extends ClientBase { // open a connection boa.writeInt(44, "len"); - ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]); + ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16], false); conReq.serialize(boa, "connect"); // close connection |