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


Java Await类代码示例

本文整理汇总了Java中scala.concurrent.Await的典型用法代码示例。如果您正苦于以下问题:Java Await类的具体用法?Java Await怎么用?Java Await使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Await类属于scala.concurrent包,在下文中一共展示了Await类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyActorReady

import scala.concurrent.Await; //导入依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
private void verifyActorReady(ActorRef actorRef) {
    // Sometimes we see messages go to dead letters soon after creation - it seems the actor isn't quite
    // in a state yet to receive messages or isn't actually created yet. This seems to happen with
    // actorSelection so, to alleviate it, we use an actorSelection and send an Identify message with
    // retries to ensure it's ready.

    Timeout timeout = new Timeout(100, TimeUnit.MILLISECONDS);
    Throwable lastError = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
        try {
            ActorSelection actorSelection = system.actorSelection(actorRef.path().toString());
            Future<Object> future = Patterns.ask(actorSelection, new Identify(""), timeout);
            ActorIdentity reply = (ActorIdentity)Await.result(future, timeout.duration());
            Assert.assertNotNull("Identify returned null", reply.getRef());
            return;
        } catch (Exception | AssertionError e) {
            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            lastError = e;
        }
    }

    throw new RuntimeException(lastError);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:TestActorFactory.java

示例2: testExecuteRemoteOperationAsync

import scala.concurrent.Await; //导入依赖的package包/类
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testExecuteRemoteOperationAsync() {
    new JavaTestKit(getSystem()) {
        {
            ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));

            ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(true, shardActorRef));

            ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef,
                    mock(ClusterWrapper.class), mock(Configuration.class));

            ActorSelection actor = actorContext.actorSelection(shardActorRef.path());

            Future<Object> future = actorContext.executeOperationAsync(actor, "hello");

            try {
                Object result = Await.result(future, Duration.create(3, TimeUnit.SECONDS));
                assertEquals("Result", "hello", result);
            } catch (Exception e) {
                throw new AssertionError(e);
            }
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:ActorContextTest.java

示例3: cancelJob

import scala.concurrent.Await; //导入依赖的package包/类
public void cancelJob(JobID jobId) throws Exception {
    // this needs better support in the Flink Mini Cluster
    if (getCurrentlyRunningJobsJava().contains(jobId)) {
        final FiniteDuration timeout = timeout();
        final ActorGateway jobManagerGateway = getLeaderGateway(timeout);

        Future<Object> cancelFuture = jobManagerGateway.ask(
                new JobManagerMessages.CancelJob(jobId), timeout);

        Object result = Await.result(cancelFuture, timeout);
        if (!(result instanceof JobManagerMessages.CancellationSuccess)) {
            throw new Exception("Cancellation failed");
        }
    } else {
        throw new IllegalStateException("Job is not running");
    }
}
 
开发者ID:pravega,项目名称:flink-connectors,代码行数:18,代码来源:FlinkMiniClusterWithSavepointCommand.java

示例4: testPersistentActorWIthIgnite

import scala.concurrent.Await; //导入依赖的package包/类
@Test
public void testPersistentActorWIthIgnite() throws Exception {
    ActorRef actorRef = actorSystem.actorOf(Props.create(IgnitePersistentTestActor.class, "1"));
    actorRef.tell("+a", ActorRef.noSender());
    actorRef.tell("+b", ActorRef.noSender());
    actorRef.tell("+c", ActorRef.noSender());
    actorRef.tell("throw", ActorRef.noSender());

    Future<Object> future = Patterns.ask(actorRef, "-b", 1000);
    Await.result(future, Duration.create(1, TimeUnit.SECONDS));

    IgniteCache<Object, Object> cache = ignite.getOrCreateCache("akka-journal");
    Assert.assertEquals(cache.size(), 4);

    actorSystem.actorSelection("akka://test/user/**").tell("!!!", ActorRef.noSender());

    Await.result(actorSystem.terminate(), Duration.create(1, TimeUnit.SECONDS));
}
 
开发者ID:Romeh,项目名称:akka-persistance-ignite,代码行数:19,代码来源:IgniteJournalCacheTest.java

示例5: sendShutDown

import scala.concurrent.Await; //导入依赖的package包/类
private void sendShutDown(final ActorRef actor) throws Exception {
    testLog.info("sendShutDown for {} starting", actor.path());

    FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS);
    Future<Boolean> stopFuture = Patterns.gracefulStop(actor, duration, Shutdown.INSTANCE);

    Boolean stopped = Await.result(stopFuture, duration);
    assertEquals("Stopped", Boolean.TRUE, stopped);

    testLog.info("sendShutDown for {} ending", actor.path());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:LeadershipTransferIntegrationTest.java

示例6: testGetExistingYangTextSchemaSource

import scala.concurrent.Await; //导入依赖的package包/类
@Test
public void testGetExistingYangTextSchemaSource() throws Exception {
    String source = "Test source.";
    YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(
            ID, ByteSource.wrap(source.getBytes()));
    Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
            Futures.immediateCheckedFuture(schemaSource));

    Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =
            remoteRepository.getYangTextSchemaSource(ID);
    assertTrue(retrievedSourceFuture.isCompleted());
    YangTextSchemaSource resultSchemaSource = Await.result(retrievedSourceFuture,
            Duration.Zero()).getRepresentation();
    assertEquals(resultSchemaSource.getIdentifier(), schemaSource.getIdentifier());
    assertArrayEquals(resultSchemaSource.read(), schemaSource.read());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:RemoteYangTextSourceProviderImplTest.java

示例7: sendRegistrationRequests

import scala.concurrent.Await; //导入依赖的package包/类
private void sendRegistrationRequests() {
    for (Map.Entry<String, Boolean> entry : notifierRegistrationStatus.entrySet()) {
        if (!entry.getValue()) {
            try {
                LOG.debug("{} registering with {}", getSelf().path().toString(), entry.getKey());
                ActorRef notifier = Await.result(
                    getContext().actorSelection(entry.getKey()).resolveOne(duration), duration);

                notifier.tell(new RegisterRoleChangeListener(), getSelf());

            } catch (Exception e) {
                LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey());
            }
        }
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:ExampleRoleChangeListener.java

示例8: getListenerActorsInfo

import scala.concurrent.Await; //导入依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
private List<DataTreeListenerInfo> getListenerActorsInfo(Collection<ActorSelection> actors) {
    final Timeout timeout = new Timeout(20, TimeUnit.SECONDS);
    final List<Future<Object>> futureList = new ArrayList<>(actors.size());
    for (ActorSelection actor: actors) {
        futureList.add(Patterns.ask(actor, GetInfo.INSTANCE, timeout));
    }

    try {
        final List<DataTreeListenerInfo> listenerInfoList = new ArrayList<>();
        Await.result(Futures.sequence(futureList, ExecutionContext.Implicits$.MODULE$.global()),
                timeout.duration()).forEach(obj -> listenerInfoList.add((DataTreeListenerInfo) obj));
        return listenerInfoList;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:ShardDataTreeListenerInfoMXBeanImpl.java

示例9: testNegativeExistsWithReadWriteTransactionClosed

import scala.concurrent.Await; //导入依赖的package包/类
@Test(expected = ReadFailedException.class)
public void testNegativeExistsWithReadWriteTransactionClosed() throws Exception {

    final ActorRef shard = createShard();
    final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard,
            datastoreContext, shardStats);

    final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props,
            "testNegativeExistsWithReadWriteTransactionClosed");

    Future<Object> future = akka.pattern.Patterns.ask(subject,
            new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));

    subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();

    future = akka.pattern.Patterns.ask(subject,
            new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:ShardTransactionFailureTest.java

示例10: bodySuccess200

import scala.concurrent.Await; //导入依赖的package包/类
@Test public void bodySuccess200() throws Exception {
  server.enqueue(new MockResponse().setBody("Hi"));

  Future<String> future = service.body();
  String result = Await.result(future, Duration.create(5, SECONDS));
  assertThat(result).isEqualTo("Hi");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:FutureTest.java

示例11: bodySuccess404

import scala.concurrent.Await; //导入依赖的package包/类
@Test public void bodySuccess404() {
  server.enqueue(new MockResponse().setResponseCode(404));

  Future<String> future = service.body();
  try {
    Await.result(future, Duration.create(5, SECONDS));
    fail();
  } catch (Exception e) {
    assertThat(e)
        .isInstanceOf(HttpException.class) // Required for backwards compatibility.
        .isInstanceOf(retrofit2.HttpException.class)
        .hasMessage("HTTP 404 Client Error");
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:FutureTest.java

示例12: bodyFailure

import scala.concurrent.Await; //导入依赖的package包/类
@Test public void bodyFailure() {
  server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));

  Future<String> future = service.body();
  try {
    Await.result(future, Duration.create(5, SECONDS));
    fail();
  } catch (Exception e) {
    assertThat(e).isInstanceOf(IOException.class);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:FutureTest.java

示例13: stopAfterJob

import scala.concurrent.Await; //导入依赖的package包/类
private void stopAfterJob(ClusterClient client, JobID jobID) {
  Preconditions.checkNotNull(jobID, "The job id must not be null");
  try {
    Future<Object> replyFuture =
        client.getJobManagerGateway().ask(
            new ShutdownClusterAfterJob(jobID),
            AKKA_TIMEOUT);
    Await.ready(replyFuture, AKKA_TIMEOUT);
  } catch (Exception e) {
    throw new RuntimeException("Unable to tell application master to stop"
        + " once the specified job has been finished", e);
  }
}
 
开发者ID:uber,项目名称:AthenaX,代码行数:14,代码来源:JobDeployer.java

示例14: happyPathWOSales

import scala.concurrent.Await; //导入依赖的package包/类
@Test
public void happyPathWOSales() throws Exception {
	
	// Given
	final Integer bookId = 1000;
	
	final Book expectedBook = srvBookCheck.getBook(bookId).getValue();

	final List<Chapter> expectedChapters = expectedBook.getChapters().stream()
			.map(s -> srvChapterCheck.getChapter(s).getValue())
			.collect(Collectors.toList());
	
	final Author expectedAuthor = srvAuthorCheck.getAuthor( expectedBook.getIdAuthor() ).getValue();

	// When
	final Future<Either<Error, Summary>> summaryFu = srvSummary
			.getSummary(bookId);
	
	final Either<Error, Summary> res = Await.result(summaryFu, Duration.apply(100, TimeUnit.MILLISECONDS));

	// Then
	final Summary summary = res.right().get();

	assertEquals( expectedBook, summary.getBook() );
	assertEquals( false, summary.getSales().isPresent() );
	assertEquals( expectedAuthor, summary.getAuthor() );
	assertEquals( expectedChapters, summary.getChapter());

}
 
开发者ID:logicaalternativa,项目名称:monad-transformer-and-more,代码行数:30,代码来源:SrvSummaryFutEitherImpTest.java

示例15: ensureConstN

import scala.concurrent.Await; //导入依赖的package包/类
@Benchmark
public Void ensureConstN() throws Exception {
  Future<Void> f = constVoidFuture;
  for (int i = 0; i < N.n; i++)
    f.transform(ensureF, ec);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:ScalaFutureBenchmark.java


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