Date: Wednesday, February 28, 2007 @ 10:50:09
Author: gilles
Path: /cvsroot/carob/carob/test/10-Connection
Modified: TestControllerPool.cpp (1.9 -> 1.10) TestControllerPool.hpp (1.2
-> 1.3)
Added test showing CAROB-132 - controller sequence not beeing remembered if
connection parameters are deleted in the meantime
------------------------+
TestControllerPool.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++--
TestControllerPool.hpp | 6 ++++
2 files changed, 65 insertions(+), 2 deletions(-)
Index: carob/test/10-Connection/TestControllerPool.cpp
diff -u carob/test/10-Connection/TestControllerPool.cpp:1.9
carob/test/10-Connection/TestControllerPool.cpp:1.10
--- carob/test/10-Connection/TestControllerPool.cpp:1.9 Thu Feb 8 11:06:49 2007
+++ carob/test/10-Connection/TestControllerPool.cpp Wed Feb 28 10:50:09 2007
@@ -27,6 +27,7 @@
#include "ControllerPool.hpp"
#include "Statement.hpp"
#include "Connection.hpp"
+#include "ConnectionParameters.hpp"
#include "Common.hpp"
@@ -47,8 +48,6 @@
void TestControllerPool::testRoundRobinSequence()
{
- const wstring fctName(L"TestControllerPool::testRoundRobinSequence");
-
ControllerInfo c1(ConnectionSetup::DEFAULT_HOST1, 4000);
ControllerInfo c2(ConnectionSetup::DEFAULT_HOST1, 4001);
ControllerInfo c3(ConnectionSetup::DEFAULT_HOST1, 4002);
@@ -69,6 +68,61 @@
v.clear();
}
+void getPoolAndAssertSequence(bool firstCtrlFirst)
+{
+ // Declaring controllers in reverse order on purpose
+ // this will avoid reusing pool from previous tests
+ ControllerInfo c1(ConnectionSetup::DEFAULT_HOST2,
ConnectionSetup::DEFAULT_PORT2);
+ ControllerInfo c2(ConnectionSetup::DEFAULT_HOST1,
ConnectionSetup::DEFAULT_PORT1);
+ std::vector<ControllerInfo> v;
+ v.push_back(c1);
+ v.push_back(c2);
+
+ // Get a new pool
+ ConnectionParameters prms (v, ConnectionSetup::DEFAULT_DB,
+ ConnectionSetup::DEFAULT_USER,
+ ConnectionSetup::DEFAULT_PASSWD);
+ AbstractControllerPool& pool = prms.getControllerPool();
+ // Test sequence
+ if (firstCtrlFirst)
+ {
+ CPPUNIT_ASSERT(pool.getController() == c1);
+ CPPUNIT_ASSERT(pool.getController() == c2);
+ CPPUNIT_ASSERT(pool.getController() == c1);
+ }
+ else
+ {
+ CPPUNIT_ASSERT(pool.getController() == c2);
+ CPPUNIT_ASSERT(pool.getController() == c1);
+ CPPUNIT_ASSERT(pool.getController() == c2);
+ }
+}
+
+void TestControllerPool::testSequenceWithDelete()
+{
+ getPoolAndAssertSequence(true);
+ // In the next call, the pools should be the same.
+ // Check this by asserting that the next ctrl given will be the 2nd one
+ getPoolAndAssertSequence(false);
+ // do another round just to have the second controller as the next one to be
+ // given by the pool
+ getPoolAndAssertSequence(true);
+
+ // Wait 10s, time after wich the pool will be discarded
+ sleep(10);
+
+ // retrieve a fake pool so pools status are updated
+ std::vector<ControllerInfo> vFake;
+ vFake.push_back(ControllerInfo(ConnectionSetup::DEFAULT_HOST1,
ConnectionSetup::DEFAULT_PORT1));
+ ConnectionParameters cpFake(vFake, ConnectionSetup::DEFAULT_DB,
+ ConnectionSetup::DEFAULT_USER,
+ ConnectionSetup::DEFAULT_PASSWD);
+ cpFake.getControllerPool();
+
+ // In this call, the pool should be a new one, the sequence should start
+ // with the first controller first
+ getPoolAndAssertSequence(true);
+}
void TestControllerPool::testNoMoreController()
{
@@ -186,6 +240,9 @@
"10.TestControllerPool::testRoundRobinSequence",
&TestControllerPool::testRoundRobinSequence));
suiteOfTests->addTest(new CppUnit::TestCaller<TestControllerPool>(
+
"10.TestControllerPool::testSequenceWithDelete",
+ &TestControllerPool::testSequenceWithDelete));
+ suiteOfTests->addTest(new CppUnit::TestCaller<TestControllerPool>(
"10.TestControllerPool::testNoMoreController",
&TestControllerPool::testNoMoreController));
suiteOfTests->addTest(new CppUnit::TestCaller<TestControllerPool>(
Index: carob/test/10-Connection/TestControllerPool.hpp
diff -u carob/test/10-Connection/TestControllerPool.hpp:1.2
carob/test/10-Connection/TestControllerPool.hpp:1.3
--- carob/test/10-Connection/TestControllerPool.hpp:1.2 Tue Nov 28 17:07:55 2006
+++ carob/test/10-Connection/TestControllerPool.hpp Wed Feb 28 10:50:09 2007
@@ -51,6 +51,12 @@
*/
void testRoundRobinSequence();
/**
+ * Creates parameters with 2 controllers, gets controllers 3 times checking
+ * the sequence 1-2-1, then deletes parameters and checks that after
creating
+ * new parameters, the retrieved controller is the 2nd one
+ */
+ void testSequenceWithDelete();
+ /**
* Adds all controllers to the list of suspects and checks that an error is
* thrown when asking for another controller (NoMoreControllerException)
*/
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits