List of usage examples for java.util.concurrent CompletableFuture completedFuture
public static <U> CompletableFuture<U> completedFuture(U value)
From source file:com.spotify.styx.api.BackfillResource.java
private CompletionStage<Boolean> haltActiveBackfillInstance(WorkflowInstance workflowInstance, Client client) { try {//www .j a va 2 s .c o m final ByteString payload = serialize(Event.halt(workflowInstance)); final Request request = Request.forUri(schedulerApiUrl("events"), "POST").withPayload(payload); return client.send(request).thenApply(response -> response.status().family().equals(SUCCESSFUL)); } catch (JsonProcessingException e) { return CompletableFuture.completedFuture(false); } }
From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java
@Override public ManagementFuture<Long> countObjects() { //(add 1 so can tell the difference!) return FutureUtils .createManagementFuture(CompletableFuture.completedFuture(1L + (long) _mutable_values.size())); }
From source file:com.ikanow.aleph2.management_db.services.DataBucketStatusCrudService.java
@Override public ManagementFuture<Supplier<Object>> storeObject(DataBucketStatusBean new_object, boolean replace_if_present) { if (replace_if_present) { throw new RuntimeException("This method is not supported, call update instead"); }//from w w w . ja va 2s .c om // Check - has to have an _id and bucket_path if ((null == new_object._id()) || (null == new_object.bucket_path()) || (null == new_object.suspended())) { return FutureUtils.createManagementFuture(FutureUtils .returnError(new RuntimeException(ErrorUtils.get(ManagementDbErrorUtils.ILLEGAL_STATUS_CREATION, new_object._id() + "|" + new_object.bucket_path() + "|" + new_object.suspended())))); } // Assuming the store works, then check the bucket final CompletableFuture<Supplier<Object>> ret_val = _underlying_data_bucket_status_db.get() .storeObject(new_object); return FutureUtils.createManagementFuture(ret_val, CompletableFuture.completedFuture(Collections.<BasicMessageBean>emptyList())); }
From source file:com.ikanow.aleph2.shared.crud.mongodb.services.MongoDbCrudService.java
@Override public CompletableFuture<Supplier<Object>> storeObject(final O new_object, final boolean replace_if_present) { try {//ww w . ja v a2s . com final DBObject dbo = convertToBson(new_object); @SuppressWarnings("unused") final com.mongodb.WriteResult result = (replace_if_present) ? _state.orig_coll.save(dbo) : _state.orig_coll.insert(dbo); return CompletableFuture.completedFuture(() -> dbo.get(_ID)); } catch (Exception e) { return FutureUtils.<Supplier<Object>>returnError(e); } }
From source file:com.ikanow.aleph2.harvest.logstash.services.LogstashHarvestService.java
@Override public CompletableFuture<BasicMessageBean> onPurge(DataBucketBean to_purge, IHarvestContext context) { final LogstashBucketConfigBean config = Optionals.ofNullable(to_purge.harvest_configs()).stream() .findFirst().map(cfg -> BeanTemplateUtils.from(cfg.config(), LogstashBucketConfigBean.class).get()) .orElse(BeanTemplateUtils.build(LogstashBucketConfigBean.class).done().get()); resetFilePointer(to_purge, config, _globals.get()); return CompletableFuture.completedFuture( ErrorUtils.buildMessage(true, this.getClass().getSimpleName(), "onPurge", "(done)")); }
From source file:io.pravega.service.server.host.ZKSegmentContainerMonitorTest.java
@Test public void testRetryOnStartFailures() throws Exception { @Cleanup//from www . j a va2s .com CuratorFramework zkClient = startClient(); initializeHostContainerMapping(zkClient); SegmentContainerRegistry containerRegistry = createMockContainerRegistry(); @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient); segMonitor.initialize(Duration.ofSeconds(1)); // Simulate a container that fails to start. CompletableFuture<ContainerHandle> failedFuture = FutureHelpers.failedFuture(new RuntimeException()); when(containerRegistry.startContainer(eq(2), any())).thenReturn(failedFuture); // Use ZK to send that information to the Container Manager. HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH); currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2)); zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData)); // Verify that it does not start. verify(containerRegistry, timeout(10000).atLeastOnce()).startContainer(eq(2), any()); assertEquals(0, segMonitor.getRegisteredContainers().size()); // Now simulate success for the same container. ContainerHandle containerHandle = mock(ContainerHandle.class); when(containerHandle.getContainerId()).thenReturn(2); when(containerRegistry.startContainer(eq(2), any())) .thenReturn(CompletableFuture.completedFuture(containerHandle)); // Verify that it retries and starts the same container again. verify(containerRegistry, timeout(10000).atLeastOnce()).startContainer(eq(2), any()); Thread.sleep(2000); assertEquals(1, segMonitor.getRegisteredContainers().size()); }
From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java
@Override public ManagementFuture<Boolean> updateObjectById(Object id, UpdateComponent<T> update) { return FutureUtils.createManagementFuture(CompletableFuture.completedFuture(null != id)); }
From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerMonitorTest.java
@Test public void testRetryOnStartFailures() throws Exception { @Cleanup/*w w w. j a v a2 s . c o m*/ CuratorFramework zkClient = startClient(); initializeHostContainerMapping(zkClient); SegmentContainerRegistry containerRegistry = createMockContainerRegistry(); @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient); segMonitor.initialize(Duration.ofSeconds(1)); // Simulate a container that fails to start. CompletableFuture<ContainerHandle> failedFuture = FutureHelpers.failedFuture(new RuntimeException()); when(containerRegistry.startContainer(eq(2), any())).thenReturn(failedFuture); // Use ZK to send that information to the Container Manager. HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH); currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2)); zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData)); // Verify that it does not start. verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any()); assertEquals(0, segMonitor.getRegisteredContainers().size()); // Now simulate success for the same container. ContainerHandle containerHandle = mock(ContainerHandle.class); when(containerHandle.getContainerId()).thenReturn(2); when(containerRegistry.startContainer(eq(2), any())) .thenReturn(CompletableFuture.completedFuture(containerHandle)); // Verify that it retries and starts the same container again. verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any()); Thread.sleep(2000); assertEquals(1, segMonitor.getRegisteredContainers().size()); }
From source file:io.pravega.client.stream.mock.MockController.java
@Override public CompletableFuture<StreamSegments> getCurrentSegments(String scope, String stream) { return CompletableFuture.completedFuture(getCurrentSegments(new StreamImpl(scope, stream))); }