private State waitForServiceCompletion(TestRequestSender sender, URI taskUri) { Set<TaskStage> finalStages = EnumSet.of(TaskStage.CANCELLED, TaskStage.FAILED, TaskStage.FINISHED); Duration waitDuration = Duration.ofSeconds(this.taskWaitSeconds); AtomicReference<State> stateHolder = new AtomicReference<>(); TestContext.waitFor(waitDuration, () -> { State state = sender.sendAndWait(Operation.createGet(taskUri), State.class); stateHolder.set(state); return finalStages.contains(state.taskInfo.stage); }, () -> "Timeout while waiting migration task to finish"); return stateHolder.get(); }
private State waitForServiceCompletion(TestRequestSender sender, URI taskUri) { Set<TaskStage> finalStages = EnumSet.of(TaskStage.CANCELLED, TaskStage.FAILED, TaskStage.FINISHED); Duration waitDuration = Duration.ofSeconds(this.taskWaitSeconds); AtomicReference<State> stateHolder = new AtomicReference<>(); TestContext.waitFor(waitDuration, () -> { State state = sender.sendAndWait(Operation.createGet(taskUri), State.class); stateHolder.set(state); return finalStages.contains(state.taskInfo.stage); }, () -> "Timeout while waiting migration task to finish"); return stateHolder.get(); }
public static void waitFor(Duration waitDuration, WaitHandler wh, String timeoutMessage) { waitFor(new WaitConfig().setDuration(waitDuration), wh, () -> timeoutMessage); }
public static void waitFor(Duration waitDuration, WaitHandler wh, String timeoutMessage) { waitFor(new WaitConfig().setDuration(waitDuration), wh, () -> timeoutMessage); }
public static void waitFor(Duration waitDuration, WaitHandler wh, Supplier<String> timeoutMessageSupplier) { waitFor(new WaitConfig().setDuration(waitDuration), wh, timeoutMessageSupplier); }
public static void waitFor(Duration waitDuration, WaitHandler wh) { waitFor(new WaitConfig().setDuration(waitDuration), wh, () -> "waitFor timed out"); }
public static void waitFor(Duration waitDuration, WaitHandler wh) { waitFor(new WaitConfig().setDuration(waitDuration), wh, () -> "waitFor timed out"); }
public static void waitFor(Duration waitDuration, WaitHandler wh, Supplier<String> timeoutMessageSupplier) { waitFor(new WaitConfig().setDuration(waitDuration), wh, timeoutMessageSupplier); }
private NodeGroupMigrationState postNodeGroupMigrationTaskAndWaitFinish(NodeGroupMigrationState requestBody) { VerificationHost destNode = this.destNodes.iterator().next(); TestRequestSender sender = destNode.getTestRequestSender(); Operation post = Operation.createPost(destNode, NodeGroupMigrationTaskService.FACTORY_LINK).setBody(requestBody); NodeGroupMigrationState response = sender.sendAndWait(post, NodeGroupMigrationState.class); String taskPath = response.documentSelfLink; Set<TaskStage> finalStages = EnumSet.of(TaskStage.CANCELLED, TaskStage.FAILED, TaskStage.FINISHED); AtomicReference<NodeGroupMigrationState> state = new AtomicReference<>(); // when conversion check fails, migration task schedule next check with this interval. // To avoid timeout in test, set timeout longer than the interval. long waitSecond = TimeUnit.MICROSECONDS.toSeconds(MigrationTaskService.DEFAULT_MAINTENANCE_INTERVAL_MILLIS) * 2; TestContext.waitFor(Duration.ofSeconds(waitSecond), () -> { Operation get = Operation.createGet(destNode, taskPath); NodeGroupMigrationState result = sender.sendAndWait(get, NodeGroupMigrationState.class); state.set(result); if (result.taskInfo == null) { // it is possible that taskinfo is not yet ready return false; } return finalStages.contains(result.taskInfo.stage); }, "waiting for MigrationService To Finish" ); return state.get(); }
waitFor(this.timeout, () -> { List<NodeGroupState> nodeGroupStates = getNodeGroupStates();
waitFor(this.timeout, () -> { List<NodeGroupState> nodeGroupStates = getNodeGroupStates();
body.key = factoryServicePath; waitFor(this.timeout, () -> {
body.key = factoryServicePath; waitFor(this.timeout, () -> {
waitFor(this.timeout, () -> { List<NodeGroupState> nodeGroupStates = getNodeGroupStates(); return nodeGroupStates.stream()
waitFor(this.timeout, () -> { List<NodeGroupState> nodeGroupStates = getNodeGroupStates(); return nodeGroupStates.stream()
TestContext.waitFor(s.getTimeout(), () -> { QueryTask queryTaskResponse = s.sendGetAndWait(queryTaskURI, QueryTask.class);
TestContext.waitFor(s.getTimeout(), () -> { QueryTask queryTaskResponse = s.sendGetAndWait(queryTaskURI, QueryTask.class);
@Test public void create() throws Throwable { ServiceHost h = ServiceHost.create("--port=0"); try { h.start(); h.startDefaultCoreServicesSynchronously(); // Start the example service factory h.startFactory(ExampleService.class, ExampleService::createFactory); boolean[] isReady = new boolean[1]; h.registerForServiceAvailability((o, e) -> { isReady[0] = true; }, ExampleService.FACTORY_LINK); Duration timeout = Duration.of(ServiceHost.ServiceHostState.DEFAULT_MAINTENANCE_INTERVAL_MICROS * 5, ChronoUnit.MICROS); TestContext.waitFor(timeout, () -> { return isReady[0]; }, "ExampleService did not start"); // verify ExampleService exists TestRequestSender sender = new TestRequestSender(h); Operation get = Operation.createGet(h, ExampleService.FACTORY_LINK); sender.sendAndWait(get); } finally { if (h != null) { h.unregisterRuntimeShutdownHook(); h.stop(); } } }
@Test public void create() throws Throwable { ServiceHost h = ServiceHost.create("--port=0"); try { h.start(); h.startDefaultCoreServicesSynchronously(); // Start the example service factory h.startFactory(ExampleService.class, ExampleService::createFactory); boolean[] isReady = new boolean[1]; h.registerForServiceAvailability((o, e) -> { isReady[0] = true; }, ExampleService.FACTORY_LINK); Duration timeout = Duration.of(ServiceHost.ServiceHostState.DEFAULT_MAINTENANCE_INTERVAL_MICROS * 5, ChronoUnit.MICROS); TestContext.waitFor(timeout, () -> { return isReady[0]; }, "ExampleService did not start"); // verify ExampleService exists TestRequestSender sender = new TestRequestSender(h); Operation get = Operation.createGet(h, ExampleService.FACTORY_LINK); sender.sendAndWait(get); } finally { if (h != null) { h.unregisterRuntimeShutdownHook(); h.stop(); } } }