Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion native/src/snappyclient/cpp/impl/ControlConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void ControlConnection::failoverToAvailableHost(
protocolFactory = 0;
break;
}
} catch (const TException& te) {
} catch (const TException&) {
failedServers.insert(controlAddr);
if (outTransport != nullptr) {
outTransport->close();
Expand Down
104 changes: 104 additions & 0 deletions native/tests/failoverTest_AddServer_AfterConn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "Connection.h"
#include <iostream>
//#include <fstream>
#include <thread>
using namespace io::snappydata::client;
using namespace std;

void stopServer(string command) {
system(command.c_str());
}

int main(int argc, char **argv) {
Connection conn;
string snappyHomeDir(argv[1]);
string serverStopScript;
serverStopScript.append("cd ").append(snappyHomeDir).append(
"; ./sbin/snappy-server.sh stop -dir=");
string serverStartScript;
serverStartScript.append("cd ").append(snappyHomeDir).append(
"; ./sbin/snappy-server.sh start -locators=localhost:10334 -dir=");
try {
std::map<std::string, std::string> properties;
properties.insert(
std::pair<std::string, std::string>("load-balance", "true"));
conn.open("localhost", 1527, "app", "app", properties);
std::cout << "before stopping server- connected to :"
<< conn.getCurrentHostAddress() << std::endl;
// creating dummy data
conn.execute("drop table if exists FailOverTest.test");
conn.execute("drop schema if exists FailOverTest");
conn.execute("create schema FailOverTest");
conn.execute(
"create table FailOverTest.test(id int) as select id from range(120000)");
auto count = conn.executeQuery("select * from FailOverTest.test");
if (count > 0) {
std::cout << "Query execute successfully before server stop"
<< std::endl;
}
//create directory for a new server 2
string createServerDir;
createServerDir.append("cd ").append(snappyHomeDir).append(
"; mkdir ./work/localhost-server-2");
system(createServerDir.c_str());
//start a server 2
string startNewServer;
startNewServer.append(serverStartScript).append(
"./work/localhost-server-2");
system(startNewServer.c_str());
//put on sleep
std::this_thread::sleep_for(std::chrono::seconds(50));
// stop the connected server 1
string stopRunningServer;
stopRunningServer.append(serverStopScript).append(
"./work/localhost-server-1");
//stop the server
std::thread t1(stopServer, stopRunningServer);
t1.join();

conn.executeQuery("insert into FailOverTest.test (id) values(120001)");
conn.execute("drop table if exists FailOverTest.test2");
conn.execute(
"create table FailOverTest.test2(id int) as select id from range(120000)");
count = conn.executeQuery("select * from FailOverTest.test2");
if (count > 0) {
std::cout << "Query execute successfully after server stop"
<< std::endl;
}
std::cout << "Test executed successfully connected to :"
<< conn.getCurrentHostAddress() << std::endl;
conn.execute("drop table if exists FailOverTest.test");
conn.execute("drop table if exists FailOverTest.test2");
conn.execute("drop schema if exists FailOverTest");
conn.close();
//start the server 1 again
serverStartScript.append("./work/localhost-server-1");
system(serverStartScript.c_str());
std::this_thread::sleep_for(std::chrono::seconds(50));
//stop server 2
serverStopScript.append("./work/localhost-server-2");
system(serverStopScript.c_str());
//remove directory for a new server 2
string removeServerDir;
removeServerDir.append("cd ").append(snappyHomeDir).append(
"; rm -r ./work/localhost-server-2");
system(removeServerDir.c_str());
} catch (SQLException& sqle) {
if (conn.isOpen()) conn.close();
//start the server 1 again
serverStartScript.append("./work/localhost-server-1");
system(serverStartScript.c_str());
std::this_thread::sleep_for(std::chrono::seconds(50));
//stop server 2
serverStopScript.append("./work/localhost-server-2");
system(serverStopScript.c_str());
//remove directory for a new server 2
string removeServerDir;
removeServerDir.append("cd ").append(snappyHomeDir).append(
"; rm -r ./work/localhost-server-2");
system(removeServerDir.c_str());
std::cout << "ExecuteQuery failed, throws exception" << std::endl;
sqle.printStackTrace(std::cout);
}
}

38 changes: 38 additions & 0 deletions native/tests/failoverTest_AddServer_AfterConn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

SNAPPY_HOME_DIR="$1"
_testDir="$2"
_snappyNativeDir="$(dirname "$_testDir")"

#echo "current working dir $_testDir"
#echo "Snappy Native dir- $_snappyNativeDir"

distDir=${_snappyNativeDir}/dist

THRIFT_VERSION=1.0.0-2
BOOST_VERSION=1.65.1

thrftLibPath=${distDir}/thrift-${THRIFT_VERSION}/lin64/lib
boostLibPath=${distDir}/boost-${BOOST_VERSION}/lin64/lib
snappClientLibPath=${_snappyNativeDir}/build-artifacts/lin/libs/snappyclient/static/release

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${thrftLibPath}:${boostLibPath}:${snappClientLibPath}

echo "$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

headerLoc=${_snappyNativeDir}/build-artifacts/lin/snappyclient/include
boostHeadeLoc=${distDir}/boost-${BOOST_VERSION}/include
thriftHeaderLoc=${distDir}/thrift-${THRIFT_VERSION}/include

g++ -std=c++11 -I${headerLoc} -I${boostHeadeLoc} -I${thriftHeaderLoc} -O0 -g3 -Wall -c ${_testDir}/failoverTest_AddServer_AfterConn.cpp -o ${_testDir}/failoverTest_AddServer_AfterConn.o

chmod 777 ${_testDir}/failoverTest_AddServer_AfterConn.o

g++ -L${boostLibPath} -L${thrftLibPath} -L${snappClientLibPath} -o ${_testDir}/failoverTest_AddServer_AfterConn ${_testDir}/failoverTest_AddServer_AfterConn.o -lsnappyclient -lcrypto -lodbc -lpthread -lssl -lboost_chrono -lboost_date_time -lboost_filesystem -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lthrift -lpthread -lrt -lgmp

chmod 777 ${_testDir}/failoverTest_AddServer_AfterConn
cd ${_testDir}
./failoverTest_AddServer_AfterConn $SNAPPY_HOME_DIR

rm failoverTest_AddServer_AfterConn failoverTest_AddServer_AfterConn.o
115 changes: 115 additions & 0 deletions native/tests/failoverTest_AddServer_BeforeConn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "Connection.h"
#include <iostream>
#include <thread>
#include <string>
using namespace io::snappydata::client;
using namespace std;

void stopServer(string command) {
system(command.c_str());
}

int main(int argc, char **argv) {
Connection conn;
string snappyHomeDir(argv[1]);
string serverStopScript;
serverStopScript.append("cd ").append(snappyHomeDir).append(
"; ./sbin/snappy-server.sh stop -dir=");
string serverStartScript;
serverStartScript.append("cd ").append(snappyHomeDir).append(
"; ./sbin/snappy-server.sh start -locators=localhost:10334 -dir=");
try {
//create directory for a new server 2
string createServerDir;
createServerDir.append("cd ").append(snappyHomeDir).append(
"; mkdir ./work/localhost-server-2");
system(createServerDir.c_str());
//start a server 2
string startNewServer;
startNewServer.append(serverStartScript).append(
"./work/localhost-server-2");
system(startNewServer.c_str());

std::map<std::string, std::string> properties;
properties.insert(
std::pair<std::string, std::string>("load-balance", "true"));

conn.open("localhost", 1527, "app", "app", properties);
std::cout << "before stopping server connected to :"
<< conn.getCurrentHostAddress() << std::endl;

// creating dummy data
conn.execute("drop table if exists FailOverTest.test");
conn.execute("drop schema if exists FailOverTest");
conn.execute("create schema FailOverTest");
conn.execute(
"create table FailOverTest.test(id int) as select id from range(120000)");
auto count = conn.executeQuery("select count(*) from FailOverTest.test");
if (count > 0) {
std::cout << "Query execute successfully before server stop"
<< std::endl;
}

// stop the connected server 1
int connectedPort = conn.getCurrentHostAddress().port;
string stopRunningServer;
if (connectedPort == 1529) {
stopRunningServer.append(serverStopScript).append(
"./work/localhost-server-2");
} else {
stopRunningServer.append(serverStopScript).append(
"./work/localhost-server-1");
}

for (int i = 0; i < 5; ++i) {
if (i == 3) {
std::thread t1(stopServer, stopRunningServer);
t1.join();
}
count = conn.executeQuery("select count(*) from FailOverTest.test");
if (count > 0 && i > 3) {
std::cout << "Query execute successfully after server stop"
<< std::endl;

} else if (count > 0 && i > 3) {
std::cout << "Query execute successfully before server stop"
<< std::endl;
}

}
std::cout << "Test executed successfully connected to :"
<< conn.getCurrentHostAddress() << std::endl;

conn.close();
//start the server 1 again
serverStartScript.append("./work/localhost-server-1");
system(serverStartScript.c_str());
std::this_thread::sleep_for(std::chrono::seconds(50));
//stop server 2
serverStopScript.append("./work/localhost-server-2");
system(serverStopScript.c_str());
//remove directory for a new server 2
string removeServerDir;
removeServerDir.append("cd ").append(snappyHomeDir).append(
"; rm -r ./work/localhost-server-2");
system(removeServerDir.c_str());
} catch (SQLException& sqle) {
if (conn.isOpen()) conn.close();
//start the server 1 again
serverStartScript.append("./work/localhost-server-1");
system(serverStartScript.c_str());
std::this_thread::sleep_for(std::chrono::seconds(50));
//stop server 2
serverStopScript.append("./work/localhost-server-2");
system(serverStopScript.c_str());

//create directory for a new server 2
string removeServerDir;
removeServerDir.append("cd ").append(snappyHomeDir).append(
"; rm -r ./work/localhost-server-2");
system(removeServerDir.c_str());
std::cout << "ExecuteQuery failed, throws exception" << std::endl;
sqle.printStackTrace(std::cout);
}
}

33 changes: 33 additions & 0 deletions native/tests/failoverTest_AddServer_BeforeConn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

SNAPPY_HOME_DIR="$1"
_testDir="$2"
_snappyNativeDir="$(dirname "$_testDir")"

distDir=${_snappyNativeDir}/dist
THRIFT_VERSION=1.0.0-2
BOOST_VERSION=1.65.1

thrftLibPath=${distDir}/thrift-${THRIFT_VERSION}/lin64/lib
boostLibPath=${distDir}/boost-${BOOST_VERSION}/lin64/lib
snappClientLibPath=${_snappyNativeDir}/build-artifacts/lin/libs/snappyclient/static/release

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${thrftLibPath}:${boostLibPath}:${snappClientLibPath}

export LD_LIBRARY_PATH

headerLoc=${_snappyNativeDir}/src/snappyclient/headers
boostHeadeLoc=${_snappyNativeDir}/dist/boost-${BOOST_VERSION}/include
thriftHeaderLoc=${distDir}/thrift-${THRIFT_VERSION}/include

g++ -std=c++11 -I${headerLoc} -I${boostHeadeLoc} -I${thriftHeaderLoc} -O0 -g3 -Wall -c ${_testDir}/failoverTest_AddServer_BeforeConn.cpp -o ${_testDir}/failoverTest_AddServer_BeforeConn.o

chmod 777 ${_testDir}/failoverTest_AddServer_BeforeConn.o

g++ -L${boostLibPath} -L${thrftLibPath} -L${snappClientLibPath} -o ${_testDir}/failoverTest_AddServer_BeforeConn ${_testDir}/failoverTest_AddServer_BeforeConn.o -lsnappyclient -lcrypto -lodbc -lpthread -lssl -lboost_chrono -lboost_date_time -lboost_filesystem -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lthrift -lpthread -lrt -lgmp

chmod 777 ${_testDir}/failoverTest_AddServer_BeforeConn
cd ${_testDir}
./failoverTest_AddServer_BeforeConn $SNAPPY_HOME_DIR

rm failoverTest_AddServer_BeforeConn failoverTest_AddServer_BeforeConn.o
58 changes: 0 additions & 58 deletions native/tests/failoverTest_NewServer.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions native/tests/failoverTest_NewServer.sh

This file was deleted.

Loading