本文整理汇总了C++中Future::isPending方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::isPending方法的具体用法?C++ Future::isPending怎么用?C++ Future::isPending使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::isPending方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: group
TEST_F(ZooKeeperTest, LeaderDetector)
{
Group group(server->connectString(), NO_TIMEOUT, "/test/");
// Initialize two members.
Future<Group::Membership> membership1 =
group.join("member 1");
AWAIT_READY(membership1);
Future<Group::Membership> membership2 =
group.join("member 2");
AWAIT_READY(membership2);
LeaderDetector detector(&group);
// Detect the leader.
Future<Option<Group::Membership> > leader =
detector.detect(None());
AWAIT_READY(leader);
ASSERT_SOME_EQ(membership1.get(), leader.get());
// Detect next leader change.
leader = detector.detect(leader.get());
EXPECT_TRUE(leader.isPending());
// Leader doesn't change after cancelling the follower.
Future<bool> cancellation = group.cancel(membership2.get());
AWAIT_READY(cancellation);
EXPECT_TRUE(cancellation.get());
EXPECT_TRUE(leader.isPending());
// Join member 2 back.
membership2 = group.join("member 2");
AWAIT_READY(membership2);
EXPECT_TRUE(leader.isPending());
// Cancelling the incumbent leader allows member 2 to be elected.
cancellation = group.cancel(membership1.get());
AWAIT_READY(cancellation);
EXPECT_TRUE(cancellation.get());
AWAIT_READY(leader);
EXPECT_SOME_EQ(membership2.get(), leader.get());
// Cancelling the only member results in no leader elected.
leader = detector.detect(leader.get().get());
EXPECT_TRUE(leader.isPending());
cancellation = group.cancel(membership2.get());
AWAIT_READY(cancellation);
EXPECT_TRUE(cancellation.get());
AWAIT_READY(leader);
ASSERT_TRUE(leader.get().isNone());
}
示例2:
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());
}
示例3: coord
TEST_F(CoordinatorTest, ElectNoQuorum)
{
const string path = os::getcwd() + "/.log";
initializer.flags.path = path;
initializer.execute();
Shared<Replica> replica(new Replica(path));
set<UPID> pids;
pids.insert(replica->pid());
Shared<Network> network(new Network(pids));
Coordinator coord(2, replica, network);
Clock::pause();
Future<Option<uint64_t> > electing = coord.elect();
Clock::advance(Seconds(10));
Clock::settle();
EXPECT_TRUE(electing.isPending());
Clock::resume();
}
示例4: _recover
void RegistrarProcess::_recover(
const MasterInfo& info,
const Future<Variable<Registry> >& recovery)
{
updating = false;
CHECK(!recovery.isPending());
if (!recovery.isReady()) {
recovered.get()->fail("Failed to recover registrar: " +
(recovery.isFailed() ? recovery.failure() : "discarded"));
} else {
Duration elapsed = metrics.state_fetch.stop();
LOG(INFO) << "Successfully fetched the registry"
<< " (" << Bytes(recovery.get().get().ByteSize()) << ")"
<< " in " << elapsed;
// Save the registry.
variable = recovery.get();
// Perform the Recover operation to add the new MasterInfo.
Owned<Operation> operation(new Recover(info));
operations.push_back(operation);
operation->future()
.onAny(defer(self(), &Self::__recover, lambda::_1));
update();
}
}
示例5: return
/*
* Class: org_apache_mesos_state_AbstractState
* Method: __expunge_is_done
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_AbstractState__1_1expunge_1is_1done
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<bool>* future = (Future<bool>*) jfuture;
return (jboolean) !future->isPending() || future->hasDiscard();
}
示例6: encoder
// This test verifies that when the write end of the `reader` used in
// `transform` fails, a failure is returned to the caller.
TEST(RecordIOTransformTest, ReaderWriterEndFail)
{
// Write some data to the pipe so that records
// are available before any reads occur.
::recordio::Encoder<string> encoder(strings::upper);
string data;
data += encoder.encode("hello ");
data += encoder.encode("world! ");
process::http::Pipe pipeA;
pipeA.writer().write(data);
process::Owned<mesos::internal::recordio::Reader<string>> reader(
new mesos::internal::recordio::Reader<string>(
::recordio::Decoder<string>(strings::lower),
pipeA.reader()));
process::http::Pipe pipeB;
auto trim = [](const string& str) { return strings::trim(str); };
Future<Nothing> transform = mesos::internal::recordio::transform<string>(
std::move(reader), trim, pipeB.writer());
Future<string> future = pipeB.reader().readAll();
pipeA.writer().fail("Writer failure");
AWAIT_FAILED(transform);
ASSERT_TRUE(future.isPending());
}
示例7: 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();
}
示例8: return
/*
* Class: org_apache_mesos_state_ZooKeeperState
* Method: __names_is_done
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_ZooKeeperState__1_1names_1is_1done
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<vector<string> >* future = (Future<vector<string> >*) jfuture;
return (jboolean) !future->isPending();
}
示例9: select
TEST(FutureTest, Select)
{
Promise<int> promise1;
Promise<int> promise2;
Promise<int> promise3;
Promise<int> promise4;
std::set<Future<int>> futures = {
promise1.future(),
promise2.future(),
promise3.future(),
promise4.future()
};
promise1.set(42);
Future<Future<int>> future = select(futures);
AWAIT_READY(future);
AWAIT_READY(future.get());
EXPECT_EQ(42, future->get());
futures.erase(promise1.future());
future = select(futures);
EXPECT_TRUE(future.isPending());
future.discard();
AWAIT_DISCARDED(future);
}
示例10: readyFuture
TEST(FutureTest, Chain)
{
Future<string> s = readyFuture()
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
s.await();
ASSERT_TRUE(s.isReady());
EXPECT_EQ("true", s.get());
s = failedFuture()
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
s.await();
ASSERT_TRUE(s.isFailed());
Promise<bool> promise;
s = pendingFuture(promise.future())
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
ASSERT_TRUE(s.isPending());
promise.discard();
AWAIT_DISCARDED(s);
}
示例11: spawn
// The test verifies that callbacks are properly serialized by the
// Sequence object.
TEST(SequenceTest, Serialize)
{
TestProcess process;
spawn(process);
Sequence sequence;
Future<Nothing> bar = FUTURE_DISPATCH(_, &TestProcess::bar);
lambda::function<Future<Nothing>(void)> f;
f = defer(process, &TestProcess::foo);
sequence.add(f);
f = defer(process, &TestProcess::bar);
sequence.add(f);
// Flush the event queue to make sure that if the method 'bar' could
// have been invoked, the future 'bar' would be satisfied before the
// pending check below.
Clock::pause();
Clock::settle();
Clock::resume();
EXPECT_TRUE(bar.isPending());
process.promise.set(Nothing());
AWAIT_READY(bar);
terminate(process);
wait(process);
}
示例12: Fork
// This test checks that the we can reap a child process and obtain
// the correct exit status.
TEST(Reap, ChildProcess)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
// The child process sleeps and will be killed by the parent.
Try<ProcessTree> tree = Fork(None(),
Exec("sleep 10"))();
ASSERT_SOME(tree);
pid_t child = tree.get();
// Reap the child process.
Future<Option<int> > status = process::reap(child);
// Now kill the child.
EXPECT_EQ(0, kill(child, SIGKILL));
Clock::pause();
// Now advance time until the reaper reaps the child.
while (status.isPending()) {
Clock::advance(Seconds(1));
Clock::settle();
}
AWAIT_READY(status);
// Check if the status is correct.
ASSERT_SOME(status.get());
int status_ = status.get().get();
ASSERT_TRUE(WIFSIGNALED(status_));
ASSERT_EQ(SIGKILL, WTERMSIG(status_));
Clock::resume();
}
示例13: ProcessBase
TEST(NetworkTest, Watch)
{
UPID pid1 = ProcessBase().self();
UPID pid2 = ProcessBase().self();
Network network;
// Test the default parameter.
Future<size_t> future = network.watch(1u);
AWAIT_READY(future);
EXPECT_EQ(0u, future.get());
future = network.watch(2u, Network::NOT_EQUAL_TO);
AWAIT_READY(future);
EXPECT_EQ(0u, future.get());
future = network.watch(0u, Network::GREATER_THAN_OR_EQUAL_TO);
AWAIT_READY(future);
EXPECT_EQ(0u, future.get());
future = network.watch(1u, Network::LESS_THAN);
AWAIT_READY(future);
EXPECT_EQ(0u, future.get());
network.add(pid1);
future = network.watch(1u, Network::EQUAL_TO);
AWAIT_READY(future);
EXPECT_EQ(1u, future.get());
future = network.watch(1u, Network::GREATER_THAN);
ASSERT_TRUE(future.isPending());
network.add(pid2);
AWAIT_READY(future);
EXPECT_EQ(2u, future.get());
future = network.watch(1u, Network::LESS_THAN_OR_EQUAL_TO);
ASSERT_TRUE(future.isPending());
network.remove(pid2);
AWAIT_READY(future);
EXPECT_EQ(1u, future.get());
}
示例14:
TEST(CollectTest, Failure)
{
Promise<int> promise1;
Promise<bool> promise2;
Future<std::tuple<int, bool>> collect =
process::collect(promise1.future(), promise2.future());
ASSERT_TRUE(collect.isPending());
promise1.set(42);
ASSERT_TRUE(collect.isPending());
promise2.set(true);
AWAIT_READY(collect);
std::tuple<int, bool> values = collect.get();
ASSERT_EQ(42, std::get<0>(values));
ASSERT_TRUE(std::get<1>(values));
// Collect should fail when a future fails.
Promise<bool> promise3;
collect = process::collect(promise1.future(), promise3.future());
ASSERT_TRUE(collect.isPending());
promise3.fail("failure");
AWAIT_FAILED(collect);
// Collect should fail when a future is discarded.
Promise<bool> promise4;
collect = process::collect(promise1.future(), promise4.future());
ASSERT_TRUE(collect.isPending());
promise4.discard();
AWAIT_FAILED(collect);
}
示例15:
TEST(DecoderTest, StreamingResponseFailure)
{
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";
// The body is shorter than the content length!
const string body = "1";
deque<Response*> responses = decoder.decode(headers.data(), headers.length());
ASSERT_FALSE(decoder.failed());
ASSERT_EQ(1, responses.size());
Response* response = responses[0];
EXPECT_EQ("200 OK", response->status);
EXPECT_EQ(3, response->headers.size());
ASSERT_EQ(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_TRUE(read.isReady());
EXPECT_EQ("1", read.get());
// Body is not yet complete.
read = reader.read();
EXPECT_TRUE(read.isPending());
// Feeding EOF to the decoder should trigger a failure!
decoder.decode("", 0);
EXPECT_TRUE(read.isFailed());
EXPECT_EQ("failed to decode body", read.failure());
}