diff --git a/cppcache/integration/framework/Cluster.cpp b/cppcache/integration/framework/Cluster.cpp index b175bb2ef4..882386d7c4 100644 --- a/cppcache/integration/framework/Cluster.cpp +++ b/cppcache/integration/framework/Cluster.cpp @@ -17,43 +17,38 @@ #include "Cluster.h" +#include #include #include Locator::Locator(Cluster &cluster, std::vector &locators, - std::string name, uint16_t jmxManagerPort, bool useIPv6) + std::string name, uint16_t jmxManagerPort) : cluster_(cluster), name_(std::move(name)), locators_(locators), jmxManagerPort_(jmxManagerPort) { - auto hostname = "localhost"; - if (useIPv6) { - hostname = "ip6-localhost"; - } - - auto port = Framework::getAvailablePort(); - - locatorAddress_ = LocatorAddress{hostname, port}; + locatorAddress_ = LocatorAddress{"localhost", Framework::getAvailablePort()}; } Locator::Locator(Cluster &cluster, std::vector &locators, - std::string name, uint16_t jmxManagerPort, bool useIPv6, - uint16_t port, std::vector &remotePorts, - uint16_t distributedSystemId) + std::string name, uint16_t jmxManagerPort, + LocatorAddress locatorAddress, + std::vector remoteLocators, + int16_t distributedSystemId) : cluster_(cluster), name_(std::move(name)), locators_(locators), jmxManagerPort_(jmxManagerPort), + locatorAddress_(locatorAddress), + remoteLocators_(remoteLocators), distributedSystemId_(distributedSystemId) { - auto hostname = "localhost"; - if (useIPv6) { - hostname = "ip6-localhost"; + if (locatorAddress_.address.empty()) { + locatorAddress.address = "localhost"; } - locatorAddress_ = LocatorAddress{hostname, port}; - for (uint16_t remotePort : remotePorts) { - remoteLocatorsPorts_.push_back(remotePort); + if (0 == locatorAddress_.port) { + locatorAddress_.port = Framework::getAvailablePort(); } } @@ -70,13 +65,11 @@ Locator::Locator(Locator &&move) : cluster_(move.cluster_), name_(move.name_), locators_(move.locators_), - locatorAddress_(move.locatorAddress_), - remoteLocatorsPorts_(move.remoteLocatorsPorts_), jmxManagerPort_(move.jmxManagerPort_), - started_(move.started_), - distributedSystemId_(move.distributedSystemId_) { - move.started_ = false; -} + locatorAddress_(move.locatorAddress_), + remoteLocators_(move.remoteLocators_), + started_(false), + distributedSystemId_(move.distributedSystemId_) {} const LocatorAddress &Locator::getAddress() const { return locatorAddress_; } @@ -90,6 +83,16 @@ void Locator::start() { cluster_.getGfsh().stop().locator().withDir(name_).execute(); } + std::vector remoteLocators; + std::transform(remoteLocators_.begin(), remoteLocators_.end(), + std::back_inserter(remoteLocators), + [](const LocatorAddress &locatorAddress) { + return locatorAddress.address.empty() + ? "localhost" + : locatorAddress.address + "[" + + std::to_string(locatorAddress.port) + "]"; + }); + auto locator = cluster_.getGfsh() .start() .locator() @@ -98,7 +101,7 @@ void Locator::start() { .withName(safeName) .withBindAddress(locatorAddress_.address) .withPort(locatorAddress_.port) - .withRemoteLocators(remoteLocatorsPorts_) + .withRemoteLocators(remoteLocators) .withDistributedSystemId(distributedSystemId_) .withMaxHeap("256m") .withJmxManagerPort(jmxManagerPort_) @@ -151,18 +154,16 @@ void Locator::stop() { const ServerAddress &Server::getAddress() const { return serverAddress_; } Server::Server(Cluster &cluster, std::vector &locators, - std::string name, std::string xmlFile, bool useIPv6, - uint16_t port) + std::string name, std::string xmlFile, + ServerAddress serverAddress) : cluster_(cluster), locators_(locators), + serverAddress_(std::move(serverAddress)), name_(std::move(name)), xmlFile_(xmlFile) { - auto hostname = "localhost"; - if (useIPv6) { - hostname = "ip6-localhost"; + if (serverAddress_.address.empty()) { + serverAddress_.address = "localhost"; } - - serverAddress_ = ServerAddress{hostname, port}; } std::string Server::getCacheXMLFile() { return xmlFile_; } @@ -232,28 +233,24 @@ void Server::stop() { started_ = false; } -Cluster::Cluster(LocatorCount initialLocators, ServerCount initialServers, - std::vector locatorPorts, - std::vector remoteLocatorPorts, - uint16_t distributedSystemId) +Cluster::Cluster(InitialLocators initialLocators, InitialServers initialServers, + RemoteLocators remoteLocators, + DistributedSystemId distributedSystemId) : Cluster( Name(std::string(::testing::UnitTest::GetInstance() ->current_test_info() ->test_suite_name()) + - "/DS" + std::to_string(distributedSystemId) + "/" + + "/DS" + std::to_string(distributedSystemId.get()) + "/" + ::testing::UnitTest::GetInstance()->current_test_info()->name()), Classpath(""), SecurityManager(""), User(""), Password(""), - initialLocators, initialServers, CacheXMLFiles({}), - std::move(locatorPorts), std::move(remoteLocatorPorts), + initialLocators, initialServers, CacheXMLFiles(), remoteLocators, distributedSystemId) {} Cluster::Cluster(Name name, Classpath classpath, SecurityManager securityManager, User user, Password password, - LocatorCount initialLocators, ServerCount initialServers, - CacheXMLFiles cacheXMLFiles, - std::vector locatorPorts, - std::vector remoteLocatorPorts, - uint16_t distributedSystemId) + InitialLocators initialLocators, InitialServers initialServers, + CacheXMLFiles cacheXMLFiles, RemoteLocators remoteLocators, + DistributedSystemId distributedSystemId) : name_(name.get()), classpath_(classpath.get()), securityManager_(securityManager.get()), @@ -261,27 +258,31 @@ Cluster::Cluster(Name name, Classpath classpath, password_(password.get()), cacheXMLFiles_(cacheXMLFiles.get()), initialLocators_(initialLocators.get()), - locatorsPorts_(std::move(locatorPorts)), - remoteLocatorsPorts_(std::move(remoteLocatorPorts)), + remoteLocators_(remoteLocators.get()), initialServers_(initialServers.get()), jmxManagerPort_(Framework::getAvailablePort()), - useIPv6_(false), - distributedSystemId_(distributedSystemId) { + distributedSystemId_(distributedSystemId.get()) { removeServerDirectory(); } -Cluster::Cluster(LocatorCount initialLocators, ServerCount initialServers, - UseIpv6 useIPv6) - : Cluster( - Name(std::string(::testing::UnitTest::GetInstance() - ->current_test_info() - ->test_suite_name()) + - "/" + - ::testing::UnitTest::GetInstance()->current_test_info()->name()), - initialLocators, initialServers, useIPv6) {} +Cluster::Cluster(InitialLocators initialLocators, InitialServers initialServers, + UseIpv6 useIpv6) + : name_(std::string(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_suite_name()) + + "/" + + ::testing::UnitTest::GetInstance()->current_test_info()->name()), + initialLocators_(initialLocators.get()), + initialServers_(initialServers.get()), + jmxManagerPort_(Framework::getAvailablePort()), + useIPv6_(useIpv6.get()) { + removeServerDirectory(); +} Cluster::Cluster(LocatorCount initialLocators, ServerCount initialServers) - : Cluster(initialLocators, initialServers, UseIpv6(false)) {} + : Cluster( + InitialLocators{std::vector(initialLocators.get())}, + InitialServers{std::vector(initialServers.get())}) {} Cluster::Cluster(LocatorCount initialLocators, ServerCount initialServers, CacheXMLFiles cacheXMLFiles) @@ -311,38 +312,15 @@ Cluster::Cluster(LocatorCount initialLocators, ServerCount initialServers, conserveSockets_ = conserveSockets.get(); } -Cluster::Cluster(LocatorCount initialLocators, ServerCount initialServers, - std::vector &serverPorts) - : name_(std::string(::testing::UnitTest::GetInstance() - ->current_test_info() - ->test_suite_name()) + - "/" + - ::testing::UnitTest::GetInstance()->current_test_info()->name()), - initialLocators_(initialLocators.get()), - initialServers_(initialServers.get()), - jmxManagerPort_(Framework::getAvailablePort()) { - for (uint16_t port : serverPorts) { - serverPorts_.push_back(port); - } - removeServerDirectory(); -} - -Cluster::Cluster(Name name, LocatorCount initialLocators, - ServerCount initialServers, UseIpv6 useIPv6) - : Cluster(Name(name.get()), Classpath(""), SecurityManager(""), User(""), - Password(""), initialLocators, initialServers, CacheXMLFiles({}), - useIPv6) {} - Cluster::Cluster(Name name, LocatorCount initialLocators, ServerCount initialServers) : Cluster(Name(name.get()), Classpath(""), SecurityManager(""), User(""), - Password(""), initialLocators, initialServers, CacheXMLFiles({}), - UseIpv6(false)) {} + Password(""), initialLocators, initialServers, CacheXMLFiles()) {} Cluster::Cluster(Name name, Classpath classpath, SecurityManager securityManager, User user, Password password, LocatorCount initialLocators, ServerCount initialServers, - CacheXMLFiles cacheXMLFiles, UseIpv6 useIPv6) + CacheXMLFiles cacheXMLFiles) : name_(name.get()), classpath_(classpath.get()), securityManager_(securityManager.get()), @@ -352,7 +330,6 @@ Cluster::Cluster(Name name, Classpath classpath, initialServers_(initialServers.get()) { jmxManagerPort_ = Framework::getAvailablePort(); cacheXMLFiles_ = cacheXMLFiles.get(); - useIPv6_ = useIPv6.get(); removeServerDirectory(); } @@ -453,38 +430,24 @@ bool Cluster::getConserveSockets() { return conserveSockets_; } void Cluster::start() { start(std::function()); } void Cluster::start(std::function extraGfshCommands) { - locators_.reserve(initialLocators_); - for (size_t i = 0; i < initialLocators_; i++) { - uint16_t port; - if (locatorsPorts_.empty()) { - port = Framework::getAvailablePort(); - } else { - port = locatorsPorts_.at(i); - } - + locators_.reserve(initialLocators_.size()); + for (size_t i = 0; i < initialLocators_.size(); i++) { locators_.push_back({*this, locators_, name_ + "/locator/" + std::to_string(i), - jmxManagerPort_, getUseIPv6(), port, - remoteLocatorsPorts_, distributedSystemId_}); + jmxManagerPort_, initialLocators_[i], remoteLocators_, + distributedSystemId_}); } - servers_.reserve(initialServers_); + servers_.reserve(initialServers_.size()); std::string xmlFile; - for (size_t i = 0; i < initialServers_; i++) { + for (size_t i = 0; i < initialServers_.size(); i++) { xmlFile = (cacheXMLFiles_.size() == 0) ? "" : cacheXMLFiles_.size() == 1 ? cacheXMLFiles_[0] : cacheXMLFiles_[i]; - uint16_t serverPort; - if (serverPorts_.empty()) { - serverPort = static_cast(0); - } else { - serverPort = serverPorts_.at(i); - } - servers_.push_back({*this, locators_, name_ + "/server/" + std::to_string(i), xmlFile, - getUseIPv6(), serverPort}); + initialServers_[i]}); } startLocators(); diff --git a/cppcache/integration/framework/Cluster.h b/cppcache/integration/framework/Cluster.h index 2a0c114a5b..5085ff5ea6 100644 --- a/cppcache/integration/framework/Cluster.h +++ b/cppcache/integration/framework/Cluster.h @@ -41,11 +41,12 @@ struct LocatorAddress { class Locator { public: Locator(Cluster &cluster, std::vector &locators, std::string name, - uint16_t jmxManagerPort, bool useIPv6); + uint16_t jmxManagerPort); Locator(Cluster &cluster, std::vector &locators, std::string name, - uint16_t jmxManagerPort, bool useIPv6, uint16_t port, - std::vector &remotePorts, uint16_t distributedSystemId); + uint16_t jmxManagerPort, LocatorAddress locatorAddress, + std::vector remoteLocators, + int16_t distributedSystemId); ~Locator(); @@ -66,15 +67,15 @@ class Locator { std::vector &locators_; + uint16_t jmxManagerPort_; + LocatorAddress locatorAddress_; - std::vector remoteLocatorsPorts_; - - uint16_t jmxManagerPort_; + std::vector remoteLocators_; bool started_ = false; - uint16_t distributedSystemId_ = 0; + int16_t distributedSystemId_ = 0; }; struct ServerAddress { @@ -85,7 +86,7 @@ struct ServerAddress { class Server { public: Server(Cluster &cluster, std::vector &locators, std::string name, - std::string xmlFile, bool useIPv6, uint16_t port); + std::string xmlFile, ServerAddress serverAddress); std::string getCacheXMLFile(); @@ -123,29 +124,32 @@ using Password = NamedType; using CacheXMLFiles = NamedType, struct CacheXMLFilesParameter>; using UseIpv6 = NamedType; -using ConserveSockets = NamedType; +using ConserveSockets = NamedType; +using InitialLocators = + NamedType, struct InitialLocatorsParameter>; +using RemoteLocators = + NamedType, struct RemoteLocatorsParameter>; +using DistributedSystemId = + NamedType; +using InitialServers = + NamedType, struct InitialServerParameter>; class Cluster { public: enum class SubscriptionState { Enabled, Disabled }; - Cluster(LocatorCount initialLocators, ServerCount initialServers, - UseIpv6 useIPv6); - - Cluster(LocatorCount initialLocators, ServerCount initialServers, - std::vector &serverPorts); + Cluster(InitialLocators initialLocators, InitialServers initialServers, + UseIpv6 useIpv6 = UseIpv6{false}); - Cluster(LocatorCount initialLocators, ServerCount initialServers, - std::vector locatorPorts, - std::vector remoteLocatorPorts, - uint16_t distributedSystemId); + Cluster(InitialLocators initialLocators, InitialServers initialServers, + RemoteLocators remoteLocators, + DistributedSystemId distributedSystemId); Cluster(Name name, Classpath classpath, SecurityManager securityManager, - User user, Password password, LocatorCount initialLocators, - ServerCount initialServers, CacheXMLFiles cacheXMLFiles, - std::vector locatorPorts, - std::vector remoteLocatorPorts, - uint16_t distributedSystemId); + User user, Password password, InitialLocators initialLocators, + InitialServers initialServers, CacheXMLFiles cacheXMLFiles, + RemoteLocators remoteLocators, + DistributedSystemId distributedSystemId); Cluster(LocatorCount initialLocators, ServerCount initialServers); @@ -155,15 +159,11 @@ class Cluster { Cluster(LocatorCount initialLocators, ServerCount initialServers, ConserveSockets conserveSockets, CacheXMLFiles cacheXMLFiles); - Cluster(Name name, LocatorCount initialLocators, ServerCount initialServers, - UseIpv6 useIPv6); - Cluster(Name name, LocatorCount initialLocators, ServerCount initialServers); Cluster(Name name, Classpath classpath, SecurityManager securityManager, User user, Password password, LocatorCount initialLocators, - ServerCount initialServers, CacheXMLFiles cacheXMLFiles, - UseIpv6 useIPv6); + ServerCount initialServers, CacheXMLFiles cacheXMLFiles); Cluster(Name name, Classpath classpath, SecurityManager securityManager, User user, Password password, LocatorCount initialLocators, @@ -248,13 +248,11 @@ class Cluster { std::string password_; std::vector cacheXMLFiles_; - size_t initialLocators_; + std::vector initialLocators_; std::vector locators_; - std::vector locatorsPorts_; - std::vector remoteLocatorsPorts_; + std::vector remoteLocators_; - size_t initialServers_; - std::vector serverPorts_; + std::vector initialServers_; std::vector servers_; bool started_ = false; @@ -278,7 +276,7 @@ class Cluster { bool useIPv6_ = false; bool conserveSockets_ = false; - uint16_t distributedSystemId_ = 0; + int16_t distributedSystemId_ = 0; GfshExecute gfsh_; diff --git a/cppcache/integration/framework/Framework.cpp b/cppcache/integration/framework/Framework.cpp index 4454ffcc1c..6c6bfcee34 100644 --- a/cppcache/integration/framework/Framework.cpp +++ b/cppcache/integration/framework/Framework.cpp @@ -32,3 +32,10 @@ uint16_t Framework::getAvailablePort() { return port; } + +const std::string& Framework::getHostname() { + static const auto hostname = initHostname(); + return hostname; +} + +std::string Framework::initHostname() { return boost::asio::ip::host_name(); } diff --git a/cppcache/integration/framework/Framework.h b/cppcache/integration/framework/Framework.h index aaaca36414..f7dd5e9fa5 100644 --- a/cppcache/integration/framework/Framework.h +++ b/cppcache/integration/framework/Framework.h @@ -21,10 +21,16 @@ #define INTEGRATION_TEST_FRAMEWORK_FRAMEWORK_H #include +#include class Framework { public: static uint16_t getAvailablePort(); + + static const std::string& getHostname(); + + private: + static std::string initHostname(); }; template diff --git a/cppcache/integration/framework/Gfsh.cpp b/cppcache/integration/framework/Gfsh.cpp index 431b067962..52bd449abd 100644 --- a/cppcache/integration/framework/Gfsh.cpp +++ b/cppcache/integration/framework/Gfsh.cpp @@ -17,6 +17,8 @@ #include "Gfsh.h" +#include + Gfsh::Start Gfsh::start() { return Start{*this}; } Gfsh::Stop Gfsh::stop() { return Stop{*this}; } @@ -65,20 +67,15 @@ Gfsh::Start::Locator &Gfsh::Start::Locator::withPort(const uint16_t &port) { } Gfsh::Start::Locator &Gfsh::Start::Locator::withRemoteLocators( - const std::vector &locatorPorts) { + const std::vector &remoteLocators) { // Example: --J='-Dgemfire.remote-locators=localhost[9009],localhost[9010]' - if (!locatorPorts.empty()) { - command_ += " --J='-Dgemfire.remote-locators="; - bool firstLocator = true; - for (uint16_t locatorPort : locatorPorts) { - if (firstLocator) { - command_ += "localhost[" + std::to_string(locatorPort) + "]"; - firstLocator = false; - } else { - command_ += ",localhost[" + std::to_string(locatorPort) + "]"; - } - } - command_ += "'"; + if (!remoteLocators.empty()) { + std::ostringstream command; + command << " --J='-Dgemfire.remote-locators="; + std::copy(remoteLocators.begin(), remoteLocators.end(), + std::ostream_iterator(command, ",")); + command << "'"; + command_ += command.str(); } return *this; } diff --git a/cppcache/integration/framework/Gfsh.h b/cppcache/integration/framework/Gfsh.h index 4b8ed3b2d2..3fa4df95b8 100644 --- a/cppcache/integration/framework/Gfsh.h +++ b/cppcache/integration/framework/Gfsh.h @@ -105,7 +105,8 @@ class Gfsh { Locator &withPort(const uint16_t &port); - Locator &withRemoteLocators(const std::vector &locatorPorts); + Locator &withRemoteLocators( + const std::vector &remoteLocators); Locator &withDistributedSystemId(const uint16_t &dsId); diff --git a/cppcache/integration/framework/NamedType.h b/cppcache/integration/framework/NamedType.h index 797aab7f1a..726ff4e9d7 100644 --- a/cppcache/integration/framework/NamedType.h +++ b/cppcache/integration/framework/NamedType.h @@ -26,6 +26,7 @@ template class NamedType { public: + NamedType() = default; explicit NamedType(T const &value) : value_(value) {} explicit NamedType(T &&value) : value_(std::move(value)) {} T &get() { return value_; } diff --git a/cppcache/integration/test/BasicIPv6Test.cpp b/cppcache/integration/test/BasicIPv6Test.cpp index 51e31d94d8..8a0cde3ac8 100644 --- a/cppcache/integration/test/BasicIPv6Test.cpp +++ b/cppcache/integration/test/BasicIPv6Test.cpp @@ -53,8 +53,9 @@ std::shared_ptr setupRegion(Cache& cache) { * Example test using 2 servers and waiting for async tasks to synchronize using * furtures. */ -TEST(BasicIPv6Test, DISABLED_queryResultForRange) { - Cluster cluster{LocatorCount{1}, ServerCount{1}, UseIpv6(true)}; +TEST(BasicIPv6Test, queryResultForRange) { + Cluster cluster{InitialLocators{{{"localhost", 0}}}, + InitialServers{{{"localhost", 0}}}, UseIpv6(true)}; cluster.start(); cluster.getGfsh() .create() diff --git a/cppcache/integration/test/DisconnectEndPointAtException.cpp b/cppcache/integration/test/DisconnectEndPointAtException.cpp index ce344820e7..4718b7ac1b 100644 --- a/cppcache/integration/test/DisconnectEndPointAtException.cpp +++ b/cppcache/integration/test/DisconnectEndPointAtException.cpp @@ -111,11 +111,11 @@ void executeTestCase(bool useSingleHopAndPR) { int MAX_ENTRY_KEY = 1000000; auto keyRangeSize = (MAX_ENTRY_KEY / NUM_THREADS); - std::vector serverPorts; - serverPorts.push_back(Framework::getAvailablePort()); - serverPorts.push_back(Framework::getAvailablePort()); + // std::vector serverPorts; + // serverPorts.push_back(Framework::getAvailablePort()); + // serverPorts.push_back(Framework::getAvailablePort()); - Cluster cluster{LocatorCount{1}, ServerCount{2}, serverPorts}; + Cluster cluster{LocatorCount{1}, ServerCount{2}}; cluster.start(); auto region_cmd = cluster.getGfsh().create().region().withName("region").withType( diff --git a/cppcache/integration/test/WanDeserializationTest.cpp b/cppcache/integration/test/WanDeserializationTest.cpp index 0b0755283e..13825f000c 100644 --- a/cppcache/integration/test/WanDeserializationTest.cpp +++ b/cppcache/integration/test/WanDeserializationTest.cpp @@ -97,15 +97,20 @@ std::shared_ptr setupRegion( } TEST(WanDeserializationTest, testEventsAreDeserializedCorrectly) { - const auto portSiteA = Framework::getAvailablePort(); - const auto portSiteB = Framework::getAvailablePort(); - - Cluster clusterA{ - LocatorCount{1}, ServerCount{1}, {portSiteA}, {portSiteB}, 1}; + const auto& hostname = Framework::getHostname(); + const auto locatorAddressA = + LocatorAddress{hostname, Framework::getAvailablePort()}; + const auto locatorAddressB = + LocatorAddress{hostname, Framework::getAvailablePort()}; + + Cluster clusterA{InitialLocators{{locatorAddressA}}, + InitialServers{{{hostname, 0}}}, + RemoteLocators{{locatorAddressB}}, DistributedSystemId(1)}; clusterA.start(); - Cluster clusterB{ - LocatorCount{1}, ServerCount{1}, {portSiteB}, {portSiteA}, 2}; + Cluster clusterB{InitialLocators{{locatorAddressB}}, + InitialServers{{{hostname, 0}}}, + RemoteLocators{{locatorAddressB}}, DistributedSystemId(2)}; clusterB.start(); // Create gw receivers