本文整理汇总了Java中scala.concurrent.duration.Deadline.hasTimeLeft方法的典型用法代码示例。如果您正苦于以下问题:Java Deadline.hasTimeLeft方法的具体用法?Java Deadline.hasTimeLeft怎么用?Java Deadline.hasTimeLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scala.concurrent.duration.Deadline
的用法示例。
在下文中一共展示了Deadline.hasTimeLeft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForLeaderNotification
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
private void waitForLeaderNotification(
String expectedJobManagerURL,
GatewayRetriever<JobManagerGateway> retriever,
Deadline deadline) throws Exception {
while (deadline.hasTimeLeft()) {
Optional<JobManagerGateway> optJobManagerGateway = retriever.getNow();
if (optJobManagerGateway.isPresent() && Objects.equals(expectedJobManagerURL, optJobManagerGateway.get().getAddress())) {
return;
}
else {
Thread.sleep(100);
}
}
}
示例2: restartAfterFailure
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
private static void restartAfterFailure(ExecutionGraph eg, FiniteDuration timeout, boolean haltAfterRestart) throws InterruptedException {
makeAFailureAndWait(eg, timeout);
assertEquals(JobStatus.RUNNING, eg.getState());
// Wait for deploying after async restart
Deadline deadline = timeout.fromNow();
waitForAllResourcesToBeAssignedAfterAsyncRestart(eg, deadline);
if (haltAfterRestart) {
if (deadline.hasTimeLeft()) {
haltExecution(eg);
} else {
fail("Failed to wait until all execution attempts left the state DEPLOYING.");
}
}
}
示例3: getJobManagerPort
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Parses the port from the job manager logs and returns it.
*
* <p>If a call to this method succeeds, successive calls will directly
* return the port and re-parse the logs.
*
* @param timeout Timeout for log parsing.
* @return The port of the job manager
* @throws InterruptedException If interrupted while waiting before
* retrying to parse the logs
* @throws NumberFormatException If the parsed port is not a number
*/
public int getJobManagerPort(FiniteDuration timeout) throws InterruptedException, NumberFormatException {
if (jobManagerPort > 0) {
return jobManagerPort;
} else {
Deadline deadline = timeout.fromNow();
while (deadline.hasTimeLeft()) {
Matcher matcher = PORT_PATTERN.matcher(getProcessOutput());
if (matcher.find()) {
String port = matcher.group(1);
jobManagerPort = Integer.parseInt(port);
return jobManagerPort;
} else {
Thread.sleep(100);
}
}
throw new RuntimeException("Could not parse port from logs");
}
}
示例4: waitForJobRemoved
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
private void waitForJobRemoved(
JobID jobId, JobManagerProcess jobManager, ActorSystem actorSystem, FiniteDuration timeout)
throws Exception {
ActorRef jobManagerRef = jobManager.getActorRef(actorSystem, timeout);
AkkaActorGateway jobManagerGateway = new AkkaActorGateway(jobManagerRef, null);
Future<Object> archiveFuture = jobManagerGateway.ask(JobManagerMessages.getRequestArchive(), timeout);
ActorRef archive = ((JobManagerMessages.ResponseArchive) Await.result(archiveFuture, timeout)).actor();
AkkaActorGateway archiveGateway = new AkkaActorGateway(archive, null);
Deadline deadline = timeout.fromNow();
while (deadline.hasTimeLeft()) {
JobManagerMessages.JobStatusResponse resp = JobManagerActorTestUtils
.requestJobStatus(jobId, archiveGateway, deadline.timeLeft());
if (resp instanceof JobManagerMessages.JobNotFound) {
Thread.sleep(100);
}
else {
return;
}
}
}
示例5: testCancelWhileRestarting
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
@Test
public void testCancelWhileRestarting() throws Exception {
// We want to manually control the restart and delay
RestartStrategy restartStrategy = new InfiniteDelayRestartStrategy();
Tuple2<ExecutionGraph, Instance> executionGraphInstanceTuple = createExecutionGraph(restartStrategy);
ExecutionGraph executionGraph = executionGraphInstanceTuple.f0;
Instance instance = executionGraphInstanceTuple.f1;
// Kill the instance and wait for the job to restart
instance.markDead();
Deadline deadline = TestingUtils.TESTING_DURATION().fromNow();
while (deadline.hasTimeLeft() &&
executionGraph.getState() != JobStatus.RESTARTING) {
Thread.sleep(100);
}
assertEquals(JobStatus.RESTARTING, executionGraph.getState());
// Canceling needs to abort the restart
executionGraph.cancel();
assertEquals(JobStatus.CANCELED, executionGraph.getState());
// The restart has been aborted
executionGraph.restart(executionGraph.getGlobalModVersion());
assertEquals(JobStatus.CANCELED, executionGraph.getState());
}
示例6: waitForAllResourcesToBeAssignedAfterAsyncRestart
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
private static void waitForAllResourcesToBeAssignedAfterAsyncRestart(ExecutionGraph eg, Deadline deadline) throws InterruptedException {
boolean success = false;
while (deadline.hasTimeLeft() && !success) {
success = true;
for (ExecutionVertex vertex : eg.getAllExecutionVertices()) {
if (vertex.getCurrentExecutionAttempt().getAssignedResource() == null) {
success = false;
Thread.sleep(100);
break;
}
}
}
}
示例7: getActorRef
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Waits for the job manager to be reachable.
*
* <p><strong>Important:</strong> Make sure to set the timeout larger than Akka's gating
* time. Otherwise, this will effectively not wait for the JobManager to startup, because the
* time out will fire immediately.
*
* @param actorSystem Actor system to be used to resolve JobManager address.
* @param timeout Timeout (make sure to set larger than Akka's gating time).
*/
public ActorRef getActorRef(ActorSystem actorSystem, FiniteDuration timeout)
throws Exception {
if (jobManagerRef != null) {
return jobManagerRef;
}
checkNotNull(actorSystem, "Actor system");
// Deadline passes timeout ms
Deadline deadline = timeout.fromNow();
while (deadline.hasTimeLeft()) {
try {
// If the Actor is not reachable yet, this throws an Exception. Retry until the
// deadline passes.
this.jobManagerRef = AkkaUtils.getActorRef(
getJobManagerAkkaURL(deadline.timeLeft()),
actorSystem,
deadline.timeLeft());
return jobManagerRef;
}
catch (Throwable ignored) {
// Retry
Thread.sleep(Math.min(100, deadline.timeLeft().toMillis()));
}
}
throw new IllegalStateException("JobManager did not start up within " + timeout + ".");
}
示例8: waitForTaskManagers
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Waits for a minimum number of task managers to connect to the job manager.
*
* @param minimumNumberOfTaskManagers Minimum number of task managers to wait for
* @param jobManager Job manager actor to ask
* @param timeout Timeout after which the operation fails
* @throws Exception If the task managers don't connection with the timeout.
*/
public static void waitForTaskManagers(
int minimumNumberOfTaskManagers,
ActorGateway jobManager,
FiniteDuration timeout) throws Exception {
checkArgument(minimumNumberOfTaskManagers >= 1);
checkNotNull(jobManager, "Job manager");
checkNotNull(timeout, "Timeout");
final Deadline deadline = timeout.fromNow();
while (deadline.hasTimeLeft()) {
Future<Object> ask = jobManager.ask(getRequestNumberRegisteredTaskManager(),
deadline.timeLeft());
Integer response = (Integer) Await.result(ask, deadline.timeLeft());
// All are connected. We are done.
if (response >= minimumNumberOfTaskManagers) {
return;
}
// Waiting for more... retry
else {
Thread.sleep(Math.min(100, deadline.timeLeft().toMillis()));
}
}
throw new IllegalStateException("Task managers not connected within deadline.");
}
示例9: executeValueQuery
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Retry a query for state for keys between 0 and {@link #maxParallelism} until
* <tt>expected</tt> equals the value of the result tuple's second field.
*/
private void executeValueQuery(
final Deadline deadline,
final QueryableStateClient client,
final JobID jobId,
final String queryableStateName,
final ValueStateDescriptor<Tuple2<Integer, Long>> stateDescriptor,
final long expected) throws Exception {
for (int key = 0; key < maxParallelism; key++) {
boolean success = false;
while (deadline.hasTimeLeft() && !success) {
CompletableFuture<ValueState<Tuple2<Integer, Long>>> future = getKvState(
deadline,
client,
jobId,
queryableStateName,
key,
BasicTypeInfo.INT_TYPE_INFO,
stateDescriptor,
false,
executor);
Tuple2<Integer, Long> value = future.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS).value();
assertEquals("Key mismatch", key, value.f0.intValue());
if (expected == value.f1) {
success = true;
} else {
// Retry
Thread.sleep(RETRY_TIMEOUT);
}
}
assertTrue("Did not succeed query", success);
}
}
示例10: executeValueQuery
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Retry a query for state for keys between 0 and {@link #maxParallelism} until
* <tt>expected</tt> equals the value of the result tuple's second field.
*/
private void executeValueQuery(
final Deadline deadline,
final QueryableStateClient client,
final JobID jobId,
final String queryableStateName,
final ValueStateDescriptor<Tuple2<Integer, Long>> stateDescriptor,
final long expected) throws Exception {
for (int key = 0; key < maxParallelism; key++) {
boolean success = false;
while (deadline.hasTimeLeft() && !success) {
CompletableFuture<ValueState<Tuple2<Integer, Long>>> future = getKvStateWithRetries(
client,
jobId,
queryableStateName,
key,
BasicTypeInfo.INT_TYPE_INFO,
stateDescriptor,
QUERY_RETRY_DELAY,
false,
executor);
Tuple2<Integer, Long> value = future.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS).value();
assertEquals("Key mismatch", key, value.f0.intValue());
if (expected == value.f1) {
success = true;
} else {
// Retry
Thread.sleep(50L);
}
}
assertTrue("Did not succeed query", success);
}
}
示例11: amqTopologyWithCheckpointing
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
@Test
public void amqTopologyWithCheckpointing() throws Exception {
ActiveMQConnectionFactory connectionFactory = createConnectionFactory();
AMQSinkConfig<String> sinkConfig = new AMQSinkConfig.AMQSinkConfigBuilder<String>()
.setConnectionFactory(connectionFactory)
.setDestinationName("queue2")
.setSerializationSchema(new SimpleStringSchema())
.build();
AMQSink<String> sink = new AMQSink<>(sinkConfig);
sink.open(new Configuration());
for (int i = 0; i < MESSAGES_NUM; i++) {
sink.invoke("amq-" + i);
}
AMQSourceConfig<String> sourceConfig = new AMQSourceConfig.AMQSourceConfigBuilder<String>()
.setConnectionFactory(connectionFactory)
.setDestinationName("queue2")
.setDeserializationSchema(new SimpleStringSchema())
.build();
final AMQSource<String> source = new AMQSource<>(sourceConfig);
RuntimeContext runtimeContext = createMockRuntimeContext();
source.setRuntimeContext(runtimeContext);
source.open(new Configuration());
final TestSourceContext sourceContext = new TestSourceContext();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
source.run(sourceContext);
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
Deadline deadline = FiniteDuration.apply(5, "s").fromNow();
while (deadline.hasTimeLeft() && sourceContext.getIdsNum() < MESSAGES_NUM) {
Thread.sleep(100);
Random random = new Random();
final long checkpointId = random.nextLong();
synchronized (sourceContext.getCheckpointLock()) {
source.snapshotState(new FunctionSnapshotContext() {
@Override
public long getCheckpointId() {
return checkpointId;
}
@Override
public long getCheckpointTimestamp() {
return System.currentTimeMillis();
}
});
source.notifyCheckpointComplete(checkpointId);
}
}
assertEquals(MESSAGES_NUM, sourceContext.getIdsNum());
}
示例12: executeValueQuery
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Retry a query for state for keys between 0 and {@link #NUM_SLOTS} until
* <tt>expected</tt> equals the value of the result tuple's second field.
*/
private void executeValueQuery(final Deadline deadline,
final QueryableStateClient client, final JobID jobId,
final QueryableStateStream<Integer, Tuple2<Integer, Long>> queryableState,
final long expected) throws Exception {
for (int key = 0; key < NUM_SLOTS; key++) {
final byte[] serializedKey = KvStateRequestSerializer.serializeKeyAndNamespace(
key,
queryableState.getKeySerializer(),
VoidNamespace.INSTANCE,
VoidNamespaceSerializer.INSTANCE);
boolean success = false;
while (deadline.hasTimeLeft() && !success) {
Future<byte[]> future = getKvStateWithRetries(client,
jobId,
queryableState.getQueryableStateName(),
key,
serializedKey,
QUERY_RETRY_DELAY,
false);
byte[] serializedValue = Await.result(future, deadline.timeLeft());
Tuple2<Integer, Long> value = KvStateRequestSerializer.deserializeValue(
serializedValue,
queryableState.getValueSerializer());
assertEquals("Key mismatch", key, value.f0.intValue());
if (expected == value.f1) {
success = true;
} else {
// Retry
Thread.sleep(50);
}
}
assertTrue("Did not succeed query", success);
}
}
示例13: testZooKeeperReelection
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Tests repeatedly the reelection of still available LeaderContender. After a contender has
* been elected as the leader, it is removed. This forces the ZooKeeperLeaderElectionService
* to elect a new leader.
*/
@Test
public void testZooKeeperReelection() throws Exception {
Deadline deadline = new FiniteDuration(5, TimeUnit.MINUTES).fromNow();
int num = 10;
ZooKeeperLeaderElectionService[] leaderElectionService = new ZooKeeperLeaderElectionService[num];
TestingContender[] contenders = new TestingContender[num];
ZooKeeperLeaderRetrievalService leaderRetrievalService = null;
TestingListener listener = new TestingListener();
try {
leaderRetrievalService = ZooKeeperUtils.createLeaderRetrievalService(client, configuration);
LOG.debug("Start leader retrieval service for the TestingListener.");
leaderRetrievalService.start(listener);
for (int i = 0; i < num; i++) {
leaderElectionService[i] = ZooKeeperUtils.createLeaderElectionService(client, configuration);
contenders[i] = new TestingContender(TEST_URL + "_" + i, leaderElectionService[i]);
LOG.debug("Start leader election service for contender #{}.", i);
leaderElectionService[i].start(contenders[i]);
}
String pattern = TEST_URL + "_" + "(\\d+)";
Pattern regex = Pattern.compile(pattern);
int numberSeenLeaders = 0;
while (deadline.hasTimeLeft() && numberSeenLeaders < num) {
LOG.debug("Wait for new leader #{}.", numberSeenLeaders);
String address = listener.waitForNewLeader(deadline.timeLeft().toMillis());
Matcher m = regex.matcher(address);
if (m.find()) {
int index = Integer.parseInt(m.group(1));
TestingContender contender = contenders[index];
// check that the retrieval service has retrieved the correct leader
if (address.equals(contender.getAddress()) && listener.getLeaderSessionID().equals(contender.getLeaderSessionID())) {
// kill the election service of the leader
LOG.debug("Stop leader election service of contender #{}.", numberSeenLeaders);
leaderElectionService[index].stop();
leaderElectionService[index] = null;
numberSeenLeaders++;
}
} else {
fail("Did not find the leader's index.");
}
}
assertFalse("Did not complete the leader reelection in time.", deadline.isOverdue());
assertEquals(num, numberSeenLeaders);
} finally {
if (leaderRetrievalService != null) {
leaderRetrievalService.stop();
}
for (ZooKeeperLeaderElectionService electionService : leaderElectionService) {
if (electionService != null) {
electionService.stop();
}
}
}
}
示例14: testJobClientRecovery
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
/**
* Tests whether the JobClientActor can connect to a newly elected leading job manager to obtain
* the JobExecutionResult. The submitted job blocks for the first execution attempt. The
* leading job manager will be killed so that the second job manager will be elected as the
* leader. The newly elected leader has to retrieve the checkpointed job from ZooKeeper
* and continue its execution. This time, the job does not block and, thus, can be finished.
* The execution result should be sent to the JobClientActor which originally submitted the
* job.
*
* @throws Exception
*/
@Test
public void testJobClientRecovery() throws Exception {
File rootFolder = tempFolder.getRoot();
Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig(
zkServer.getConnectString(),
rootFolder.getPath());
config.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, 2);
config.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, 1);
final TestingCluster cluster = new TestingCluster(config);
cluster.start();
JobVertex blockingVertex = new JobVertex("Blocking Vertex");
blockingVertex.setInvokableClass(BlockingTask.class);
blockingVertex.setParallelism(1);
final JobGraph jobGraph = new JobGraph("Blocking Test Job", blockingVertex);
final Promise<JobExecutionResult> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
Deadline deadline = new FiniteDuration(2, TimeUnit.MINUTES).fromNow();
try {
Thread submitter = new Thread(new Runnable() {
@Override
public void run() {
try {
JobExecutionResult result = cluster.submitJobAndWait(jobGraph, false);
promise.success(result);
} catch (Exception e) {
promise.failure(e);
}
}
});
submitter.start();
synchronized (BlockingTask.waitLock) {
while (BlockingTask.HasBlockedExecution < 1 && deadline.hasTimeLeft()) {
BlockingTask.waitLock.wait(deadline.timeLeft().toMillis());
}
}
if (deadline.isOverdue()) {
Assert.fail("The job has not blocked within the given deadline.");
}
ActorGateway gateway = cluster.getLeaderGateway(deadline.timeLeft());
gateway.tell(TestingJobManagerMessages.getDisablePostStop());
gateway.tell(PoisonPill.getInstance());
// if the job fails then an exception is thrown here
Await.result(promise.future(), deadline.timeLeft());
} finally {
cluster.stop();
}
}
示例15: testFailWhileRestarting
import scala.concurrent.duration.Deadline; //导入方法依赖的package包/类
@Test
public void testFailWhileRestarting() throws Exception {
Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
Instance instance = ExecutionGraphTestUtils.getInstance(
new ActorTaskManagerGateway(
new SimpleActorGateway(TestingUtils.directExecutionContext())),
NUM_TASKS);
scheduler.newInstanceAvailable(instance);
// Blocking program
ExecutionGraph executionGraph = new ExecutionGraph(
TestingUtils.defaultExecutor(),
TestingUtils.defaultExecutor(),
new JobID(),
"TestJob",
new Configuration(),
new SerializedValue<>(new ExecutionConfig()),
AkkaUtils.getDefaultTimeout(),
// We want to manually control the restart and delay
new InfiniteDelayRestartStrategy(),
scheduler);
JobVertex jobVertex = new JobVertex("NoOpInvokable");
jobVertex.setInvokableClass(NoOpInvokable.class);
jobVertex.setParallelism(NUM_TASKS);
JobGraph jobGraph = new JobGraph("TestJob", jobVertex);
executionGraph.attachJobGraph(jobGraph.getVerticesSortedTopologicallyFromSources());
assertEquals(JobStatus.CREATED, executionGraph.getState());
executionGraph.scheduleForExecution();
assertEquals(JobStatus.RUNNING, executionGraph.getState());
// Kill the instance and wait for the job to restart
instance.markDead();
Deadline deadline = TestingUtils.TESTING_DURATION().fromNow();
while (deadline.hasTimeLeft() &&
executionGraph.getState() != JobStatus.RESTARTING) {
Thread.sleep(100);
}
assertEquals(JobStatus.RESTARTING, executionGraph.getState());
// The restarting should not fail with an ordinary exception
executionGraph.failGlobal(new Exception("Test exception"));
assertEquals(JobStatus.RESTARTING, executionGraph.getState());
// but it should fail when sending a SuppressRestartsException
executionGraph.failGlobal(new SuppressRestartsException(new Exception("Test exception")));
assertEquals(JobStatus.FAILED, executionGraph.getState());
// The restart has been aborted
executionGraph.restart(executionGraph.getGlobalModVersion());
assertEquals(JobStatus.FAILED, executionGraph.getState());
}