本文整理汇总了C++中Future::await方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::await方法的具体用法?C++ Future::await怎么用?C++ Future::await使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::await方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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);
}
示例4: 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);
}
示例5: coord
TEST(CoordinatorTest, Truncate)
{
const std::string path1 = utils::os::getcwd() + "/.log1";
const std::string path2 = utils::os::getcwd() + "/.log2";
utils::os::rmdir(path1);
utils::os::rmdir(path2);
Replica replica1(path1);
Replica replica2(path2);
Network network;
network.add(replica1.pid());
network.add(replica2.pid());
Coordinator coord(2, &replica1, &network);
{
Result<uint64_t> result = coord.elect(Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(0, result.get());
}
for (uint64_t position = 1; position <= 10; position++) {
Result<uint64_t> result =
coord.append(utils::stringify(position), Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(position, result.get());
}
{
Result<uint64_t> result = coord.truncate(7, Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(11, result.get());
}
{
Future<std::list<Action> > actions = replica1.read(6, 10);
ASSERT_TRUE(actions.await(2.0));
ASSERT_TRUE(actions.isFailed());
EXPECT_EQ("Bad read range (truncated position)", actions.failure());
}
{
Future<std::list<Action> > actions = replica1.read(7, 10);
ASSERT_TRUE(actions.await(2.0));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(4, actions.get().size());
foreach (const Action& action, actions.get()) {
ASSERT_TRUE(action.has_type());
ASSERT_EQ(Action::APPEND, action.type());
EXPECT_EQ(utils::stringify(action.position()), action.append().bytes());
}
}
utils::os::rmdir(path1);
utils::os::rmdir(path2);
}
示例6: 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);
}
示例7: 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());
}
示例8: remove
bool SlavesManager::remove(const string& hostname, uint16_t port)
{
// Make sure the slave is currently activated or deactivated.
if (!active.contains(hostname, port) &&
!inactive.contains(hostname, port)) {
LOG(WARNING) << "Attempted to remove unknown slave!";
return false;
}
// Get the storage system to persist the removal.
Future<bool> removed =
process::dispatch(storage->self(), &SlavesManagerStorage::remove,
hostname, port);
removed.await();
if (removed.isReady() && removed.get()) {
active.remove(hostname, port);
inactive.remove(hostname, port);
// Tell the master that this slave is now deactivated.
process::dispatch(master, &Master::deactivatedSlaveHostnamePort,
hostname, port);
return true;
}
return false;
}
示例9: if
/*
* Class: org_apache_mesos_state_ZooKeeperState
* Method: __expunge_get
* Signature: (J)Ljava/lang/Boolean;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_ZooKeeperState__1_1expunge_1get
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<bool>* future = (Future<bool>*) jfuture;
future->await();
if (future->isFailed()) {
jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return NULL;
} else if (future->isDiscarded()) {
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return NULL;
}
CHECK(future->isReady());
if (future->get()) {
jclass clazz = env->FindClass("java/lang/Boolean");
return env->GetStaticObjectField(
clazz, env->GetStaticFieldID(clazz, "TRUE", "Ljava/lang/Boolean;"));
}
jclass clazz = env->FindClass("java/lang/Boolean");
return env->GetStaticObjectField(
clazz, env->GetStaticFieldID(clazz, "FALSE", "Ljava/lang/Boolean;"));
}
示例10: if
/*
* Class: org_apache_mesos_state_AbstractState
* Method: __fetch_get
* Signature: (J)Lorg/apache/mesos/state/Variable;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1fetch_1get
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<Variable>* future = (Future<Variable>*) jfuture;
future->await();
if (future->isFailed()) {
jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return nullptr;
} else if (future->isDiscarded()) {
// TODO(benh): Consider throwing an ExecutionException since we
// never return true for 'isCancelled'.
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return nullptr;
}
CHECK_READY(*future);
Variable* variable = new Variable(future->get());
// Variable variable = new Variable();
jclass clazz = env->FindClass("org/apache/mesos/state/Variable");
jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
jobject jvariable = env->NewObject(clazz, _init_);
jfieldID __variable = env->GetFieldID(clazz, "__variable", "J");
env->SetLongField(jvariable, __variable, (jlong) variable);
return jvariable;
}
示例11: Nothing
// This hook locates the file created by environment decorator hook
// and deletes it.
virtual Try<Nothing> slaveRemoveExecutorHook(
const FrameworkInfo& frameworkInfo,
const ExecutorInfo& executorInfo)
{
LOG(INFO) << "Executing 'slaveRemoveExecutorHook'";
// Send a HookExecuted message to ourself. The hook test
// "VerifySlaveLaunchExecutorHook" will wait for the testing
// infrastructure to intercept this message. The intercepted message
// indicates successful execution of this hook.
HookProcess hookProcess;
process::spawn(&hookProcess);
Future<Nothing> future =
process::dispatch(hookProcess, &HookProcess::await);
process::dispatch(hookProcess, &HookProcess::signal);
// Make sure we don't terminate the process before the message self-send has
// completed.
future.await();
process::terminate(hookProcess);
process::wait(hookProcess);
return Nothing();
}
示例12: Timeout
TEST(CoordinatorTest, Failover)
{
const std::string path1 = utils::os::getcwd() + "/.log1";
const std::string path2 = utils::os::getcwd() + "/.log2";
utils::os::rmdir(path1);
utils::os::rmdir(path2);
Replica replica1(path1);
Replica replica2(path2);
Network network1;
network1.add(replica1.pid());
network1.add(replica2.pid());
Coordinator coord1(2, &replica1, &network1);
{
Result<uint64_t> result = coord1.elect(Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(0, result.get());
}
uint64_t position;
{
Result<uint64_t> result = coord1.append("hello world", Timeout(1.0));
ASSERT_TRUE(result.isSome());
position = result.get();
EXPECT_EQ(1, position);
}
Network network2;
network2.add(replica1.pid());
network2.add(replica2.pid());
Coordinator coord2(2, &replica2, &network2);
{
Result<uint64_t> result = coord2.elect(Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(position, result.get());
}
{
Future<std::list<Action> > actions = replica2.read(position, position);
ASSERT_TRUE(actions.await(2.0));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1, actions.get().size());
EXPECT_EQ(position, actions.get().front().position());
ASSERT_TRUE(actions.get().front().has_type());
ASSERT_EQ(Action::APPEND, actions.get().front().type());
EXPECT_EQ("hello world", actions.get().front().append().bytes());
}
utils::os::rmdir(path1);
utils::os::rmdir(path2);
}
示例13: deactivate
bool SlavesManager::deactivate(const string& hostname, uint16_t port)
{
// Make sure the slave is currently activated.
if (active.contains(hostname, port)) {
// Get the storage system to persist the deactivation.
Future<bool> deactivated =
process::dispatch(storage->self(), &SlavesManagerStorage::deactivate,
hostname, port);
deactivated.await();
if (deactivated.isReady() && deactivated.get()) {
active.remove(hostname, port);
inactive.put(hostname, port);
// Tell the master that this slave is now deactivated.
process::dispatch(master, &Master::deactivatedSlaveHostnamePort,
hostname, port);
return true;
}
}
return false;
}
示例14: add
bool SlavesManager::add(const string& hostname, uint16_t port)
{
// Ignore request if slave is already active.
if (active.contains(hostname, port)) {
LOG(WARNING) << "Attempted to add an already added slave!";
return false;
}
// Make sure this slave is not currently deactivated.
if (inactive.contains(hostname, port)) {
LOG(WARNING) << "Attempted to add a deactivated slave, "
<< "try activating it instead!";
return false;
}
// Ask the storage system to persist the addition.
Future<bool> added =
process::dispatch(storage->self(), &SlavesManagerStorage::add,
hostname, port);
added.await();
if (added.isReady() && added.get()) {
active.put(hostname, port);
// Tell the master that this slave is now active.
process::dispatch(master, &Master::activatedSlaveHostnamePort,
hostname, port);
return true;
}
return false;
}
示例15: if
/*
* Class: org_apache_mesos_state_AbstractState
* Method: __expunge_get
* Signature: (J)Ljava/lang/Boolean;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1expunge_1get
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<bool>* future = (Future<bool>*) jfuture;
future->await();
if (future->isFailed()) {
jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return NULL;
} else if (future->isDiscarded()) {
// TODO(benh): Consider throwing an ExecutionException since we
// never return true for 'isCancelled'.
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return NULL;
}
CHECK_READY(*future);
if (future->get()) {
jclass clazz = env->FindClass("java/lang/Boolean");
return env->GetStaticObjectField(
clazz, env->GetStaticFieldID(clazz, "TRUE", "Ljava/lang/Boolean;"));
}
jclass clazz = env->FindClass("java/lang/Boolean");
return env->GetStaticObjectField(
clazz, env->GetStaticFieldID(clazz, "FALSE", "Ljava/lang/Boolean;"));
}