Date: Thursday, February 2, 2006 @ 18:20:56
Author: gilles
Path: /cvsroot/carob/carob/test
Added: 10-Connection/TestControllerConnectPolicy.cpp (1.1)
10-Connection/TestControllerConnectPolicy.hpp (1.1)
Modified: CarobTestLauncher.cpp (1.20 -> 1.21)
Added tests on round robin policy
Added one test on suspect list update. This test is disabled by default because
it needs user interaction
-----------------------------------------------+
10-Connection/TestControllerConnectPolicy.cpp | 154 ++++++++++++++++++++++++
10-Connection/TestControllerConnectPolicy.hpp | 68 ++++++++++
CarobTestLauncher.cpp | 3
3 files changed, 224 insertions(+), 1 deletion(-)
Index: carob/test/10-Connection/TestControllerConnectPolicy.cpp
diff -u /dev/null carob/test/10-Connection/TestControllerConnectPolicy.cpp:1.1
--- /dev/null Thu Feb 2 18:20:56 2006
+++ carob/test/10-Connection/TestControllerConnectPolicy.cpp Thu Feb 2
18:20:56 2006
@@ -0,0 +1,154 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed 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.
+ *
+ * Initial developer(s): Gilles Rayrat
+ * Contributor(s):
+ */
+
+#include "TestControllerConnectPolicy.hpp"
+
+#include "ControllerConnectPolicy.hpp"
+
+#include "Common.hpp"
+
+#include <string>
+#include <iostream>
+
+using std::wstring;
+
+using namespace CarobNS;
+
+void TestControllerConnectPolicy::setUp()
+{
+}
+
+void TestControllerConnectPolicy::tearDown()
+{
+}
+
+void TestControllerConnectPolicy::testRoundRobinSequence()
+{
+ wstring fctName(L"TestControllerConnectPolicy::testSuspectListUpdate");
+
+ ControllerInfo c1(L"localhost", 4000);
+ ControllerInfo c2(L"localhost", 4001);
+ ControllerInfo c3(L"localhost", 4002);
+ ControllerInfo c4(L"localhost", 4003);
+
+ std::vector<ControllerInfo> v;
+ v.push_back(c1);
+ v.push_back(c2);
+ v.push_back(c3);
+ v.push_back(c4);
+
+ RoundRobinConnectPolicy cp(v);
+ CPPUNIT_ASSERT(cp.getController() == c1);
+ cp.suspectControllerOfFailure(c2);
+ cp.suspectControllerOfFailure(c4);
+ CPPUNIT_ASSERT(cp.getController() == c3);
+ CPPUNIT_ASSERT(cp.getController() == c1);
+ //clean up suspect list
+ cp.removeControllerFromSuspectList(c2);
+ cp.removeControllerFromSuspectList(c4);
+
+}
+
+void TestControllerConnectPolicy::testNoMoreController()
+{
+ wstring fctName(L"TestControllerConnectPolicy::testNoMoreController");
+
+ ControllerInfo c1(L"localhost", 4000);
+ ControllerInfo c2(L"localhost", 4001);
+ ControllerInfo c3(L"localhost", 4002);
+ ControllerInfo c4(L"localhost", 4003);
+
+ std::vector<ControllerInfo> v;
+ v.push_back(c1);
+ v.push_back(c2);
+ v.push_back(c3);
+ v.push_back(c4);
+
+ RoundRobinConnectPolicy cp(v);
+ cp.suspectControllerOfFailure(c1);
+ cp.suspectControllerOfFailure(c2);
+ cp.suspectControllerOfFailure(c3);
+ cp.suspectControllerOfFailure(c4);
+
+ try
+ {
+ if (isDebugEnabled())
+ logDebug(fctName, L"Trying to get controller - should fail");
+ cp.getController();
+ CPPUNIT_ASSERT(false); //should have thrown an exception
+ }
+ catch (NoMoreControllerException nmce)
+ {
+ if (isErrorEnabled())
+ logError(fctName, L"getController() failed (this is ok). Exception: "
+ + nmce.description());
+ }
+ //clean up suspect list
+ cp.removeControllerFromSuspectList(c1);
+ cp.removeControllerFromSuspectList(c2);
+ cp.removeControllerFromSuspectList(c3);
+ cp.removeControllerFromSuspectList(c4);
+}
+
+
+void TestControllerConnectPolicy::testSuspectListUpdate()
+{
+ wstring fctName(L"TestControllerConnectPolicy::testSuspectListUpdate");
+ std::wcerr<<L"Launch 4 servers on localhost:4000-4003 and press
<return>"<<std::endl;
+ std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+
+ ControllerInfo c1(L"localhost", 4000);
+ ControllerInfo c2(L"localhost", 4001);
+ ControllerInfo c3(L"localhost", 4002);
+ ControllerInfo c4(L"localhost", 4003);
+
+ std::vector<ControllerInfo> v;
+ v.push_back(c1);
+ v.push_back(c2);
+ v.push_back(c3);
+ v.push_back(c4);
+
+ RoundRobinConnectPolicy cp(v);
+ cp.suspectControllerOfFailure(c1);
+ cp.suspectControllerOfFailure(c2);
+ CPPUNIT_ASSERT(cp.getController() == c3);
+ CPPUNIT_ASSERT(cp.getController() == c4);
+ cp.updateSuspectList();
+ CPPUNIT_ASSERT(cp.getController() == c1);
+ CPPUNIT_ASSERT(cp.getController() == c2);
+}
+
+CppUnit::Test* TestControllerConnectPolicy::suite()
+{
+ CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite(
"TestControllerConnectPolicy" );
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestControllerConnectPolicy>(
+
"TestControllerConnectPolicy::testRoundRobinSequence",
+
&TestControllerConnectPolicy::testRoundRobinSequence));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestControllerConnectPolicy>(
+
"TestControllerConnectPolicy::testNoMoreController",
+
&TestControllerConnectPolicy::testNoMoreController));
+//Test disabled, needs user interaction
+/* suiteOfTests->addTest(new CppUnit::TestCaller<TestControllerConnectPolicy>(
+
"TestControllerConnectPolicy::testSuspectListUpdate",
+
&TestControllerConnectPolicy::testSuspectListUpdate));
+*/
+ return suiteOfTests;
+}
Index: carob/test/10-Connection/TestControllerConnectPolicy.hpp
diff -u /dev/null carob/test/10-Connection/TestControllerConnectPolicy.hpp:1.1
--- /dev/null Thu Feb 2 18:20:56 2006
+++ carob/test/10-Connection/TestControllerConnectPolicy.hpp Thu Feb 2
18:20:56 2006
@@ -0,0 +1,68 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005-2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed 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.
+ *
+ * Initial developer(s): Gilles Rayrat
+ * Contributor(s):
+ */
+
+#ifndef TESTCONTROLLERCONNECTPOLICY_H_
+#define TESTCONTROLLERCONNECTPOLICY_H_
+
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/TestCase.h>
+#include <cppunit/TestSuite.h>
+#include <cppunit/TestCaller.h>
+
+#include "ControllerConnectPolicy.hpp"
+
+/**
+ * Test class for controller connection policy
+ * Tests suspected controller queuing and update
+ * A controller *MUST* run locally for test success !!!
+ */
+class TestControllerConnectPolicy : CppUnit::TestFixture
+{
+public:
+ /** Suite of tests to be run */
+ static CppUnit::Test* suite();
+
+ /** Nothing to setup / tear down*/
+ void setUp();
+ void tearDown();
+ /**
+ * Adds 2 out of 4 controllers to the list of suspects and checks that the
+ * getController function returns the non suspect controller in the good
order
+ */
+ void testRoundRobinSequence();
+ /**
+ * Adds all controllers to the list of suspects and checks that an error is
+ * thrown when asking for another controller (NoMoreControllerException)
+ */
+ void testNoMoreController();
+ /**
+ * Adds valid controllers to the list of suspects and checks that they come
up
+ * again. Note: this test needs 4 (basic) servers to run locally !!! (user
+ * input is asked when servers are ready). These servers can be simulated by
+ * Lenart Janos's socket utility ("socket -s <port>" command)
+ * See http://packages.debian.org/stable/net/socket for more info
+ */
+ void testSuspectListUpdate();
+private:
+};
+
+#endif /*TESTCONTROLLERCONNECTPOLICY_H_*/
Index: carob/test/CarobTestLauncher.cpp
diff -u carob/test/CarobTestLauncher.cpp:1.20
carob/test/CarobTestLauncher.cpp:1.21
--- carob/test/CarobTestLauncher.cpp:1.20 Thu Jan 26 12:12:53 2006
+++ carob/test/CarobTestLauncher.cpp Thu Feb 2 18:20:56 2006
@@ -39,6 +39,7 @@
#include "TestStatement.hpp"
#include "01-Unit/TestStringCodecs.hpp"
#include "10-Connection/TestConnect.hpp"
+#include "10-Connection/TestControllerConnectPolicy.hpp"
#include "30-ResultSet/TestSimpleUnicode.hpp"
#include "40-Parameter-PreparedStatement/TestParameterStatement.hpp"
#include "40-Parameter-PreparedStatement/TestPreparedStatement.hpp"
@@ -67,7 +68,7 @@
runner.addTest(TestSimpleUnicode::suite());
runner.addTest(TestParameterStatement::suite());
runner.addTest(TestIEEE754::suite());
-
+ runner.addTest(TestControllerConnectPolicy::suite());
// add our own protector
CarobProtector* cprot = new CarobProtector();
runner.eventManager().pushProtector(cprot);
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits