|
@@ -36,6 +36,10 @@ class Zookeeper_operations : public CPPUNIT_NS::TestFixture
|
|
|
CPPUNIT_TEST(testCloseWhileInProgressFromCompletion);
|
|
|
CPPUNIT_TEST(testCloseWhileMultiInProgressFromMain);
|
|
|
CPPUNIT_TEST(testCloseWhileMultiInProgressFromCompletion);
|
|
|
+ CPPUNIT_TEST(testConnectResponseFull);
|
|
|
+ CPPUNIT_TEST(testConnectResponseNoReadOnlyFlag);
|
|
|
+ CPPUNIT_TEST(testConnectResponseSplitAtReadOnlyFlag);
|
|
|
+ CPPUNIT_TEST(testConnectResponseNoReadOnlyFlagSplit);
|
|
|
#else
|
|
|
CPPUNIT_TEST(testAsyncWatcher1);
|
|
|
CPPUNIT_TEST(testAsyncGetOperation);
|
|
@@ -710,6 +714,126 @@ public:
|
|
|
CPPUNIT_ASSERT_EQUAL((int)ZCLOSING,res2.rc_);
|
|
|
}
|
|
|
|
|
|
+ void testConnectResponseFull()
|
|
|
+ {
|
|
|
+ CloseFinally guard(&zh);
|
|
|
+ Mock_socket socketMock;
|
|
|
+ HandshakeResponse hsResponse;
|
|
|
+ std::string hsResponseData = hsResponse.toString();
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(hsResponseData.length(), static_cast<size_t>(41));
|
|
|
+
|
|
|
+ zh = zookeeper_init("localhost:2121", watcher, 10000, NULL, NULL, 0);
|
|
|
+ CPPUNIT_ASSERT(zh!=0);
|
|
|
+
|
|
|
+ int rc, fd, interest;
|
|
|
+ timeval tv;
|
|
|
+
|
|
|
+ rc = zookeeper_interest(zh, &fd, &interest, &tv);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ socketMock.recvReturnBuffer = hsResponseData;
|
|
|
+ rc = zookeeper_process(zh, interest);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE, static_cast<int>(zh->state));
|
|
|
+ }
|
|
|
+
|
|
|
+ void testConnectResponseNoReadOnlyFlag()
|
|
|
+ {
|
|
|
+ CloseFinally guard(&zh);
|
|
|
+ Mock_socket socketMock;
|
|
|
+ HandshakeResponse hsResponse;
|
|
|
+
|
|
|
+ hsResponse.omitReadOnly = true;
|
|
|
+
|
|
|
+ std::string hsResponseData = hsResponse.toString();
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(hsResponseData.length(), static_cast<size_t>(40));
|
|
|
+
|
|
|
+ zh = zookeeper_init("localhost:2121", watcher, 10000, NULL, NULL, 0);
|
|
|
+ CPPUNIT_ASSERT(zh!=0);
|
|
|
+
|
|
|
+ int rc, fd, interest;
|
|
|
+ timeval tv;
|
|
|
+
|
|
|
+ rc = zookeeper_interest(zh, &fd, &interest, &tv);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ socketMock.recvReturnBuffer = hsResponseData;
|
|
|
+ rc = zookeeper_process(zh, interest);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE, static_cast<int>(zh->state));
|
|
|
+ }
|
|
|
+
|
|
|
+ void testConnectResponseSplitAtReadOnlyFlag()
|
|
|
+ {
|
|
|
+ CloseFinally guard(&zh);
|
|
|
+ Mock_socket socketMock;
|
|
|
+ HandshakeResponse hsResponse;
|
|
|
+ std::string hsResponseData = hsResponse.toString();
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(hsResponseData.length(), static_cast<size_t>(41));
|
|
|
+
|
|
|
+ zh = zookeeper_init("localhost:2121", watcher, 10000, NULL, NULL, 0);
|
|
|
+ CPPUNIT_ASSERT(zh!=0);
|
|
|
+
|
|
|
+ int rc, fd, interest;
|
|
|
+ timeval tv;
|
|
|
+
|
|
|
+ rc = zookeeper_interest(zh, &fd, &interest, &tv);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ socketMock.recvReturnBuffer = hsResponseData.substr(0, 40);
|
|
|
+ rc = zookeeper_process(zh, interest);
|
|
|
+ // Response not complete.
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZNOTHING), rc);
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE, static_cast<int>(zh->state));
|
|
|
+
|
|
|
+ socketMock.recvReturnBuffer = hsResponseData.substr(40);
|
|
|
+ rc = zookeeper_process(zh, interest);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE, static_cast<int>(zh->state));
|
|
|
+ }
|
|
|
+
|
|
|
+ void testConnectResponseNoReadOnlyFlagSplit()
|
|
|
+ {
|
|
|
+ CloseFinally guard(&zh);
|
|
|
+ Mock_socket socketMock;
|
|
|
+ HandshakeResponse hsResponse;
|
|
|
+
|
|
|
+ hsResponse.omitReadOnly = true;
|
|
|
+
|
|
|
+ std::string hsResponseData = hsResponse.toString();
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(hsResponseData.length(), static_cast<size_t>(40));
|
|
|
+
|
|
|
+ zh = zookeeper_init("localhost:2121", watcher, 10000, NULL, NULL, 0);
|
|
|
+ CPPUNIT_ASSERT(zh!=0);
|
|
|
+
|
|
|
+ int rc, fd, interest;
|
|
|
+ timeval tv;
|
|
|
+
|
|
|
+ rc = zookeeper_interest(zh, &fd, &interest, &tv);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ socketMock.recvReturnBuffer = hsResponseData.substr(0, 20);
|
|
|
+ rc = zookeeper_process(zh, interest);
|
|
|
+ // Response not complete.
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZNOTHING), rc);
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE, static_cast<int>(zh->state));
|
|
|
+
|
|
|
+ socketMock.recvReturnBuffer = hsResponseData.substr(20);
|
|
|
+ rc = zookeeper_process(zh, interest);
|
|
|
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(ZOK), rc);
|
|
|
+
|
|
|
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE, static_cast<int>(zh->state));
|
|
|
+ }
|
|
|
+
|
|
|
#else
|
|
|
class TestGetDataJob: public TestJob{
|
|
|
public:
|