Date: Friday, February 24, 2006 @ 12:58:06
Author: gilles
Path: /cvsroot/carob/carob/test/10-Connection
Added: TestFailOver.cpp (1.1) TestFailOver.hpp (1.1)
(new files)
Added failover testing
Only two tests enabled because because big one requires user interaction
------------------+
TestFailOver.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++
TestFailOver.hpp | 69 ++++++++++++++++++++++
2 files changed, 233 insertions(+)
Index: carob/test/10-Connection/TestFailOver.cpp
diff -u /dev/null carob/test/10-Connection/TestFailOver.cpp:1.1
--- /dev/null Fri Feb 24 12:58:06 2006
+++ carob/test/10-Connection/TestFailOver.cpp Fri Feb 24 12:58:06 2006
@@ -0,0 +1,164 @@
+/*
+ * 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 "TestFailOver.hpp"
+
+#include "Statement.hpp"
+#include "Connection.hpp"
+
+#include "Common.hpp"
+
+#include <string>
+#include <iostream>
+
+using std::wstring;
+
+using namespace CarobNS;
+
+void TestFailOver::setUp()
+{
+}
+
+void TestFailOver::tearDown()
+{
+}
+
+void TestFailOver::testReconnectNoControllers()
+{
+ // this is a dummy port
+ ConnectionParameters connectionPrms(L"localhost",
+ 12345,
+ L"myDB",
+ L"user",
+ L"",
+ DEBUG_LEVEL_DEBUG);
+ // 1st try with only 1 failing ctrler
+ try
+ {
+ Connection* connectionPtr = new Connection(connectionPrms);
+ connectionPtr->setAutoCommit(false); //just to avoid unused variable
warning
+ }
+ catch (ConnectionException ce)
+ {
+ if (isInfoEnabled())
+ logError(L"TestFailOver::testReconnectNoControllers",
+ L"new Connection throw connection exception (this is ok): "
+ + ce.description());
+ }
+ // 2nd try with 2 (first one is now suspected of failure...
+ connectionPrms.addController(L"localhost", 12346);
+ connectionPrms.addController(L"localhost", 12347);
+ try
+ {
+ Connection* connectionPtr = new Connection(connectionPrms);
+ connectionPtr->setAutoCommit(false); //just to avoid unused variable
warning
+ }
+ catch (ConnectionException ce)
+ {
+ if (isInfoEnabled())
+ logError(L"TestFailOver::testReconnectNoControllers",
+ L"new Connection throw connection exception (this is ok): "
+ + ce.description());
+ }
+}
+
+void TestFailOver::testConnectOnlyOneControllerUp()
+{
+ // this is a dummy port
+ ConnectionParameters connectionPrms(L"localhost",
+ 12348,
+ L"myDB",
+ L"user",
+ L"",
+ DEBUG_LEVEL_DEBUG);
+ // 2nd controller is down too
+ connectionPrms.addController(L"localhost", 12349);
+ // 3rd controller is ok
+ connectionPrms.addController(L"localhost", 25322);
+ // 4th is down
+ connectionPrms.addController(L"localhost", 12350);
+ Connection* connectionPtr = new Connection(connectionPrms);
+ //no exception.. good. clean the connection
+ delete connectionPtr;
+}
+
+void TestFailOver::testReconnect()
+{
+ // this is a dummy controller
+ ConnectionParameters connectionPrms(L"localhost",
+ 25324,
+ L"myDB",
+ L"user",
+ L"",
+ DEBUG_LEVEL_DEBUG);
+ // this one will work
+ connectionPrms.addController(L"localhost", 25322);
+ // this one too
+ connectionPrms.addController(L"localhost", 25323);
+ Connection* connectionPtr = new Connection(connectionPrms);
+ Statement* statementPtr = connectionPtr->createStatement();
+
+ wstring fctName(L"TestExecWriteRequest::testReconnect");
+ wstring requestBegin = L"UPDATE product SET cost=";
+ wstring requestEnd = L" where id=";
+
+// int nbRowsAffected;
+ bool rsuc;
+ if (isInfoEnabled())
+ logInfo(fctName, L"Executing 1000 writes");
+ for (int i=0; i<1000; i++)
+ {
+ try
+ {
+// nbRowsAffected = statementPtr->executeUpdate(
+// requestBegin + toWString(i) + requestEnd + toWString(i%50));
+ rsuc = statementPtr->execute(
+ requestBegin + toWString(i) + requestEnd + toWString(i%50));
+ }
+ catch (NoMoreControllerException nmce)
+ {
+ if (isInfoEnabled())
+ logError(fctName, L"Write failed (this is ok). Exception:"
+ + nmce.description());
+ }
+// CPPUNIT_ASSERT(nbRowsAffected == 1);
+ CPPUNIT_ASSERT(rsuc == false);
+ sleep(1);
+ }
+}
+
+CppUnit::Test* TestFailOver::suite()
+{
+ CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "TestFailOver" );
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestFailOver>(
+ "TestFailOver::testReconnectNoControllers",
+ &TestFailOver::testReconnectNoControllers));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestFailOver>(
+
"TestFailOver::testConnectOnlyOneControllerUp",
+
&TestFailOver::testConnectOnlyOneControllerUp));
+//disabled test: needs user interaction
+/* suiteOfTests->addTest(new CppUnit::TestCaller<TestFailOver>(
+ "TestFailOver::testReconnect",
+ &TestFailOver::testReconnect));
+*/
+
+ return suiteOfTests;
+}
Index: carob/test/10-Connection/TestFailOver.hpp
diff -u /dev/null carob/test/10-Connection/TestFailOver.hpp:1.1
--- /dev/null Fri Feb 24 12:58:06 2006
+++ carob/test/10-Connection/TestFailOver.hpp Fri Feb 24 12:58:06 2006
@@ -0,0 +1,69 @@
+/*
+ * 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 TESTFAILOVER_H_
+#define TESTFAILOVER_H_
+
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/TestCase.h>
+#include <cppunit/TestSuite.h>
+#include <cppunit/TestCaller.h>
+
+#include "Connection.hpp"
+
+/**
+ * Test class for controller connection policy
+ * Tests suspected controller queuing and update
+ * A controller *MUST* run locally for test success !!!
+ */
+class TestFailOver : CppUnit::TestFixture
+{
+public:
+ /** Suite of tests to be run */
+ static CppUnit::Test* suite();
+
+ /** Nothing to setup / tear down*/
+ void setUp();
+ void tearDown();
+ /**
+ * Tries to connect to 1 then 2 failing controllers (actually with dummy
ports)
+ */
+ void testReconnectNoControllers();
+ /**
+ * Tries to connect to a list of controller in which only 1 ctrller is up
+ */
+ void testConnectOnlyOneControllerUp();
+ /**
+ * USER INTERACTION NEEDED !
+ * Launches 1000 write requests having 2 controllers.
+ * During these writes, the user has to stop one of the controllers and check
+ * that the other one is connected to silently
+ * Stop controller preferably with iptables. Command for iptables:
+ * > iptables -A INPUT -i lo -p tcp --dport 25322 -d localhost -j REJECT
--reject-with tcp-reset
+ * to restore traffic:
+ * > iptables -D INPUT 1
+ */
+ void testReconnect();
+private:
+};
+
+#endif /*TESTFAILOVER_H_*/
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits