in cppcache/integration-test/testXmlCacheCreationWithPools.cpp [227:429]
int testXmlCacheCreationWithPools() {
auto cacheFactory = CacheFactory();
std::shared_ptr<Cache> cptr;
std::cout << "create DistributedSytem with name=XML_CACHE_CREATION_TEST"
<< std::endl;
std::cout
<< "Create cache with the configurations provided in valid_cache_pool.xml"
<< std::endl;
try {
auto duplicateFile =
CacheHelper::createDuplicateXMLFile("valid_cache_pool.xml");
cptr = std::make_shared<Cache>(
cacheFactory.set("cache-xml-file", duplicateFile).create());
if (!cptr->getPdxIgnoreUnreadFields()) {
std::cout << "getPdxIgnoreUnreadFields should return true." << std::endl;
return -1;
} else {
std::cout << "getPdxIgnoreUnreadFields returned true." << std::endl;
}
} catch (Exception &ex) {
std::cout << "Exception: msg = " << ex.what() << std::endl;
LOG(ex.getStackTrace());
return -1;
} catch (...) {
LOGINFO("unknown exception");
return -1;
}
std::cout << "Test if number of root regions are correct" << std::endl;
auto vrp = cptr->rootRegions();
std::cout << " vrp.size=" << vrp.size() << std::endl;
if (vrp.size() != 2) {
std::cout << "Number of root regions does not match" << std::endl;
return -1;
}
std::cout << "Root regions in Cache :" << std::endl;
for (size_t i = 0; i < vrp.size(); i++) {
std::cout << "vc[" << i << "].m_regionPtr=" << vrp.at(i).get() << std::endl;
std::cout << "vc[" << i << "]=" << vrp.at(i)->getName() << std::endl;
}
auto regPtr1 = cptr->getRegion("Root1");
auto &&vr = regPtr1->subregions(true);
std::cout << "Test if the number of sub regions with the root region Root1 "
"are correct"
<< std::endl;
std::cout << " vr.size=" << vr.size() << std::endl;
if (vr.size() != 1) {
std::cout << "Number of Subregions does not match" << std::endl;
return -1;
}
std::cout << "get subregions from the root region :" << vrp.at(0)->getName()
<< std::endl;
for (size_t i = 0; i < vr.size(); i++) {
std::cout << "vc[" << i << "].m_regionPtr=" << vr.at(i).get() << std::endl;
std::cout << "vc[" << i << "]=" << vr.at(i)->getName() << std::endl;
}
// TODO - global Issue is that we cannot have config with server and locator
// pools. Check if this assumption is valid and if so then break up this test.
auto subRegPtr = vr.at(0);
auto regPtr2 = cptr->getRegion("Root2");
std::cout << "Test if the number of sub regions with the root region Root2 "
"are correct"
<< std::endl;
vr = regPtr2->subregions(true);
std::cout << " vr.size=" << vr.size() << std::endl;
if (vr.size() != 0) {
std::cout << "Number of Subregions does not match" << std::endl;
return -1;
}
vr.clear();
vrp.clear();
std::cout << "Test the attributes of region" << std::endl;
const auto &poolNameReg1 = regPtr1->getAttributes().getPoolName();
const auto &poolNameSubReg = subRegPtr->getAttributes().getPoolName();
const auto &poolNameReg2 = regPtr2->getAttributes().getPoolName();
if (poolNameReg1 != "test_pool_1") {
std::cout << "Wrong pool name for region 1" << std::endl;
return -1;
}
if (poolNameReg2 != "test_pool_2") {
std::cout << "Wrong pool name for region 2" << std::endl;
return -1;
}
if (poolNameSubReg != "test_pool_2") {
std::cout << "Wrong pool name for sub region" << std::endl;
return -1;
}
auto poolOfReg1 = cptr->getPoolManager().find(poolNameReg1);
auto poolOfSubReg = cptr->getPoolManager().find(poolNameSubReg);
auto poolOfReg2 = cptr->getPoolManager().find(poolNameReg2);
SLIST locators;
SLIST servers;
SLIST emptylist;
locators.clear();
servers.clear();
emptylist.clear();
locators.push_back(std::string("localhost:") +
std::to_string(CacheHelper::staticLocatorHostPort1));
servers.push_back(std::string("localhost:") +
std::to_string(CacheHelper::staticHostPort1));
servers.push_back(std::string("localhost:") +
std::to_string(CacheHelper::staticHostPort2));
// THIS MUST MATCH WITH THE CLIENT CACHE XML LOADED
bool check1 = checkPoolAttribs(
poolOfReg1, locators, emptylist, 12345, 23456, 3, 7, 3,
std::chrono::milliseconds(5555), 12345, "test_pool_1", 23456,
"ServerGroup1", 32768, true, 900123, 567, 0, 10123, true, 250001);
bool check2 = checkPoolAttribs(
poolOfReg2, emptylist, servers, 23456, 34567, 2, 8, 5,
std::chrono::milliseconds(6666), 23456, "test_pool_2", 34567,
"ServerGroup2", 65536, false, 800222, 678, 1, 20345, false, 5000);
bool check3 = checkPoolAttribs(
poolOfSubReg, emptylist, servers, 23456, 34567, 2, 8, 5,
std::chrono::milliseconds(6666), 23456, "test_pool_2", 34567,
"ServerGroup2", 65536, false, 800222, 678, 1, 20345, false, 5000);
if (!cptr->isClosed()) {
cptr->close();
// Do not set it to null because the destructor will be invoked here and
// the regions and pools previously obtained, that will be deleted when the
// function returns, will make use of the their reference to the deleted
// cache and thus make the process crash.
// cptr = nullptr;
}
if (!check1 || !check2 || !check3) {
std::cout << "Property check failed" << std::endl;
return -1;
}
////////////////////////////testing of cache.xml completed///////////////////
try {
std::cout << "Testing invalid pool xml 1" << std::endl;
auto duplicateFile =
CacheHelper::createDuplicateXMLFile("invalid_cache_pool.xml");
Cache cache = cacheFactory.set("cache-xml-file", duplicateFile).create();
return -1;
} catch (Exception &ex) {
std::cout << "EXPECTED EXCEPTION" << std::endl;
std::cout << "Exception: msg = " << ex.what() << std::endl;
LOG(ex.getStackTrace());
}
try {
std::cout << "Testing invalid pool xml 2" << std::endl;
auto duplicateFile =
CacheHelper::createDuplicateXMLFile("invalid_cache_pool2.xml");
Cache cache = cacheFactory.set("cache-xml-file", duplicateFile).create();
return -1;
} catch (Exception &ex) {
std::cout << "EXPECTED EXCEPTION" << std::endl;
std::cout << "Exception: msg = " << ex.what() << std::endl;
LOG(ex.getStackTrace());
}
try {
std::cout << "Testing invalid pool xml 3" << std::endl;
auto duplicateFile =
CacheHelper::createDuplicateXMLFile("invalid_cache_pool3.xml");
Cache cache = cacheFactory.set("cache-xml-file", duplicateFile).create();
return -1;
} catch (Exception &ex) {
std::cout << "EXPECTED EXCEPTION" << std::endl;
std::cout << "Exception: msg = " << ex.what() << std::endl;
LOG(ex.getStackTrace());
}
try {
std::cout << "Testing invalid pool xml 4" << std::endl;
auto duplicateFile =
CacheHelper::createDuplicateXMLFile("invalid_cache_pool4.xml");
Cache cache = cacheFactory.set("cache-xml-file", duplicateFile).create();
return -1;
} catch (Exception &ex) {
std::cout << "EXPECTED EXCEPTION" << std::endl;
std::cout << "Exception: msg = " << ex.what() << std::endl;
LOG(ex.getStackTrace());
}
std::cout << "done with test" << std::endl;
std::cout << "Test successful!" << std::endl;
return 0;
}