Example #1
0
TEST(libmcrouter, listenSock) {
  /* Create a listen socket, pass it to a child mcrouter and
     check that communication through the socket works */
  using namespace facebook::memcache;

  ListenSocket listenSock;

  std::vector<std::string> args{MCROUTER_INSTALL_PATH "mcrouter/mcrouter",
        "--listen-sock-fd", folly::to<std::string>(listenSock.getSocketFd()),
        "--config-str", configString };
  auto testArgs = defaultTestCommandLineArgs();
  args.insert(args.end(), testArgs.begin(), testArgs.end());
  folly::Subprocess mcr(args);

  SCOPE_EXIT {
    mcr.terminate();
    mcr.wait();
  };

  const std::string kSetRequest = "set testkey 0 0 1\r\nv\r\n";
  const std::string kStoredReply = "STORED\r\n";
  const std::string kGetRequest = "get testkey\r\n";
  const std::string kGetReply = "VALUE testkey 0 1\r\nv\r\nEND\r\n";

  ClientSocket mcrSock(listenSock.getPort());
  EXPECT_EQ(kStoredReply, mcrSock.sendRequest(kSetRequest));
  EXPECT_EQ(kGetReply, mcrSock.sendRequest(kGetRequest));

  ClientSocket mcSock(memcacheLocal->getPort());
  EXPECT_EQ(kGetReply, mcSock.sendRequest(kGetRequest));
}
Example #2
0
void umbrellaBinaryReply(std::string data, mc_res_t expectedResult) {
  ListenSocket sock;

  std::thread serverThread([&sock, &data] {
    auto sockFd = ::accept(sock.getSocketFd(), nullptr, nullptr);
    // Don't read anything, just reply with a serialized reply.
    size_t n = folly::writeFull(sockFd, data.data(), data.size());
    CHECK(n == data.size());
  });

  TestClient client("localhost", sock.getPort(), 200, mc_umbrella_protocol);
  client.sendGet("test", expectedResult);
  client.waitForReplies();
  serverThread.join();
}