Skip to content

Commit

Permalink
Set db hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoe committed May 4, 2018
1 parent a48bd8d commit b7da0de
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
37 changes: 19 additions & 18 deletions MongoDB/testsuite/src/MongoDBTest.cpp
Expand Up @@ -10,6 +10,7 @@

#include "Poco/DateTime.h"
#include "Poco/ObjectPool.h"
#include "Poco/Environment.h"
#include "Poco/MongoDB/InsertRequest.h"
#include "Poco/MongoDB/QueryRequest.h"
#include "Poco/MongoDB/DeleteRequest.h"
Expand All @@ -33,6 +34,21 @@ using namespace Poco::MongoDB;

Poco::MongoDB::Connection::Ptr MongoDBTest::_mongo;

namespace
{
std::string getHost()
{
#if POCO_OS == POCO_OS_ANDROID
return "10.0.2.2";
#else
if(Poco::Environment::has("MONGODB_HOST"))
return Poco::Environment::get("MONGODB_HOST");
else
return "127.0.0.1";
#endif
}
}


MongoDBTest::MongoDBTest(const std::string& name):
CppUnit::TestCase("MongoDB")
Expand Down Expand Up @@ -300,12 +316,7 @@ void MongoDBTest::testBuildInfo()

void MongoDBTest::testConnectionPool()
{
#if POCO_OS == POCO_OS_ANDROID
std::string host = "10.0.2.2";
#else
std::string host = "127.0.0.1";
#endif

std::string host = getHost();
Poco::Net::SocketAddress sa(host, 27017);
Poco::PoolableObjectFactory<Poco::MongoDB::Connection, Poco::MongoDB::Connection::Ptr> factory(sa);
Poco::ObjectPool<Poco::MongoDB::Connection, Poco::MongoDB::Connection::Ptr> pool(factory, 10, 15);
Expand Down Expand Up @@ -414,13 +425,7 @@ void MongoDBTest::testConnectURI()
{
Poco::MongoDB::Connection conn;
Poco::MongoDB::Connection::SocketFactory sf;

#if POCO_OS == POCO_OS_ANDROID
std::string host = "10.0.2.2";
#else
std::string host = "127.0.0.1";
#endif

std::string host = getHost();
conn.connect("mongodb://" + host, sf);
conn.disconnect();

Expand Down Expand Up @@ -463,11 +468,7 @@ void MongoDBTest::testConnectURI()

CppUnit::Test* MongoDBTest::suite()
{
#if POCO_OS == POCO_OS_ANDROID
std::string host = "10.0.2.2";
#else
std::string host = "127.0.0.1";
#endif
std::string host = getHost();
try
{
_mongo = new Poco::MongoDB::Connection(host, 27017);
Expand Down
3 changes: 3 additions & 0 deletions Redis/testsuite/src/RedisTest.cpp
Expand Up @@ -11,6 +11,7 @@
#include "Poco/Exception.h"
#include "Poco/Delegate.h"
#include "Poco/Thread.h"
#include "Poco/Environment.h"
#include "RedisTest.h"
#include "Poco/Redis/AsyncReader.h"
#include "Poco/Redis/Command.h"
Expand All @@ -35,6 +36,8 @@ RedisTest::RedisTest(const std::string& name):
#if POCO_OS == POCO_OS_ANDROID
_host = "10.0.2.2";
#endif
if(Poco::Environment::has("REDIS_HOST"))
_host = Poco::Environment::get("REDIS_HOST");
if (!_connected)
{
try
Expand Down
5 changes: 4 additions & 1 deletion SQL/MySQL/testsuite/src/MySQLTest.cpp
Expand Up @@ -47,7 +47,10 @@ Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;

std::string MySQLTest::getHost()
{
return "127.0.0.1"; //do not change to "localhost"!
if (Environment::has("MYSQL_HOST"))
return Environment::get("MYSQL_HOST");
else
return "127.0.0.1"; //do not change to "localhost"!
}


Expand Down
5 changes: 4 additions & 1 deletion SQL/PostgreSQL/testsuite/src/PostgreSQLTest.cpp
Expand Up @@ -50,7 +50,10 @@ std::string PostgreSQLTest::_dbConnString;
// Parameters for barebone-test
//
std::string PostgreSQLTest::getHost() {
return "localhost";
if (Environment::has("POSTGRESQL_HOST"))
return Environment::get("POSTGRESQL_HOST");
else
return "localhost";
}
std::string PostgreSQLTest::getPort() {
return "5432";
Expand Down

0 comments on commit b7da0de

Please sign in to comment.