当前位置: 首页>>代码示例>>C++>>正文


C++ TestFiberManager::run方法代码示例

本文整理汇总了C++中TestFiberManager::run方法的典型用法代码示例。如果您正苦于以下问题:C++ TestFiberManager::run方法的具体用法?C++ TestFiberManager::run怎么用?C++ TestFiberManager::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestFiberManager的用法示例。


在下文中一共展示了TestFiberManager::run方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rh

TEST(routeHandleTest, hashSalt) {
  vector<std::shared_ptr<TestHandle>> test_handles{
      make_shared<TestHandle>(GetRouteTestData(carbon::Result::FOUND, "a")),
      make_shared<TestHandle>(GetRouteTestData(carbon::Result::FOUND, "b")),
      make_shared<TestHandle>(GetRouteTestData(carbon::Result::FOUND, "c")),
  };
  auto outOfRangeRh = createNullRoute<typename TestRouterInfo::RouteHandleIf>();

  TestFiberManager fm;

  TestRouteHandle<SelectionRoute<TestRouterInfo, HashSelector<HashFunc>>> rh(
      get_route_handles(test_handles),
      HashSelector<HashFunc>(/* salt= */ "1", HashFunc(test_handles.size())),
      std::move(outOfRangeRh));

  fm.run([&]() {
    auto reply = rh.route(McGetRequest("0"));
    /* 01 % 3 == 1 */
    EXPECT_EQ("b", carbon::valueRangeSlow(reply).str());
  });

  fm.run([&]() {
    auto reply = rh.route(McGetRequest("1"));
    /* 11 % 3 == 2 */
    EXPECT_EQ("c", carbon::valueRangeSlow(reply).str());
  });

  fm.run([&]() {
    auto reply = rh.route(McGetRequest("2"));
    /* 21 % 3 == 0 */
    EXPECT_EQ("a", carbon::valueRangeSlow(reply).str());
  });
}
开发者ID:facebook,项目名称:mcrouter,代码行数:33,代码来源:RouteHandleTest.cpp

示例2: rh

TEST(routeHandleTest, hashSalt) {
  vector<std::shared_ptr<TestHandle>> test_handles{
    make_shared<TestHandle>(GetRouteTestData(mc_res_found, "a")),
    make_shared<TestHandle>(GetRouteTestData(mc_res_found, "b")),
    make_shared<TestHandle>(GetRouteTestData(mc_res_found, "c")),
  };

  TestFiberManager fm;

  TestRouteHandle<HashRoute<TestRouteHandleIf, HashFunc>> rh(
    get_route_handles(test_handles),
    /* salt= */ "1",
    HashFunc(test_handles.size()));

  fm.run([&]() {
      auto reply = rh.route(McRequestWithMcOp<mc_op_get>("0"));
      /* 01 % 3 == 1 */
      EXPECT_TRUE(toString(reply.value()) == "b");
    });

  fm.run([&]() {
      auto reply = rh.route(McRequestWithMcOp<mc_op_get>("1"));
      /* 11 % 3 == 2 */
      EXPECT_TRUE(toString(reply.value()) == "c");
    });

  fm.run([&]() {
      auto reply = rh.route(McRequestWithMcOp<mc_op_get>("2"));
      /* 21 % 3 == 0 */
      EXPECT_TRUE(toString(reply.value()) == "a");
    });
}
开发者ID:THIAGOWESLLEY2,项目名称:mcrouter,代码行数:32,代码来源:RouteHandleTest.cpp

示例3: UpdateRouteTestData

TEST(warmUpRouteTest, warmUp) {
  vector<std::shared_ptr<TestHandle>> test_handles{
    make_shared<TestHandle>(GetRouteTestData(mc_res_found, "a"),
                            UpdateRouteTestData(mc_res_stored),
                            DeleteRouteTestData(mc_res_deleted)),
    make_shared<TestHandle>(GetRouteTestData(mc_res_found, "b"),
                            UpdateRouteTestData(mc_res_stored),
                            DeleteRouteTestData(mc_res_notfound)),
    make_shared<TestHandle>(GetRouteTestData(mc_res_notfound, ""),
                            UpdateRouteTestData(mc_res_notstored),
                            DeleteRouteTestData(mc_res_notfound)),
  };
  auto route_handles = get_route_handles(test_handles);

  TestFiberManager fm;

  fm.run([&]() {
    TestRouteHandle<WarmUpRoute<TestRouteHandleIf>> rh(
      route_handles[0], route_handles[1], 1);

    auto reply_get = rh.route(
        McRequestWithMcOp<mc_op_get>("key_get"));
    EXPECT_TRUE("b" == toString(reply_get.value()));
    EXPECT_TRUE(vector<string>{"key_get"} != test_handles[0]->saw_keys);
    EXPECT_TRUE(vector<string>{"key_get"} == test_handles[1]->saw_keys);
    (test_handles[0]->saw_keys).clear();
    (test_handles[1]->saw_keys).clear();

    auto reply_del = rh.route(
        McRequestWithMcOp<mc_op_delete>("key_del"));
    EXPECT_TRUE(mc_res_notfound == reply_del.result());
    EXPECT_TRUE(vector<string>{"key_del"} != test_handles[0]->saw_keys);
    EXPECT_TRUE(vector<string>{"key_del"} == test_handles[1]->saw_keys);
  });
  fm.run([&]() {
    TestRouteHandle<WarmUpRoute<TestRouteHandleIf>> rh(
      route_handles[0], route_handles[2], 1);

    auto reply_get = rh.route(
        McRequestWithMcOp<mc_op_get>("key_get"));
    EXPECT_TRUE("a" == toString(reply_get.value()));
    EXPECT_TRUE(vector<string>{"key_get"} == test_handles[0]->saw_keys);
    EXPECT_TRUE(vector<string>{"key_get"} == test_handles[2]->saw_keys);
  });
  fm.run([&]() {
    EXPECT_TRUE((vector<uint32_t>{0, 1}) == test_handles[2]->sawExptimes);
    (test_handles[0]->saw_keys).clear();
    (test_handles[2]->saw_keys).clear();
    EXPECT_TRUE((vector<mc_op_t>{ mc_op_get, mc_op_add }) ==
              test_handles[2]->sawOperations);
  });
  fm.run([&]() {
    TestRouteHandle<WarmUpRoute<TestRouteHandleIf>> rh(
      route_handles[0], route_handles[2], 1);

    auto reply_del = rh.route(
        McRequestWithMcOp<mc_op_delete>("key_del"));
    EXPECT_TRUE(mc_res_notfound == reply_del.result());
    EXPECT_TRUE(vector<string>{"key_del"} != test_handles[0]->saw_keys);
    EXPECT_TRUE(vector<string>{"key_del"} == test_handles[2]->saw_keys);
  });


}
开发者ID:DennyLoko,项目名称:mcrouter,代码行数:64,代码来源:WarmUpRouteTest.cpp

示例4: factory

TEST(RouteHandleFactoryTest, sanity) {
  TestFiberManager fm;

  RouteHandleProvider<TestRouteHandleIf> provider;

  RouteHandleFactory<TestRouteHandleIf> factory(provider);

  auto rh = factory.create("AllAsyncRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("AllFastestRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("AllInitialRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("AllMajorityRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("AllSyncRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("FailoverRoute|NullRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("HashRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("HostIdRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("LatestRoute|NullRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("MissFailoverRoute|NullRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("RandomRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->routeSimple(McRequest("a"), McOperation<mc_op_get>());
    EXPECT_TRUE(reply.isError());
  });
}
开发者ID:cppfool,项目名称:mcrouter,代码行数:84,代码来源:routehandlefactory_test.cpp

示例5: pf

TEST(RouteHandleFactoryTest, sanity) {
  TestFiberManager fm;

  auto router = getTestRouter();
  auto proxy = router->getProxy(0);
  PoolFactory pf(folly::dynamic::object(), router->configApi());
  McRouteHandleProvider provider(*proxy, pf);
  RouteHandleFactory<McrouterRouteHandleIf> factory(provider);

  auto rh = factory.create("AllAsyncRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("AllFastestRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("AllInitialRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("AllMajorityRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("AllSyncRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("FailoverRoute|NullRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("HashRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("HostIdRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });

  rh = factory.create("LatestRoute|NullRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("LoggingRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    mockFiberContext();
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("MissFailoverRoute|NullRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_EQ(reply.result(), mc_res_notfound);
  });

  rh = factory.create("RandomRoute|ErrorRoute");
  EXPECT_TRUE(rh != nullptr);
  fm.run([&rh]() {
    auto reply = rh->route(McRequestWithMcOp<mc_op_get>("a"));
    EXPECT_TRUE(reply.isError());
  });
}
开发者ID:DennyLoko,项目名称:mcrouter,代码行数:94,代码来源:route_handle_factory_test.cpp


注:本文中的TestFiberManager::run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。