ElfTest() : elfFile_(binaryPath.c_str()) {
}
- virtual ~ElfTest() {
- }
+ ~ElfTest() override {}
protected:
ElfFile elfFile_;
class ElfCacheTest : public testing::Test {
protected:
- void SetUp();
+ void SetUp() override;
};
// Capture "golden" stack trace with default-configured Symbolizer
public:
/// But it doesn't *have* to be a singleton.
ThreadWheelTimekeeper();
- ~ThreadWheelTimekeeper();
+ ~ThreadWheelTimekeeper() override;
/// Implement the Timekeeper interface
/// This future *does* complete on the timer thread. You should almost
class TestData : public RequestData {
public:
explicit TestData(int data) : data_(data) {}
- virtual ~TestData() {}
+ ~TestData() override {}
int data_;
};
});
}
- ~ViaFixture() {
+ ~ViaFixture() override {
done = true;
eastExecutor->add([=]() { });
t.join();
worker = std::thread(std::bind(&ThreadExecutor::work, this));
}
- ~ThreadExecutor() {
+ ~ThreadExecutor() override {
done = true;
funcs.write([]{});
worker.join();
int64_t startTime_;
protected:
- virtual ~AsyncSSLSocketConnector() {
- }
+ ~AsyncSSLSocketConnector() override {}
public:
AsyncSSLSocketConnector(AsyncSSLSocket *sslSocket,
std::chrono::steady_clock::now().time_since_epoch()).count()) {
}
- virtual void connectSuccess() noexcept {
+ void connectSuccess() noexcept override {
VLOG(7) << "client socket connected";
int64_t timeoutLeft = 0;
sslSocket_->sslConn(this, timeoutLeft);
}
- virtual void connectErr(const AsyncSocketException& ex) noexcept {
+ void connectErr(const AsyncSocketException& ex) noexcept override {
LOG(ERROR) << "TCP connect failed: " << ex.what();
fail(ex);
delete this;
}
- virtual void handshakeSuc(AsyncSSLSocket *sock) noexcept {
+ void handshakeSuc(AsyncSSLSocket* sock) noexcept override {
VLOG(7) << "client handshake success";
if (callback_) {
callback_->connectSuccess();
delete this;
}
- virtual void handshakeErr(AsyncSSLSocket *socket,
- const AsyncSocketException& ex) noexcept {
+ void handshakeErr(AsyncSSLSocket* socket,
+ const AsyncSocketException& ex) noexcept override {
LOG(ERROR) << "client handshakeErr: " << ex.what();
fail(ex);
delete this;
BackoffTimeout(AsyncServerSocket* socket)
: AsyncTimeout(socket->getEventBase()), socket_(socket) {}
- virtual void timeoutExpired() noexcept {
- socket_->backoffTimeoutExpired();
- }
+ void timeoutExpired() noexcept override { socket_->backoffTimeoutExpired(); }
private:
AsyncServerSocket* socket_;
}
// private destructor, to ensure callers use destroy()
- virtual ~BytesWriteRequest() = default;
+ ~BytesWriteRequest() override = default;
const struct iovec* getOps() const {
assert(opCount_ > opIndex_);
explicit FunctionLoopCallback(const Cob& function)
: function_(function) {}
- virtual void runLoopCallback() noexcept {
+ void runLoopCallback() noexcept override {
function_();
delete this;
}
class EventBase::FunctionRunner
: public NotificationQueue<std::pair<void (*)(void*), void*>>::Consumer {
public:
- void messageAvailable(std::pair<void (*)(void*), void*>&& msg) {
+ void messageAvailable(std::pair<void (*)(void*), void*>&& msg) override {
// In libevent2, internal events do not break the loop.
// Most users would expect loop(), followed by runInEventBaseThread(),
bool immediateReadCalled = false;
explicit AsyncSocketImmediateRead(folly::EventBase* evb) : AsyncSocket(evb) {}
protected:
- virtual void checkForImmediateRead() noexcept override {
+ void checkForImmediateRead() noexcept override {
immediateReadCalled = true;
AsyncSocket::handleRead();
}
acceptStoppedFn_ = fn;
}
- void connectionAccepted(int fd, const folly::SocketAddress& clientAddr)
- noexcept {
+ void connectionAccepted(
+ int fd, const folly::SocketAddress& clientAddr) noexcept override {
events_.emplace_back(fd, clientAddr);
if (connectionAcceptedFn_) {
connectionAcceptedFn_(fd, clientAddr);
}
}
- void acceptError(const std::exception& ex) noexcept {
+ void acceptError(const std::exception& ex) noexcept override {
events_.emplace_back(ex.what());
if (acceptErrorFn_) {
acceptErrorFn_(ex);
}
}
- void acceptStarted() noexcept {
+ void acceptStarted() noexcept override {
events_.emplace_back(TYPE_START);
if (acceptStartedFn_) {
acceptStartedFn_();
}
}
- void acceptStopped() noexcept {
+ void acceptStopped() noexcept override {
events_.emplace_back(TYPE_STOP);
if (acceptStoppedFn_) {
UDPAcceptor(EventBase* evb, int n): evb_(evb), n_(n) {
}
- void onListenStarted() noexcept {
- }
+ void onListenStarted() noexcept override {}
- void onListenStopped() noexcept {
- }
+ void onListenStopped() noexcept override {}
void onDataAvailable(std::shared_ptr<folly::AsyncUDPSocket> socket,
const folly::SocketAddress& client,
std::unique_ptr<folly::IOBuf> data,
- bool truncated) noexcept {
+ bool truncated) noexcept override {
lastClient_ = client;
lastMsg_ = data->moveToFbString().toStdString();
folly::IOBuf::copyBuffer(folly::to<std::string>("PING ", n_)));
}
- void getReadBuffer(void** buf, size_t* len) noexcept {
+ void getReadBuffer(void** buf, size_t* len) noexcept override {
*buf = buf_;
*len = 1024;
}
void onDataAvailable(const folly::SocketAddress& client,
size_t len,
- bool truncated) noexcept {
+ bool truncated) noexcept override {
VLOG(4) << "Read " << len << " bytes (trun:" << truncated << ") from "
<< client.describe() << " - " << std::string(buf_, len);
VLOG(4) << n_ << " left";
sendPing();
}
- void onReadError(const folly::AsyncSocketException& ex) noexcept {
+ void onReadError(const folly::AsyncSocketException& ex) noexcept override {
VLOG(4) << ex.what();
// Start listening for next PONG
socket_->resumeRead(this);
}
- void onReadClosed() noexcept {
+ void onReadClosed() noexcept override {
CHECK(false) << "We unregister reads before closing";
}
- void timeoutExpired() noexcept {
+ void timeoutExpired() noexcept override {
VLOG(4) << "Timeout expired";
sendPing();
}
: eventBase_(eventBase)
, count_(count) {}
- virtual void runLoopCallback() noexcept {
+ void runLoopCallback() noexcept override {
--count_;
if (count_ > 0) {
eventBase_->runInLoop(this);
TestHandler(EventBase* eventBase, int fd)
: EventHandler(eventBase, fd), fd_(fd) {}
- virtual void handlerReady(uint16_t events) noexcept {
+ void handlerReady(uint16_t events) noexcept override {
ssize_t bytesRead = 0;
ssize_t bytesWritten = 0;
if (events & READ) {
PartialReadHandler(EventBase* eventBase, int fd, size_t readLength)
: TestHandler(eventBase, fd), fd_(fd), readLength_(readLength) {}
- virtual void handlerReady(uint16_t events) noexcept {
+ void handlerReady(uint16_t events) noexcept override {
assert(events == EventHandler::READ);
ssize_t bytesRead = readFromFD(fd_, readLength_);
log.emplace_back(events, bytesRead, 0);
PartialWriteHandler(EventBase* eventBase, int fd, size_t writeLength)
: TestHandler(eventBase, fd), fd_(fd), writeLength_(writeLength) {}
- virtual void handlerReady(uint16_t events) noexcept {
+ void handlerReady(uint16_t events) noexcept override {
assert(events == EventHandler::WRITE);
ssize_t bytesWritten = writeToFD(fd_, writeLength_);
log.emplace_back(events, 0, bytesWritten);
: AsyncTimeout(eb)
, handler_(h) {}
- virtual void timeoutExpired() noexcept {
- delete handler_;
- }
+ void timeoutExpired() noexcept override { delete handler_; }
private:
EventHandler* handler_;
: AsyncTimeout(eventBase)
, timestamp(false) {}
- virtual void timeoutExpired() noexcept {
- timestamp.reset();
- }
+ void timeoutExpired() noexcept override { timestamp.reset(); }
TimePoint timestamp;
};
reschedule();
}
- virtual void timeoutExpired() noexcept {
+ void timeoutExpired() noexcept override {
timestamps.emplace_back();
reschedule();
}
: AsyncTimeout(eb)
, timeout_(t) {}
- virtual void timeoutExpired() noexcept {
- delete timeout_;
- }
+ void timeoutExpired() noexcept override { delete timeout_; }
private:
AsyncTimeout* timeout_;
, count_(count)
, action_(action) {}
- virtual void runLoopCallback() noexcept {
+ void runLoopCallback() noexcept override {
--count_;
if (count_ > 0) {
eventBase_->runInLoop(this);
unregisterHandler();
}
- virtual void handlerReady(uint16_t events) noexcept {
+ void handlerReady(uint16_t events) noexcept override {
// We didn't register with PERSIST, so we will have been automatically
// unregistered already.
ASSERT_FALSE(isHandlerRegistered());
eventBase_->runInLoop(this);
}
- virtual void runLoopCallback() noexcept {
+ void runLoopCallback() noexcept override {
++loopInvocations_;
if (loopInvocations_ >= maxLoopInvocations_) {
return;
scheduleTimeout(1);
}
- virtual ~IdleTimeTimeoutSeries() {}
+ ~IdleTimeTimeoutSeries() override {}
- void timeoutExpired() noexcept {
+ void timeoutExpired() noexcept override {
++timeouts_;
if(timeout_.empty()){
PipeHandler(EventBase* eventBase, int fd)
: EventHandler(eventBase, fd) {}
- void handlerReady(uint16_t events) noexcept {
- abort();
- }
+ void handlerReady(uint16_t events) noexcept override { abort(); }
};
TEST(EventBaseTest, StopBeforeLoop) {
class CompressionTest
: public testing::TestWithParam<std::tr1::tuple<int, CodecType>> {
protected:
- void SetUp() {
+ void SetUp() override {
auto tup = GetParam();
uncompressedLength_ = uint64_t(1) << std::tr1::get<0>(tup);
codec_ = getCodec(std::tr1::get<1>(tup));
class CompressionVarintTest
: public testing::TestWithParam<std::tr1::tuple<int, CodecType>> {
protected:
- void SetUp() {
+ void SetUp() override {
auto tup = GetParam();
uncompressedLength_ = uint64_t(1) << std::tr1::get<0>(tup);
codec_ = getCodec(std::tr1::get<1>(tup));
class CompressionCorruptionTest : public testing::TestWithParam<CodecType> {
protected:
- void SetUp() {
- codec_ = getCodec(GetParam());
- }
+ void SetUp() override { codec_ = getCodec(GetParam()); }
void runSimpleTest(const DataHolder& dh);
class MoveToFbStringTest
: public ::testing::TestWithParam<std::tr1::tuple<int, int, bool, BufType>> {
protected:
- void SetUp() {
+ void SetUp() override {
elementSize_ = std::tr1::get<0>(GetParam());
elementCount_ = std::tr1::get<1>(GetParam());
shared_ = std::tr1::get<2>(GetParam());
explicit IntException(int i)
: i_(i) {}
- virtual int getInt() const override { return i_; }
- virtual const char* what() const noexcept override {
+ int getInt() const override { return i_; }
+ const char* what() const noexcept override {
what_ = folly::to<std::string>("int == ", i_);
return what_.c_str();
}
class IntPaddedConstTest : public IntPaddedTestBase {
protected:
- void SetUp() {
+ void SetUp() override {
v_.resize(4);
n_ = 0;
for (int i = 0; i < 4; i++) {
class StructPaddedConstTest : public StructPaddedTestBase {
protected:
- void SetUp() {
+ void SetUp() override {
v_.resize(4);
n_ = 0;
for (int i = 0; i < 4; i++) {
class Derived : public Base {
public:
- virtual int foo() const FOLLY_FINAL { return 2; }
+ int foo() const FOLLY_FINAL { return 2; }
};
// A compiler that supports final will likely inline the call to p->foo()
class Exception : public std::exception {
public:
explicit Exception(const std::string& value) : value_(value) {}
- virtual ~Exception(void) noexcept {}
+ ~Exception(void) noexcept override {}
- virtual const char *what(void) const noexcept {
- return value_.c_str();
- }
+ const char* what(void) const noexcept override { return value_.c_str(); }
private:
std::string value_;
socket_->sslAccept(this);
}
- virtual void timeoutExpired() noexcept override {
+ void timeoutExpired() noexcept override {
VLOG(4) << "SSL handshake timeout expired";
sslError_ = SSLErrorEnum::TIMEOUT;
dropConnection();
}
- virtual void describe(std::ostream& os) const override {
+ void describe(std::ostream& os) const override {
os << "pending handshake on " << clientAddr_;
}
- virtual bool isBusy() const override {
- return true;
- }
- virtual void notifyPendingShutdown() override {}
- virtual void closeWhenIdle() override {}
+ bool isBusy() const override { return true; }
+ void notifyPendingShutdown() override {}
+ void closeWhenIdle() override {}
- virtual void dropConnection() override {
+ void dropConnection() override {
VLOG(10) << "Dropping in progress handshake for " << clientAddr_;
socket_->closeNow();
}
- virtual void dumpConnectionState(uint8_t loglevel) override {
- }
+ void dumpConnectionState(uint8_t loglevel) override {}
private:
// AsyncSSLSocket::HandshakeCallback API
- virtual void handshakeSuc(AsyncSSLSocket* sock) noexcept override {
+ void handshakeSuc(AsyncSSLSocket* sock) noexcept override {
const unsigned char* nextProto = nullptr;
unsigned nextProtoLength = 0;
delete this;
}
- virtual void handshakeErr(AsyncSSLSocket* sock,
- const AsyncSocketException& ex) noexcept override {
+ void handshakeErr(AsyncSSLSocket* sock,
+ const AsyncSocketException& ex) noexcept override {
auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - acceptTime_);
VLOG(3) << "SSL handshake error after " << elapsedTime.count() <<
" ms; " << sock->getRawBytesReceived() << " bytes received & " <<
class TestClientPipelineFactory : public PipelineFactory<BytesPipeline> {
public:
std::unique_ptr<BytesPipeline, folly::DelayedDestruction::Destructor>
- newPipeline(std::shared_ptr<AsyncSocket> sock) {
+ newPipeline(std::shared_ptr<AsyncSocket> sock) override {
// We probably aren't connected immedately, check after a small delay
EventBaseManager::get()->getEventBase()->tryRunAfterDelay([sock](){
CHECK(sock->good());
class TestPipelineFactory : public PipelineFactory<BytesPipeline> {
public:
- std::unique_ptr<BytesPipeline, folly::DelayedDestruction::Destructor> newPipeline(
- std::shared_ptr<AsyncSocket> sock) {
+ std::unique_ptr<BytesPipeline, folly::DelayedDestruction::Destructor>
+ newPipeline(std::shared_ptr<AsyncSocket> sock) override {
pipelines++;
return std::unique_ptr<BytesPipeline, folly::DelayedDestruction::Destructor>(
TestAcceptor() : Acceptor(ServerSocketConfig()) {
Acceptor::init(nullptr, &base_);
}
- void onNewConnection(
- AsyncSocket::UniquePtr sock,
- const folly::SocketAddress* address,
- const std::string& nextProtocolName,
- const TransportInfo& tinfo) {
- }
+ void onNewConnection(AsyncSocket::UniquePtr sock,
+ const folly::SocketAddress* address,
+ const std::string& nextProtocolName,
+ const TransportInfo& tinfo) override {}
};
class TestAcceptorFactory : public AcceptorFactory {
public:
- std::shared_ptr<Acceptor> newAcceptor(EventBase* base) {
+ std::shared_ptr<Acceptor> newAcceptor(EventBase* base) override {
return std::make_shared<TestAcceptor>();
}
};
class TestHandlerPipeline : public InboundHandler<void*> {
public:
- void read(Context* ctx, void* conn) {
+ void read(Context* ctx, void* conn) override {
connections++;
return ctx->fireRead(conn);
}
public:
std::unique_ptr<ServerBootstrap<BytesPipeline>::AcceptPipeline,
folly::DelayedDestruction::Destructor>
- newPipeline(std::shared_ptr<AsyncSocket>) {
+ newPipeline(std::shared_ptr<AsyncSocket>) override {
std::unique_ptr<ServerBootstrap<BytesPipeline>::AcceptPipeline,
folly::DelayedDestruction::Destructor> pipeline(
class TestUDPPipeline : public InboundHandler<void*> {
public:
- void read(Context* ctx, void* conn) {
- connections++;
- }
+ void read(Context* ctx, void* conn) override { connections++; }
};
TEST(Bootstrap, UDP) {
EXPECT_EQ(0, unlink(path));
}
- ~FileRegionTest() {
+ ~FileRegionTest() override {
// Close up shop
close(fd);
acceptedSocket->close();
class ConcreteHandler : public Handler<Rin, Rout, Win, Wout> {
typedef typename Handler<Rin, Rout, Win, Wout>::Context Context;
public:
- void read(Context* ctx, Rin msg) {}
- Future<void> write(Context* ctx, Win msg) { return makeFuture(); }
+ void read(Context* ctx, Rin msg) override {}
+ Future<void> write(Context* ctx, Win msg) override { return makeFuture(); }
};
typedef HandlerAdapter<std::string, std::string> StringHandler;
explicit FrameTester(std::function<void(std::unique_ptr<IOBuf>)> test)
: test_(test) {}
- void read(Context* ctx, std::unique_ptr<IOBuf> buf) {
+ void read(Context* ctx, std::unique_ptr<IOBuf> buf) override {
test_(std::move(buf));
}
- void readException(Context* ctx, exception_wrapper w) {
+ void readException(Context* ctx, exception_wrapper w) override {
test_(nullptr);
}
private:
class BytesReflector
: public BytesToBytesHandler {
public:
-
- Future<void> write(Context* ctx, std::unique_ptr<IOBuf> buf) {
+ Future<void> write(Context* ctx, std::unique_ptr<IOBuf> buf) override {
IOBufQueue q_(IOBufQueue::cacheChainLength());
q_.append(std::move(buf));
ctx->fireRead(q_);
public:
explicit MemoryIdlerTimeout(EventBase* b) : AsyncTimeout(b), base_(b) {}
- virtual void timeoutExpired() noexcept {
- idled = true;
- }
+ void timeoutExpired() noexcept override { idled = true; }
- virtual void runLoopCallback() noexcept {
+ void runLoopCallback() noexcept override {
if (idled) {
MemoryIdler::flushLocalMallocCaches();
MemoryIdler::unmapUnusedStack(MemoryIdler::kDefaultStackToRetain);
class TestObserver : public ThreadPoolExecutor::Observer {
public:
- void threadStarted(ThreadPoolExecutor::ThreadHandle*) {
+ void threadStarted(ThreadPoolExecutor::ThreadHandle*) override { threads_++; }
+ void threadStopped(ThreadPoolExecutor::ThreadHandle*) override { threads_--; }
+ void threadPreviouslyStarted(ThreadPoolExecutor::ThreadHandle*) override {
threads_++;
}
- void threadStopped(ThreadPoolExecutor::ThreadHandle*) {
- threads_--;
- }
- void threadPreviouslyStarted(ThreadPoolExecutor::ThreadHandle*) {
- threads_++;
- }
- void threadNotYetStopped(ThreadPoolExecutor::ThreadHandle*) {
+ void threadNotYetStopped(ThreadPoolExecutor::ThreadHandle*) override {
threads_--;
}
void checkCalls() {
class SimpleDecode : public ByteToMessageCodec {
public:
- virtual std::unique_ptr<IOBuf> decode(
- Context* ctx, IOBufQueue& buf, size_t&) {
+ std::unique_ptr<IOBuf> decode(Context* ctx,
+ IOBufQueue& buf,
+ size_t&) override {
return buf.move();
}
};
class EchoService : public Service<std::string, std::string> {
public:
- virtual Future<std::string> operator()(std::string req) override {
- return req;
- }
+ Future<std::string> operator()(std::string req) override { return req; }
};
class EchoIntService : public Service<std::string, int> {
public:
- virtual Future<int> operator()(std::string req) override {
+ Future<int> operator()(std::string req) override {
return folly::to<int>(req);
}
};
std::shared_ptr<Service<std::string, std::string>> service) :
ServiceFilter<std::string, std::string>(service) {}
- virtual Future<std::string> operator()(std::string req) {
+ Future<std::string> operator()(std::string req) override {
return (*service_)(req + "\n");
}
};
std::shared_ptr<Service<std::string, std::string>> service) :
ServiceFilter<int, int, std::string, std::string>(service) {}
- virtual Future<int> operator()(int req) {
+ Future<int> operator()(int req) override {
return (*service_)(folly::to<std::string>(req)).then([](std::string resp) {
return folly::to<int>(resp);
});
std::shared_ptr<Service<std::string, int>> service) :
ServiceFilter<int, std::string, std::string, int>(service) {}
- virtual Future<std::string> operator()(int req) {
+ Future<std::string> operator()(int req) override {
return (*service_)(folly::to<std::string>(req)).then([](int resp) {
return folly::to<std::string>(resp);
});
std::shared_ptr<ServiceFactory<Pipeline, Req, Resp>> factory)
: ServiceFactoryFilter<Pipeline, Req, Resp>(factory) {}
- virtual Future<std::shared_ptr<Service<Req, Resp>>> operator()(
- std::shared_ptr<ClientBootstrap<Pipeline>> client) {
+ Future<std::shared_ptr<Service<Req, Resp>>> operator()(
+ std::shared_ptr<ClientBootstrap<Pipeline>> client) override {
connectionCount++;
return (*this->serviceFactory_)(client);
}
public:
SSLCacheClient(EventBase* eventBase, SSL_SESSION **pSess, ClientRunner* cr);
- ~SSLCacheClient() {
+ ~SSLCacheClient() override {
if (session_ && !FLAGS_global)
SSL_SESSION_free(session_);
if (socket_ != nullptr) {
void start();
- virtual void connectSuccess() noexcept;
+ void connectSuccess() noexcept override;
- virtual void connectErr(const AsyncSocketException& ex)
- noexcept ;
+ void connectErr(const AsyncSocketException& ex) noexcept override;
- virtual void handshakeSuc(AsyncSSLSocket* sock) noexcept;
-
- virtual void handshakeErr(
- AsyncSSLSocket* sock,
- const AsyncSocketException& ex) noexcept;
+ void handshakeSuc(AsyncSSLSocket* sock) noexcept override;
+ void handshakeErr(AsyncSSLSocket* sock,
+ const AsyncSocketException& ex) noexcept override;
};
int