Skip to content

Commit

Permalink
GEODE-9553: remove all remaining printf variations from C++ code (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Bender authored Oct 22, 2021
1 parent aa99cb4 commit 91ee46a
Show file tree
Hide file tree
Showing 72 changed files with 970 additions and 1,037 deletions.
17 changes: 10 additions & 7 deletions cppcache/integration-test/BuiltinCacheableWrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <cstdlib>
#include <wchar.h>
#include <random>
#include <sstream>
#include <iomanip>

#include <ace/Date_Time.h>

Expand Down Expand Up @@ -616,15 +618,15 @@ class CacheableHugeUnicodeStringWrapper : public CacheableWrapper {
int32_t maxKeys() const override { return INT_MAX; }

void initKey(int32_t keyIndex, int32_t maxSize) override {
std::wostringstream strm;

if (maxSize <= 0xFFFF) // ensure its larger than 64k
{
maxSize += (0xFFFF + 1);
}
std::wstring baseStr(maxSize - 10, L'\x0905');
wchar_t indexStr[15];
swprintf(indexStr, 14, L"%10d", keyIndex);
baseStr.append(indexStr);
m_cacheableObject = CacheableString::create(baseStr);
strm << baseStr << std::setw(10) << std::setfill(L'0') << keyIndex;
m_cacheableObject = CacheableString::create(strm.str());
}

void initRandomValue(int32_t maxSize) override {
Expand Down Expand Up @@ -661,15 +663,16 @@ class CacheableUnicodeStringWrapper : public CacheableWrapper {
int32_t maxKeys() const override { return INT_MAX; }

void initKey(int32_t keyIndex, int32_t maxSize) override {
std::wostringstream strm;

maxSize %= 21800; // so that encoded length is within 64k
if (maxSize < 11) {
maxSize = 11;
}
std::wstring baseStr(maxSize - 10, L'\x0905');
wchar_t indexStr[15];
swprintf(indexStr, 14, L"%10d", keyIndex);
baseStr.append(indexStr);
m_cacheableObject = CacheableString::create(baseStr);
strm << baseStr << std::setw(10) << std::setfill(L'0') << keyIndex;
m_cacheableObject = CacheableString::create(strm.str());
}

void initRandomValue(int32_t maxSize) override {
Expand Down
63 changes: 33 additions & 30 deletions cppcache/integration-test/CacheHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <fstream>
#include <iostream>
#include <list>

#include <ace/INET_Addr.h>
Expand Down Expand Up @@ -224,8 +225,9 @@ CacheHelper::CacheHelper(const bool, const char *poolName,

poolFactory.setPRSingleHopEnabled(prSingleHop);
poolFactory.setThreadLocalConnections(threadLocal);
printf(" Setting pr-single-hop to prSingleHop = %d ", prSingleHop);
printf("Setting threadLocal to %d ", threadLocal);
std::cout << " Setting pr-single-hop to prSingleHop = " << prSingleHop
<< "\n";
std::cout << "Setting threadLocal to " << threadLocal << "\n";
if (!locators.empty()) {
addServerLocatorEPs(locators, poolFactory);
if (serverGroup) {
Expand All @@ -239,7 +241,7 @@ CacheHelper::CacheHelper(const bool, const char *poolName,
poolFactory.setLoadConditioningInterval(
std::chrono::milliseconds(loadConditioningInterval));
}
printf("Setting connections to %d ", connections);
std::cout << "Setting connections to " << connections << "\n";
if (connections >= 0) {
poolFactory.setMinConnections(connections);
poolFactory.setMaxConnections(connections);
Expand Down Expand Up @@ -405,7 +407,6 @@ std::shared_ptr<Pool> CacheHelper::createPool(
const std::string &serverGroup, int redundancy, bool clientNotification,
std::chrono::milliseconds subscriptionAckInterval, int connections,
int loadConditioningInterval, bool isMultiuserMode) {
// printf(" in createPool isMultiuserMode = %d \n", isMultiuserMode);
auto poolFac = getCache()->getPoolManager().createFactory();

addServerLocatorEPs(locators, poolFac);
Expand Down Expand Up @@ -502,7 +503,8 @@ void CacheHelper::createPoolWithLocators(
std::chrono::milliseconds subscriptionAckInterval, int connections,
bool isMultiuserMode, const std::string &serverGroup) {
LOG("createPool() entered.");
printf(" in createPoolWithLocators isMultiuserMode = %d\n", isMultiuserMode);
std::cout << " in createPoolWithLocators isMultiuserMode = "
<< isMultiuserMode << "\n";
auto poolPtr = createPool(name, locators, serverGroup, subscriptionRedundancy,
clientNotificationEnabled, subscriptionAckInterval,
connections, -1, isMultiuserMode);
Expand Down Expand Up @@ -841,26 +843,27 @@ std::shared_ptr<CacheableString> CacheHelper::createCacheable(

void CacheHelper::showKeys(
std::vector<std::shared_ptr<CacheableKey>> &vecKeys) {
fprintf(stdout, "vecKeys.size() = %zd\n", vecKeys.size());
std::cout << "vecKeys.size() = " << vecKeys.size() << "\n";
for (size_t i = 0; i < vecKeys.size(); i++) {
fprintf(stdout, "key[%zd] - %s\n", i, vecKeys.at(i)->toString().c_str());
std::cout << "key[" << i << "] -" << vecKeys.at(i)->toString() << "\n";
}
fflush(stdout);
std::cout << std::flush;
}

void CacheHelper::showRegionAttributes(RegionAttributes attributes) {
printf("caching=%s\n", attributes.getCachingEnabled() ? "true" : "false");
printf("Entry Time To Live = %s\n",
to_string(attributes.getEntryTimeToLive()).c_str());
printf("Entry Idle Timeout = %s\n",
to_string(attributes.getEntryIdleTimeout()).c_str());
printf("Region Time To Live = %s\n",
to_string(attributes.getRegionTimeToLive()).c_str());
printf("Region Idle Timeout = %s\n",
to_string(attributes.getRegionIdleTimeout()).c_str());
printf("Initial Capacity = %d\n", attributes.getInitialCapacity());
printf("Load Factor = %f\n", attributes.getLoadFactor());
printf("End Points = %s\n", attributes.getEndpoints().c_str());
std::cout << "caching=" << (attributes.getCachingEnabled() ? "true" : "false")
<< "\n";
std::cout << "Entry Time To Live = "
<< to_string(attributes.getEntryTimeToLive()) << "\n";
std::cout << "Entry Idle Timeout = "
<< to_string(attributes.getEntryIdleTimeout()) << "\n";
std::cout << "Region Time To Live = "
<< to_string(attributes.getRegionTimeToLive()) << "\n";
std::cout << "Region Idle Timeout = "
<< to_string(attributes.getRegionIdleTimeout()) << "\n";
std::cout << "Initial Capacity = " << attributes.getInitialCapacity() << "\n";
std::cout << "Load Factor = " << attributes.getLoadFactor() << "\n";
std::cout << "End Points = " << attributes.getEndpoints() << "\n";
}

std::shared_ptr<QueryService> CacheHelper::getQueryService() {
Expand Down Expand Up @@ -928,7 +931,7 @@ const std::string CacheHelper::getTcrEndpoints(bool &isLocalServer,
}

isLocalServer = gflocalserver;
printf("getHostPort :: %s \n", gfendpoints.c_str());
std::cout << "getHostPort :: " << gfendpoints << "\n";

return gfendpoints;
}
Expand Down Expand Up @@ -992,7 +995,7 @@ std::string CacheHelper::getLocatorHostPort(bool &isLocator,

isLocator = gflocator;
isLocalServer = gflocalserver;
printf("getLocatorHostPort :: %s \n", gflchostport.c_str());
std::cout << "getLocatorHostPort :: " << gflchostport << "\n";

return gflchostport;
}
Expand All @@ -1016,9 +1019,9 @@ void CacheHelper::initServer(int instance, const std::string &xml,
if (!isServerCleanupCallbackRegistered &&
gClientCleanup.registerCallback(&CacheHelper::cleanupServerInstances)) {
isServerCleanupCallbackRegistered = true;
printf("TimeBomb registered server cleanupcallback \n");
std::cout << "TimeBomb registered server cleanupcallback \n";
}
printf("Inside initServer added\n");
std::cout << "Inside initServer added\n";

static const auto gfjavaenv = Utils::getEnv("GFJAVA");
static auto gfLogLevel = Utils::getEnv("GFE_LOGLEVEL");
Expand Down Expand Up @@ -1087,10 +1090,10 @@ void CacheHelper::initServer(int instance, const std::string &xml,
}

std::string xmlFile_new;
printf(" xml file name = %s \n", xmlFile.c_str());
std::cout << " xml file name = " << xmlFile << "\n";
xmlFile = CacheHelper::createDuplicateXMLFile(xmlFile);

printf(" creating dir = %s \n", sname.c_str());
std::cout << " creating dir = " << sname << "\n";
boost::filesystem::create_directory(sname);

int64_t defaultTombstone_timeout = 600000;
Expand Down Expand Up @@ -1141,7 +1144,7 @@ void CacheHelper::initServer(int instance, const std::string &xml,
server.execute();

staticServerInstanceList.push_back(instance);
printf("added server instance %d\n", instance);
std::cout << "added server instance " << instance << "\n";
}

std::string CacheHelper::createDuplicateXMLFile(const std::string &source,
Expand All @@ -1165,8 +1168,8 @@ std::string CacheHelper::createDuplicateXMLFile(const std::string &source,
dest);

CacheHelper::staticConfigFileList.push_back(dest);
printf("createDuplicateXMLFile added file %s %zd", dest.c_str(),
CacheHelper::staticConfigFileList.size());
std::cout << "createDuplicateXMLFile added file " << dest.c_str() << " "
<< CacheHelper::staticConfigFileList.size() << "\n";

return dest;
}
Expand Down Expand Up @@ -1497,7 +1500,7 @@ bool CacheHelper::setSeed() {
"Environment variable TESTNAME for test name is not set.");

int seed = std::hash<std::string>{}(testnameenv);
printf("seed for process %d\n", seed);
std::cout << "seed for process " << seed << "\n";
// The integration tests rely on the pseudo-random
// number generator being seeded with a very particular
// value specific to the test by way of the test name.
Expand Down
2 changes: 1 addition & 1 deletion cppcache/integration-test/InitSmartHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class InitSmartHeap {
InitSmartHeap() {}

} doInit;
}
} // namespace geode_smartheap
30 changes: 11 additions & 19 deletions cppcache/integration-test/QueryHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class QueryHelper {
for (int i = (sizeof(constantExpectedRowsRS) / sizeof(int)) - 1; i > -1;
i--) {
if (constantExpectedRowsRS[i] == queryindex) {
printf("index %d is having constant rows \n",
constantExpectedRowsRS[i]);
std::cout << "index " << constantExpectedRowsRS[i] << " is having constant rows \n";
return true;
}
}
Expand All @@ -133,8 +132,7 @@ class QueryHelper {
for (int i = (sizeof(constantExpectedRowsPQRS) / sizeof(int)) - 1; i > -1;
i--) {
if (constantExpectedRowsPQRS[i] == queryindex) {
printf("index %d is having constant rows \n",
constantExpectedRowsPQRS[i]);
std::cout << "index " << constantExpectedRowsPQRS[i] << " is having constant rows \n";
return true;
}
}
Expand All @@ -146,8 +144,7 @@ class QueryHelper {
for (int i = (sizeof(constantExpectedRowsSS) / sizeof(int)) - 1; i > -1;
i--) {
if (constantExpectedRowsSS[i] == queryindex) {
printf("index %d is having constant rows \n",
constantExpectedRowsSS[i]);
std::cout << "index " << constantExpectedRowsSS[i] << " is having constant rows \n";
return true;
}
}
Expand All @@ -159,8 +156,7 @@ class QueryHelper {
for (int i = (sizeof(constantExpectedRowsSSPQ) / sizeof(int)) - 1; i > -1;
i--) {
if (constantExpectedRowsSSPQ[i] == queryindex) {
printf("index %d is having constant rows \n",
constantExpectedRowsSSPQ[i]);
std::cout << "index " << constantExpectedRowsSSPQ[i] << " is having constant rows \n";
return true;
}
}
Expand Down Expand Up @@ -192,15 +188,11 @@ void QueryHelper::populatePortfolioData(
std::string key =
"port" + std::to_string(set) + '-' + std::to_string(current);
auto keyport = CacheableKey::create(key);
// printf(" QueryHelper::populatePortfolioData creating key = %s and
// puting data \n",portname);
rptr->put(keyport, port);
}
}
// portfolioSetSize = setSize; portfolioNumSets = numSets; objectSize =
// objSize;

printf("all puts done \n");
std::cout << "all puts done \n";
}

const char* secIds[] = {"SUN", "IBM", "YHOO", "GOOG", "MSFT",
Expand Down Expand Up @@ -244,10 +236,8 @@ void QueryHelper::populatePortfolioPdxData(std::shared_ptr<Region>& rptr,
current);
}
}
// portfolioSetSize = setSize; portfolioNumSets = numSets; objectSize =
// objSize;

printf("all puts done \n");
std::cout << "all puts done \n";
}

void QueryHelper::populatePositionPdxData(std::shared_ptr<Region>& rptr,
Expand Down Expand Up @@ -337,8 +327,10 @@ bool QueryHelper::verifyRS(std::shared_ptr<SelectResults>& resultSet,
foundRows++;
}

printf("found rows %zd, expected %zd \n", foundRows, expectedRows);
if (foundRows == expectedRows) return true;
std::cout << "found rows " << foundRows << ", expected " << expectedRows << "\n";
if (foundRows == expectedRows) {
return true;
}
}
return false;
}
Expand All @@ -353,7 +345,7 @@ bool QueryHelper::verifySS(std::shared_ptr<SelectResults>& structSet,
auto siptr = std::dynamic_pointer_cast<Struct>(ser);

if (siptr == nullptr) {
printf("siptr is nullptr \n\n");
std::cout << "siptr is nullptr \n\n";
return false;
}

Expand Down
Loading

0 comments on commit 91ee46a

Please sign in to comment.