Skip to content

Commit

Permalink
Fix cerr as well
Browse files Browse the repository at this point in the history
- PR Review feedback
- Initially skipped cerr but after some reading, cerr will flush after every << thus endl can also be avoided.
  • Loading branch information
CJCombrink committed Apr 11, 2024
1 parent ca8ebf5 commit c5800a2
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 55 deletions.
4 changes: 2 additions & 2 deletions contrib/fb303/TClientInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void TClientInfoServerHandler::getStatsStrings(vector<string>& result) {
char addrBuf[INET6_ADDRSTRLEN];
const char* addrStr = info->getAddr(addrBuf, sizeof addrBuf);
if (addrStr == nullptr) {
// cerr << "no addr!" << endl;
// cerr << "no addr!" << '\n';
continue;
}

Expand All @@ -160,7 +160,7 @@ void TClientInfoServerHandler::getStatsStrings(vector<string>& result) {
char buf[256];
snprintf(buf, sizeof buf, "%d %s %s %.3f %llu", i, addrStr, callStr, secs,
(uint64_t)info->getNCalls());

result.push_back(buf);
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/cpp/src/thrift/async/TEvhttpClientChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ void TEvhttpClientChannel::finish(struct evhttp_request* req) {
self->finish(req);
} catch (std::exception& e) {
// don't propagate a C++ exception in C code (e.g. libevent)
std::cerr << "TEvhttpClientChannel::response exception thrown (ignored): " << e.what()
<< std::endl;
std::cerr << "TEvhttpClientChannel::response exception thrown (ignored): " << e.what() << '\n';
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/cpp/src/thrift/async/TEvhttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,21 @@ void TEvhttpServer::complete(RequestContext* ctx, bool success) {
int rv = evhttp_add_header(ctx->req->output_headers, "Content-Type", "application/x-thrift");
if (rv != 0) {
// TODO: Log an error.
std::cerr << "evhttp_add_header failed " << __FILE__ << ":" << __LINE__ << std::endl;
std::cerr << "evhttp_add_header failed " << __FILE__ << ":" << __LINE__ << '\n';
}

struct evbuffer* buf = evbuffer_new();
if (buf == nullptr) {
// TODO: Log an error.
std::cerr << "evbuffer_new failed " << __FILE__ << ":" << __LINE__ << std::endl;
std::cerr << "evbuffer_new failed " << __FILE__ << ":" << __LINE__ << '\n';
} else {
uint8_t* obuf;
uint32_t sz;
ctx->obuf->getBuffer(&obuf, &sz);
int ret = evbuffer_add(buf, obuf, sz);
if (ret != 0) {
// TODO: Log an error.
std::cerr << "evhttp_add failed with " << ret << " " << __FILE__ << ":" << __LINE__
<< std::endl;
std::cerr << "evhttp_add failed with " << ret << " " << __FILE__ << ":" << __LINE__ << '\n';
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/cpp/src/thrift/transport/TFileTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace transport {

using std::shared_ptr;
using std::cerr;
using std::endl;
using std::string;
using namespace apache::thrift::protocol;
using namespace apache::thrift::concurrency;
Expand Down Expand Up @@ -1031,7 +1030,7 @@ void TFileProcessor::process(uint32_t numEvents, bool tail) {
break;
}
} catch (TException& te) {
cerr << te.what() << endl;
cerr << te.what() << '\n';
break;
}
}
Expand Down Expand Up @@ -1059,7 +1058,7 @@ void TFileProcessor::processChunk() {
} catch (TEOFException&) {
break;
} catch (TException& te) {
cerr << te.what() << endl;
cerr << te.what() << '\n';
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/cpp/test/OneWayHTTPTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ class OneWayServiceHandler : public onewaytest::OneWayServiceIf {

void roundTripRPC() override {
#ifdef ENABLE_STDERR_LOGGING
cerr << "roundTripRPC()" << endl;
cerr << "roundTripRPC()" << '\n';
#endif
}
void oneWayRPC() override {
#ifdef ENABLE_STDERR_LOGGING
cerr << "oneWayRPC()" << std::endl ;
cerr << "oneWayRPC()" << '\n';
#endif
}
};
Expand Down Expand Up @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE( JSON_BufferedHTTP )

int port = ss->getPort() ;
#ifdef ENABLE_STDERR_LOGGING
cerr << "port " << port << endl ;
cerr << "port " << port << '\n';
#endif

{
Expand Down
26 changes: 13 additions & 13 deletions lib/cpp/test/concurrency/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ int main(int argc, char** argv) {
std::cout << "\t\tThreadFactory reap N threads test: N = " << reapLoops << "x" << reapCount << '\n';

if (!threadFactoryTests.reapNThreads(reapLoops, reapCount)) {
std::cerr << "\t\ttThreadFactory reap N threads FAILED" << std::endl;
std::cerr << "\t\ttThreadFactory reap N threads FAILED" << '\n';
return 1;
}

std::cout << "\t\tThreadFactory flood N threads test: N = " << floodLoops << "x" << floodCount << '\n';

if (!threadFactoryTests.floodNTest(floodLoops, floodCount)) {
std::cerr << "\t\ttThreadFactory flood N threads FAILED" << std::endl;
std::cerr << "\t\ttThreadFactory flood N threads FAILED" << '\n';
return 1;
}

std::cout << "\t\tThreadFactory synchronous start test" << '\n';

if (!threadFactoryTests.synchStartTest()) {
std::cerr << "\t\ttThreadFactory synchronous start FAILED" << std::endl;
std::cerr << "\t\ttThreadFactory synchronous start FAILED" << '\n';
return 1;
}

std::cout << "\t\tThreadFactory monitor timeout test" << '\n';

if (!threadFactoryTests.monitorTimeoutTest()) {
std::cerr << "\t\ttThreadFactory monitor timeout FAILED" << std::endl;
std::cerr << "\t\ttThreadFactory monitor timeout FAILED" << '\n';
return 1;
}
}
Expand Down Expand Up @@ -119,35 +119,35 @@ int main(int argc, char** argv) {
TimerManagerTests timerManagerTests;

if (!timerManagerTests.test00()) {
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
std::cerr << "\t\tTimerManager tests FAILED" << '\n';
return 1;
}

std::cout << "\t\tTimerManager test01" << '\n';

if (!timerManagerTests.test01()) {
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
std::cerr << "\t\tTimerManager tests FAILED" << '\n';
return 1;
}

std::cout << "\t\tTimerManager test02" << '\n';

if (!timerManagerTests.test02()) {
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
std::cerr << "\t\tTimerManager tests FAILED" << '\n';
return 1;
}

std::cout << "\t\tTimerManager test03" << '\n';

if (!timerManagerTests.test03()) {
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
std::cerr << "\t\tTimerManager tests FAILED" << '\n';
return 1;
}

std::cout << "\t\tTimerManager test04" << '\n';

if (!timerManagerTests.test04()) {
std::cerr << "\t\tTimerManager tests FAILED" << std::endl;
std::cerr << "\t\tTimerManager tests FAILED" << '\n';
return 1;
}
}
Expand All @@ -166,23 +166,23 @@ int main(int argc, char** argv) {
std::cout << "\t\tThreadManager api test:" << '\n';

if (!threadManagerTests.apiTest()) {
std::cerr << "\t\tThreadManager apiTest FAILED" << std::endl;
std::cerr << "\t\tThreadManager apiTest FAILED" << '\n';
return 1;
}

std::cout << "\t\tThreadManager load test: worker count: " << workerCount
<< " task count: " << taskCount << " delay: " << delay << '\n';

if (!threadManagerTests.loadTest(taskCount, delay, workerCount)) {
std::cerr << "\t\tThreadManager loadTest FAILED" << std::endl;
std::cerr << "\t\tThreadManager loadTest FAILED" << '\n';
return 1;
}

std::cout << "\t\tThreadManager block test: worker count: " << workerCount
<< " delay: " << delay << '\n';

if (!threadManagerTests.blockTest(delay, workerCount)) {
std::cerr << "\t\tThreadManager blockTest FAILED" << std::endl;
std::cerr << "\t\tThreadManager blockTest FAILED" << '\n';
return 1;
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ int main(int argc, char** argv) {

if (!threadManagerTests.loadTest(taskCount, delay, workerCount))
{
std::cerr << "\t\tThreadManager loadTest FAILED" << std::endl;
std::cerr << "\t\tThreadManager loadTest FAILED" << '\n';
return 1;
}
}
Expand Down
22 changes: 11 additions & 11 deletions lib/cpp/test/concurrency/ThreadManagerTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class ThreadManagerTests {
sleep_(100);
int64_t b = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
if (b - a < 50 || b - a > 150) {
std::cerr << "\t\t\texpected 100ms gap, found " << (b-a) << "ms gap instead." << std::endl;
std::cerr << "\t\t\texpected 100ms gap, found " << (b-a) << "ms gap instead." << '\n';
return false;
}

Expand All @@ -408,7 +408,7 @@ class ThreadManagerTests {
threadManager->start();
threadManager->setExpireCallback(expiredNotifier); // std::bind(&ThreadManagerTests::expiredNotifier, this));

#define EXPECT(FUNC, COUNT) { size_t c = FUNC; if (c != COUNT) { std::cerr << "expected " #FUNC" to be " #COUNT ", but was " << c << std::endl; return false; } }
#define EXPECT(FUNC, COUNT) { size_t c = FUNC; if (c != COUNT) { std::cerr << "expected " #FUNC" to be " #COUNT ", but was " << c << '\n'; return false; } }

EXPECT(threadManager->workerCount(), 1);
EXPECT(threadManager->idleWorkerCount(), 1);
Expand Down Expand Up @@ -477,7 +477,7 @@ class ThreadManagerTests {

shared_ptr<Runnable> nextTask = threadManager->removeNextPending();
if (nextTask != otherTask) {
std::cerr << "\t\t\t\t\texpected removeNextPending to return otherTask" << std::endl;
std::cerr << "\t\t\t\t\texpected removeNextPending to return otherTask" << '\n';
return false;
}

Expand All @@ -489,7 +489,7 @@ class ThreadManagerTests {

nextTask = threadManager->removeNextPending();
if (nextTask) {
std::cerr << "\t\t\t\t\texpected removeNextPending to return an empty Runnable" << std::endl;
std::cerr << "\t\t\t\t\texpected removeNextPending to return an empty Runnable" << '\n';
return false;
}

Expand All @@ -512,25 +512,25 @@ class ThreadManagerTests {
std::cout << "\t\t\t\tremove expired tasks.." << '\n';

if (!m_expired.empty()) {
std::cerr << "\t\t\t\t\texpected m_expired to be empty" << std::endl;
std::cerr << "\t\t\t\t\texpected m_expired to be empty" << '\n';
return false;
}

threadManager->removeExpiredTasks();

if (m_expired.size() != 2) {
std::cerr << "\t\t\t\t\texpected m_expired to be set" << std::endl;
std::cerr << "\t\t\t\t\texpected m_expired to be set" << '\n';
return false;
}

if (m_expired.front() != expiredTask) {
std::cerr << "\t\t\t\t\texpected m_expired[0] to be the expired task" << std::endl;
std::cerr << "\t\t\t\t\texpected m_expired[0] to be the expired task" << '\n';
return false;
}
m_expired.pop_front();

if (m_expired.front() != expiredTask) {
std::cerr << "\t\t\t\t\texpected m_expired[1] to be the expired task" << std::endl;
std::cerr << "\t\t\t\t\texpected m_expired[1] to be the expired task" << '\n';
return false;
}

Expand All @@ -554,12 +554,12 @@ class ThreadManagerTests {
sleep_(100); // make sure it has time to spin up and expire the task

if (m_expired.empty()) {
std::cerr << "\t\t\t\t\texpected m_expired to be set" << std::endl;
std::cerr << "\t\t\t\t\texpected m_expired to be set" << '\n';
return false;
}

if (m_expired.front() != expiredTask) {
std::cerr << "\t\t\t\t\texpected m_expired to be the expired task" << std::endl;
std::cerr << "\t\t\t\t\texpected m_expired to be the expired task" << '\n';
return false;
}

Expand All @@ -573,7 +573,7 @@ class ThreadManagerTests {
std::cout << "\t\t\t\ttry to remove too many workers" << '\n';
try {
threadManager->removeWorker(2);
std::cerr << "\t\t\t\t\texpected InvalidArgumentException" << std::endl;
std::cerr << "\t\t\t\t\texpected InvalidArgumentException" << '\n';
return false;
} catch (const InvalidArgumentException&) {
/* expected */
Expand Down
8 changes: 4 additions & 4 deletions lib/cpp/test/concurrency/TimerManagerTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TimerManagerTests {
_success(false),
_done(false) {}

~Task() override { std::cerr << this << std::endl; }
~Task() override { std::cerr << this << '\n'; }

void run() override {

Expand Down Expand Up @@ -84,7 +84,7 @@ class TimerManagerTests {
timerManager.threadFactory(shared_ptr<ThreadFactory>(new ThreadFactory()));
timerManager.start();
if (timerManager.state() != TimerManager::STARTED) {
std::cerr << "timerManager is not in the STARTED state, but should be" << std::endl;
std::cerr << "timerManager is not in the STARTED state, but should be" << '\n';
return false;
}

Expand All @@ -104,15 +104,15 @@ class TimerManagerTests {
}

if (!task->_done) {
std::cerr << "task is not done, but it should have executed" << std::endl;
std::cerr << "task is not done, but it should have executed" << '\n';
return false;
}

std::cout << "\t\t\t" << (task->_success ? "Success" : "Failure") << "!" << '\n';
}

if (orphanTask->_done) {
std::cerr << "orphan task is done, but it should not have executed" << std::endl;
std::cerr << "orphan task is done, but it should not have executed" << '\n';
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions test/cpp/src/StressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class ClientThread : public Runnable {
loopEchoString();
break;
default:
cerr << "Unexpected loop type" << _loopType << endl;
cerr << "Unexpected loop type" << _loopType << '\n';
break;
}

Expand Down Expand Up @@ -386,7 +386,7 @@ int main(int argc, char** argv) {
}

} catch (std::exception& e) {
cerr << e.what() << endl;
cerr << e.what() << '\n';
cerr << usage.str();
}

Expand Down Expand Up @@ -468,7 +468,7 @@ int main(int argc, char** argv) {
server->setServerEventHandler(observer);
std::shared_ptr<Thread> serverThread = threadFactory->newThread(server);

cerr << "Starting the server on port " << port << endl;
cerr << "Starting the server on port " << port << '\n';

serverThread->start();
observer->waitForService();
Expand Down Expand Up @@ -538,7 +538,7 @@ int main(int argc, char** argv) {
Synchronized s(monitor);
threadCount = clientCount;

cerr << "Launch " << clientCount << " " << clientType << " client threads" << endl;
cerr << "Launch " << clientCount << " " << clientType << " client threads" << '\n';

time00 = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();

Expand Down Expand Up @@ -598,7 +598,7 @@ int main(int argc, char** argv) {
for (iter = count.begin(); iter != count.end(); ++iter) {
printf("%s => %d\n", iter->first, iter->second);
}
cerr << "done." << endl;
cerr << "done." << '\n';
}

return 0;
Expand Down
Loading

0 comments on commit c5800a2

Please sign in to comment.