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


C++ Future::isReady方法代码示例

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


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

示例1: statistics

TEST(Statistics, truncate)
{
  Clock::pause();

  Statistics statistics(seconds(60*60*24));

  statistics.set("statistic", 3.14);

  Future<map<seconds, double> > values = statistics.get("statistic");

  values.await();

  ASSERT_TRUE(values.isReady());
  EXPECT_EQ(1, values.get().size());
  EXPECT_GE(Clock::now(), values.get().begin()->first.value);
  EXPECT_DOUBLE_EQ(3.14, values.get().begin()->second);

  Clock::advance((60*60*24) + 1);

  statistics.increment("statistic");

  values = statistics.get("statistic");

  values.await();

  ASSERT_TRUE(values.isReady());
  EXPECT_EQ(1, values.get().size());
  EXPECT_GE(Clock::now(), values.get().begin()->first.value);
  EXPECT_DOUBLE_EQ(4.14, values.get().begin()->second);

  Clock::resume();
}
开发者ID:mailmahee,项目名称:libprocess,代码行数:32,代码来源:statistics_tests.cpp

示例2: statistics

TEST(Statistics, truncate)
{
  Clock::pause();

  Statistics statistics(Days(1));

  statistics.set("test", "statistic", 3.0);

  Future<map<Seconds, double> > values =
    statistics.timeseries("test", "statistic");

  values.await();

  ASSERT_TRUE(values.isReady());
  EXPECT_EQ(1, values.get().size());
  EXPECT_GE(Clock::now(), values.get().begin()->first.secs());
  EXPECT_DOUBLE_EQ(3.0, values.get().begin()->second);

  Clock::advance((60*60*24) + 1);

  statistics.increment("test", "statistic");

  values = statistics.timeseries("test", "statistic");

  values.await();

  ASSERT_TRUE(values.isReady());
  EXPECT_EQ(1, values.get().size());
  EXPECT_GE(Clock::now(), values.get().begin()->first.secs());
  EXPECT_DOUBLE_EQ(4.0, values.get().begin()->second);

  Clock::resume();
}
开发者ID:vanillahsu,项目名称:libprocess,代码行数:33,代码来源:statistics_tests.cpp

示例3: spawn

TEST(ProcessTest, Defer2)
{
  ASSERT_TRUE(GTEST_IS_THREADSAFE);

  DeferProcess process;

  PID<DeferProcess> pid = spawn(process);

  Future<string> f = dispatch(pid, &DeferProcess::func1, 41);

  f.await();

  ASSERT_TRUE(f.isReady());
  EXPECT_EQ("41", f.get());

  f = dispatch(pid, &DeferProcess::func2, 41);

  f.await();

  ASSERT_TRUE(f.isReady());
  EXPECT_EQ("42", f.get());

  terminate(pid);
  wait(pid);
}
开发者ID:LinxiaHu,项目名称:mesos,代码行数:25,代码来源:process_tests.cpp

示例4: Failure

Future<Nothing> HealthCheckerProcess::__tcpHealthCheck(
    const tuple<
        Future<Option<int>>,
        Future<string>,
        Future<string>>& t)
{
  Future<Option<int>> status = std::get<0>(t);
  if (!status.isReady()) {
    return Failure(
        "Failed to get the exit status of the " + string(TCP_CHECK_COMMAND) +
        " process: " + (status.isFailed() ? status.failure() : "discarded"));
  }

  if (status->isNone()) {
    return Failure(
        "Failed to reap the " + string(TCP_CHECK_COMMAND) + " process");
  }

  int statusCode = status->get();
  if (statusCode != 0) {
    Future<string> error = std::get<2>(t);
    if (!error.isReady()) {
      return Failure(
          string(TCP_CHECK_COMMAND) + " returned " +
          WSTRINGIFY(statusCode) + "; reading stderr failed: " +
          (error.isFailed() ? error.failure() : "discarded"));
    }

    return Failure(
        string(TCP_CHECK_COMMAND) + " returned " +
        WSTRINGIFY(statusCode) + ": " + error.get());
  }

  return Nothing();
}
开发者ID:liyubobj,项目名称:mesos,代码行数:35,代码来源:health_checker.cpp

示例5: close

TEST(IO, Read)
{
  ASSERT_TRUE(GTEST_IS_THREADSAFE);

  int pipes[2];
  char data[3];

  // Create a blocking pipe.
  ASSERT_NE(-1, ::pipe(pipes));

  // Test on a blocking file descriptor.
  AWAIT_EXPECT_FAILED(io::read(pipes[0], data, 3));

  close(pipes[0]);
  close(pipes[1]);

  // Test on a closed file descriptor.
  AWAIT_EXPECT_FAILED(io::read(pipes[0], data, 3));

  // Create a nonblocking pipe.
  ASSERT_NE(-1, ::pipe(pipes));
  ASSERT_SOME(os::nonblock(pipes[0]));
  ASSERT_SOME(os::nonblock(pipes[1]));

  // Test reading nothing.
  AWAIT_EXPECT_FAILED(io::read(pipes[0], data, 0));

  // Test successful read.
  Future<size_t> future = io::read(pipes[0], data, 3);
  ASSERT_FALSE(future.isReady());

  ASSERT_EQ(2, write(pipes[1], "hi", 2));

  AWAIT_ASSERT_EQ(2u, future);
  EXPECT_EQ('h', data[0]);
  EXPECT_EQ('i', data[1]);

  // Test cancellation.
  future = io::read(pipes[0], data, 1);
  ASSERT_FALSE(future.isReady());

  future.discard();

  ASSERT_EQ(3, write(pipes[1], "omg", 3));

  AWAIT_ASSERT_EQ(3u, io::read(pipes[0], data, 3));
  EXPECT_EQ('o', data[0]);
  EXPECT_EQ('m', data[1]);
  EXPECT_EQ('g', data[2]);

  // Test read EOF.
  future = io::read(pipes[0], data, 3);
  ASSERT_FALSE(future.isReady());

  close(pipes[1]);

  AWAIT_ASSERT_EQ(0u, future);

  close(pipes[0]);
}
开发者ID:AsylumCorp,项目名称:mesos,代码行数:60,代码来源:io_tests.cpp

示例6:

TEST(Future, toUnitWhileInProgress) {
  Promise<int> p;
  Future<Unit> fu = p.getFuture().unit();
  EXPECT_FALSE(fu.isReady());
  p.setValue(42);
  EXPECT_TRUE(fu.isReady());
}
开发者ID:SamSaffron,项目名称:DiscourseMobile,代码行数:7,代码来源:FutureTest.cpp

示例7: Failure

Future<Nothing> untar(const string& file, const string& directory)
{
  const vector<string> argv = {
    "tar",
    "-C",
    directory,
    "-x",
    "-f",
    file
  };

  Try<Subprocess> s = subprocess(
      "tar",
      argv,
      Subprocess::PATH("/dev/null"),
      Subprocess::PATH("/dev/null"),
      Subprocess::PIPE());

  if (s.isError()) {
    return Failure("Failed to execute the subprocess: " + s.error());
  }

  return await(
      s.get().status(),
      process::io::read(s.get().err().get()))
    .then([](const tuple<
        Future<Option<int>>,
        Future<string>>& t) -> Future<Nothing> {
      Future<Option<int>> status = std::get<0>(t);
      if (!status.isReady()) {
        return Failure(
          "Failed to get the exit status of the subprocess: " +
          (status.isFailed() ? status.failure() : "discarded"));
      }

      Future<string> error = std::get<1>(t);
      if (!error.isReady()) {
        return Failure(
          "Failed to read stderr from the subprocess: " +
          (error.isFailed() ? error.failure() : "discarded"));
      }

      if (status->isNone()) {
        return Failure("Failed to reap the subprocess");
      }

      if (status->get() != 0) {
        return Failure(
            "Unexpected result from the subprocess: " +
            WSTRINGIFY(status->get()) +
            ", stderr='" + error.get() + "'");
      }

      return Nothing();
    });
}
开发者ID:lins05,项目名称:mesos,代码行数:56,代码来源:puller.cpp

示例8: replica

TEST(ReplicaTest, Promise)
{
  const std::string path = utils::os::getcwd() + "/.log";

  utils::os::rmdir(path);

  Replica replica(path);

  PromiseRequest request;
  PromiseResponse response;
  Future<PromiseResponse> future;

  request.set_id(2);

  future = protocol::promise(replica.pid(), request);

  future.await(2.0);
  ASSERT_TRUE(future.isReady());

  response = future.get();
  EXPECT_TRUE(response.okay());
  EXPECT_EQ(2, response.id());
  EXPECT_TRUE(response.has_position());
  EXPECT_EQ(0, response.position());
  EXPECT_FALSE(response.has_action());

  request.set_id(1);

  future = protocol::promise(replica.pid(), request);

  future.await(2.0);
  ASSERT_TRUE(future.isReady());

  response = future.get();
  EXPECT_FALSE(response.okay());
  EXPECT_EQ(1, response.id());
  EXPECT_FALSE(response.has_position());
  EXPECT_FALSE(response.has_action());

  request.set_id(3);

  future = protocol::promise(replica.pid(), request);

  future.await(2.0);
  ASSERT_TRUE(future.isReady());

  response = future.get();
  EXPECT_TRUE(response.okay());
  EXPECT_EQ(3, response.id());
  EXPECT_TRUE(response.has_position());
  EXPECT_EQ(0, response.position());
  EXPECT_FALSE(response.has_action());

  utils::os::rmdir(path);
}
开发者ID:vicever,项目名称:mesos,代码行数:55,代码来源:log_tests.cpp

示例9:

// Makes sure that the unwrap call also works when the promise was not yet
// fulfilled, and that the returned Future<T> becomes ready once the promise
// is fulfilled.
TEST(Unwrap, futureNotReady) {
  Promise<Future<int>> p;
  Future<Future<int>> future = p.getFuture();
  Future<int> unwrapped = future.unwrap();
  // Sanity - should not be ready before the promise is fulfilled.
  ASSERT_FALSE(unwrapped.isReady());
  // Fulfill the promise and make sure the unwrapped future is now ready.
  p.setValue(makeFuture(5484));
  ASSERT_TRUE(unwrapped.isReady());
  EXPECT_EQ(5484, unwrapped.value());
}
开发者ID:Orvid,项目名称:folly,代码行数:14,代码来源:UnwrapTest.cpp

示例10: Failure

Future<Nothing> NetworkCniIsolatorProcess::_detach(
    const ContainerID& containerId,
    const std::string& networkName,
    const string& plugin,
    const tuple<Future<Option<int>>, Future<string>>& t)
{
  CHECK(infos.contains(containerId));
  CHECK(infos[containerId]->containerNetworks.contains(networkName));

  Future<Option<int>> status = std::get<0>(t);
  if (!status.isReady()) {
    return Failure(
        "Failed to get the exit status of the CNI plugin '" +
        plugin + "' subprocess: " +
        (status.isFailed() ? status.failure() : "discarded"));
  }

  if (status->isNone()) {
    return Failure(
        "Failed to reap the CNI plugin '" + plugin + "' subprocess");
  }

  if (status.get() == 0) {
    const string ifDir = paths::getInterfaceDir(
        rootDir.get(),
        containerId.value(),
        networkName,
        infos[containerId]->containerNetworks[networkName].ifName);

    Try<Nothing> rmdir = os::rmdir(ifDir);
    if (rmdir.isError()) {
      return Failure(
          "Failed to remove interface directory '" +
          ifDir + "': " + rmdir.error());
    }

    return Nothing();
  }

  // CNI plugin will print result (in case of success) or error (in
  // case of failure) to stdout.
  Future<string> output = std::get<1>(t);
  if (!output.isReady()) {
    return Failure(
        "Failed to read stdout from the CNI plugin '" +
        plugin + "' subprocess: " +
        (output.isFailed() ? output.failure() : "discarded"));
  }

  return Failure(
      "The CNI plugin '" + plugin + "' failed to detach container "
      "from network '" + networkName + "': " + output.get());
}
开发者ID:gaoguanguo,项目名称:mesos,代码行数:53,代码来源:cni.cpp

示例11: Failure

static Future<Nothing> _fetch(const Future<std::tuple<
    Future<Option<int>>,
    Future<string>,
    Future<string>>>& future)
{
  CHECK_READY(future);

  Future<Option<int>> status = std::get<0>(future.get());
  if (!status.isReady()) {
    return Failure(
        "Failed to get the exit status of the curl subprocess: " +
        (status.isFailed() ? status.failure() : "discarded"));
  }

  if (status->isNone()) {
    return Failure("Failed to reap the curl subprocess");
  }

  if (status->get() != 0) {
    Future<string> error = std::get<2>(future.get());
    if (!error.isReady()) {
      return Failure(
          "Failed to perform 'curl'. Reading stderr failed: " +
          (error.isFailed() ? error.failure() : "discarded"));
    }

    return Failure("Failed to perform 'curl': " + error.get());
  }

  Future<string> output = std::get<1>(future.get());
  if (!output.isReady()) {
    return Failure(
        "Failed to read stdout from 'curl': " +
        (output.isFailed() ? output.failure() : "discarded"));
  }

  // Parse the output and get the HTTP response code.
  Try<int> code = numify<int>(output.get());
  if (code.isError()) {
    return Failure("Unexpected output from 'curl': " + output.get());
  }

  if (code.get() != http::Status::OK) {
    return Failure(
        "Unexpected HTTP response code: " +
        http::Status::string(code.get()));
  }

  return Nothing();
}
开发者ID:juanramb,项目名称:mesos,代码行数:50,代码来源:curl.cpp

示例12: response

TEST(DecoderTest, StreamingResponse)
{
  StreamingResponseDecoder decoder;

  const string headers =
    "HTTP/1.1 200 OK\r\n"
    "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n"
    "Content-Type: text/plain\r\n"
    "Content-Length: 2\r\n"
    "\r\n";

  const string body = "hi";

  deque<http::Response*> responses =
    decoder.decode(headers.data(), headers.length());

  EXPECT_FALSE(decoder.failed());
  EXPECT_TRUE(decoder.writingBody());
  ASSERT_EQ(1, responses.size());

  Owned<http::Response> response(responses[0]);

  EXPECT_EQ("200 OK", response->status);
  EXPECT_EQ(3, response->headers.size());

  ASSERT_EQ(http::Response::PIPE, response->type);
  ASSERT_SOME(response->reader);

  http::Pipe::Reader reader = response->reader.get();
  Future<string> read = reader.read();
  EXPECT_TRUE(read.isPending());

  decoder.decode(body.data(), body.length());
  EXPECT_FALSE(decoder.failed());
  EXPECT_FALSE(decoder.writingBody());

  // Feeding EOF to the decoder should be ok.
  decoder.decode("", 0);
  EXPECT_FALSE(decoder.failed());
  EXPECT_FALSE(decoder.writingBody());

  EXPECT_TRUE(read.isReady());
  EXPECT_EQ("hi", read.get());

  // Response should be complete.
  read = reader.read();
  EXPECT_TRUE(read.isReady());
  EXPECT_EQ("", read.get());
}
开发者ID:GYGit,项目名称:mesos,代码行数:49,代码来源:decoder_tests.cpp

示例13:

TEST(HTTPTest, PipeEOF)
{
  http::Pipe pipe;
  http::Pipe::Reader reader = pipe.reader();
  http::Pipe::Writer writer = pipe.writer();

  // A 'read' on an empty pipe should block.
  Future<string> read = reader.read();
  EXPECT_TRUE(read.isPending());

  // Writing an empty string should have no effect.
  EXPECT_TRUE(writer.write(""));
  EXPECT_TRUE(read.isPending());

  // After a 'write' the pending 'read' should complete.
  EXPECT_TRUE(writer.write("hello"));
  ASSERT_TRUE(read.isReady());
  EXPECT_EQ("hello", read.get());

  // After a 'write' a call to 'read' should be completed immediately.
  ASSERT_TRUE(writer.write("world"));

  read = reader.read();
  ASSERT_TRUE(read.isReady());
  EXPECT_EQ("world", read.get());

  // Close the write end of the pipe and ensure the remaining
  // data can be read.
  EXPECT_TRUE(writer.write("!"));
  EXPECT_TRUE(writer.close());
  AWAIT_EQ("!", reader.read());

  // End of file should be reached.
  AWAIT_EQ("", reader.read());
  AWAIT_EQ("", reader.read());

  // Writes to a pipe with the write end closed are ignored.
  EXPECT_FALSE(writer.write("!"));
  AWAIT_EQ("", reader.read());

  // The write end cannot be closed twice.
  EXPECT_FALSE(writer.close());

  // Close the read end, this should not notify the writer
  // since the write end was already closed.
  EXPECT_TRUE(reader.close());
  EXPECT_TRUE(writer.readerClosed().isPending());
}
开发者ID:haosdent,项目名称:mesos,代码行数:48,代码来源:http_tests.cpp

示例14: CHECK

Future<bool> LeaderContenderProcess::withdraw()
{
  if (contending.isNone()) {
    // Nothing to withdraw because the contender has not contended.
    return false;
  }

  if (withdrawing.isSome()) {
    // Repeated calls to withdraw get the same result.
    return withdrawing.get();
  }

  withdrawing = new Promise<bool>();

  CHECK(!candidacy.isDiscarded());

  if (candidacy.isPending()) {
    // If we have not obtained the candidacy yet, we withdraw after
    // it is obtained.
    LOG(INFO) << "Withdraw requested before the candidacy is obtained; will "
              << "withdraw after it happens";
    candidacy.onAny(defer(self(), &Self::cancel));
  } else if (candidacy.isReady()) {
    cancel();
  } else {
    // We have failed to obtain the candidacy so we do not need to
    // cancel it.
    return false;
  }

  return withdrawing.get()->future();
}
开发者ID:GrovoLearning,项目名称:mesos,代码行数:32,代码来源:contender.cpp

示例15: collect

TEST(Process, collect)
{
  ASSERT_TRUE(GTEST_IS_THREADSAFE);

  Promise<int> promise1;
  Promise<int> promise2;
  Promise<int> promise3;
  Promise<int> promise4;

  std::list<Future<int> > futures;
  futures.push_back(promise1.future());
  futures.push_back(promise2.future());
  futures.push_back(promise3.future());
  futures.push_back(promise4.future());

  promise1.set(1);
  promise2.set(2);
  promise3.set(3);
  promise4.set(4);

  Future<std::list<int> > future = collect(futures);

  EXPECT_TRUE(future.await());
  EXPECT_TRUE(future.isReady());

  std::list<int> values;
  values.push_back(1);
  values.push_back(2);
  values.push_back(3);
  values.push_back(4);

  EXPECT_EQ(values, future.get());
}
开发者ID:mailmahee,项目名称:libprocess,代码行数:33,代码来源:tests.cpp


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