Date: Tuesday, February 6, 2007 @ 12:40:50
Author: marc
Path: /cvsroot/carob/carob/test
Modified: ConnectionSetup.cpp (1.18 -> 1.19)
Implemented connection reuse. Enabled by default for stronger checks. Useful
for CAROB-124.
---------------------+
ConnectionSetup.cpp | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
Index: carob/test/ConnectionSetup.cpp
diff -u carob/test/ConnectionSetup.cpp:1.18 carob/test/ConnectionSetup.cpp:1.19
--- carob/test/ConnectionSetup.cpp:1.18 Mon Jan 29 15:46:22 2007
+++ carob/test/ConnectionSetup.cpp Tue Feb 6 12:40:50 2007
@@ -32,6 +32,7 @@
using namespace CarobNS;
+// statics initialization
#ifdef CAROB_TEST_USE_MYSQL
const std::wstring& ConnectionSetup::DEFAULT_HOST1 = L"node1";
const std::wstring& ConnectionSetup::DEFAULT_HOST2 = L"node2";
@@ -55,8 +56,31 @@
const bool ConnectionSetup::DEFAULT_CONNECTION_PERSISTENCY =
ConnectionParameters::DEFAULT_CONNECTION_PERSISTENCY;
const bool ConnectionSetup::DEFAULT_RETRIEVE_SQL_WARNINGS =
ConnectionParameters::DEFAULT_RETRIEVE_SQL_WARNINGS;
+namespace {
+ // try to reuse lastConnection?
+ const bool reuseConnection = true;
+ Connection* lastConnection = NULL;
+}
+
+
void ConnectionSetup::setUp()
{
+ static const wchar_t fctName[] = L"ConnectionSetup::setUp()";
+
+ if (reuseConnection)
+ {
+ if (lastConnection != NULL
+ && ! lastConnection->isClosed())
+ {
+ logInfo(fctName, L"reusing lastConnection");
+ connectionPtr = lastConnection;
+ return; // reuse success
+ }
+ else // reuse failed: reconnect
+ logInfo(fctName, std::wstring(L"lastConnection was ")
+ + (lastConnection ? L" closed" : L" NULL"));
+ }
+
std::vector<ControllerInfo> ctrls;
ctrls.push_back(ControllerInfo(ConnectionSetup::DEFAULT_HOST1,
DEFAULT_PORT1));
ctrls.push_back(ControllerInfo(ConnectionSetup::DEFAULT_HOST2,
DEFAULT_PORT2));
@@ -79,12 +103,18 @@
connectionPtr = NULL;
CPPUNIT_ASSERT_MESSAGE("Could not connect to default host", false);
}
+
+ lastConnection = connectionPtr;
+
}
void ConnectionSetup::tearDown()
{
- if (connectionPtr)
- delete connectionPtr;
+ if (reuseConnection)
+ return;
+
+ delete connectionPtr;
+ lastConnection = NULL;
}
void dropTableIfExists(Connection *conn_p, const std::wstring& tableName)
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits