本文整理汇总了Java中com.google.common.util.concurrent.SettableFuture.get方法的典型用法代码示例。如果您正苦于以下问题:Java SettableFuture.get方法的具体用法?Java SettableFuture.get怎么用?Java SettableFuture.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.SettableFuture
的用法示例。
在下文中一共展示了SettableFuture.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteChildListenParent
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void deleteChildListenParent() throws InterruptedException, ExecutionException, TimeoutException {
DataBroker dataBroker = testContext.getDataBroker();
final WriteTransaction initTx = dataBroker.newWriteOnlyTransaction();
initTx.put(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, createList11(), true);
initTx.submit().get(5, TimeUnit.SECONDS);
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, LIST11_PATH,
change -> event.set(change), DataChangeScope.SUBTREE);
final WriteTransaction deleteTx = dataBroker.newWriteOnlyTransaction();
deleteTx.delete(LogicalDatastoreType.OPERATIONAL, LIST11_PATH.augmentation(List11SimpleAugment.class));
deleteTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get();
assertFalse(receivedEvent.getRemovedPaths().contains(TLL_COMPLEX_AUGMENT_PATH));
}
示例2: createResource
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public BatchAccount createResource(BatchAccounts resources) throws Exception {
final String batchAccountName = "batch" + this.testId;
final BatchAccount[] batchAccounts = new BatchAccount[1];
final SettableFuture<BatchAccount> future = SettableFuture.create();
Observable<Indexable> resourceStream = resources.define(batchAccountName)
.withRegion(Region.INDIA_CENTRAL)
.withNewResourceGroup()
.withTag("mytag", "testtag")
.createAsync();
Utils.<BatchAccount>rootResource(resourceStream)
.subscribe(new Action1<BatchAccount>() {
@Override
public void call(BatchAccount batchAccount) {
future.set(batchAccount);
}
});
batchAccounts[0] = future.get();
Assert.assertNull(batchAccounts[0].autoStorage());
return batchAccounts[0];
}
示例3: downloadUsingCacheFailsWhenTheHashIsIncorrect
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void downloadUsingCacheFailsWhenTheHashIsIncorrect() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RemoteFile remoteFile = RemoteFile.of(
new URI("https://raw.githubusercontent.com/njlr/test-lib-a/3af013452fe6b448b1cb33bb81bb19da690ec764/BUCK"),
HashCode.fromString("aaaaaaaaaaaaaa4f244296b0fba7a70166dea49c9e8d3eacda58d67a"));
final Path cachePath = CacheTasks.getCachePath(fs, remoteFile);
final SettableFuture<Throwable> futureException = SettableFuture.create();
CacheTasks.downloadToCache(fs, remoteFile).subscribe(
next -> {},
error -> {
futureException.set(error);
},
() -> {});
final Throwable exception = futureException.get(5000L, TimeUnit.MILLISECONDS);
assertTrue(exception instanceof DownloadFileException);
assertTrue(exception.getCause() instanceof HashMismatchException);
}
示例4: fetchFailsWhenThereAreNoReleases
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void fetchFailsWhenThereAreNoReleases() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RecipeSource recipeSource = GitProviderRecipeSource.of(fs, GitHubGitProvider.of());
final Single<Recipe> task = recipeSource.fetch(
RecipeIdentifier.of("github", "njlr", "test-lib-no-releases"))
.result();
final SettableFuture<Throwable> futureException = SettableFuture.create();
task.subscribe(
result -> {
}, error -> {
futureException.set(error);
});
final Throwable exception = futureException.get(90, TimeUnit.SECONDS);
assertTrue(exception instanceof RecipeFetchException);
}
示例5: givesInformativeParseErrors
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void givesInformativeParseErrors() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
EvenMoreFiles.writeFile(
fs.getPath(System.getProperty("user.home"), ".buckaroo", "buckaroo-recipes", "recipes", "org", "example.json"),
"{ \"content\": \"this is an invalid recipe\" }");
final RecipeSource recipeSource = LazyCookbookRecipeSource.of(
fs.getPath(System.getProperty("user.home"), ".buckaroo", "buckaroo-recipes"));
final SettableFuture<Throwable> futureError = SettableFuture.create();
recipeSource.fetch(RecipeIdentifier.of(Identifier.of("org"), Identifier.of("example")))
.result()
.subscribe(x -> {
}, error -> {
futureError.set(error);
});
final Throwable exception = futureError.get(5000L, TimeUnit.MILLISECONDS);
assertTrue(exception instanceof RecipeFetchException);
}
示例6: testSeparateWrites
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void testSeparateWrites() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture =
SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH,
dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
validateEvent(event);
}
示例7: outboundPingAndWait
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
private void outboundPingAndWait(final InboundMessageQueuer p, long nonce) throws Exception {
// Send a ping and wait for it to get to the other side
SettableFuture<Void> pingReceivedFuture = SettableFuture.create();
p.mapPingFutures.put(nonce, pingReceivedFuture);
p.peer.sendMessage(new Ping(nonce));
pingReceivedFuture.get();
p.mapPingFutures.remove(nonce);
}
示例8: createResource
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public RedisCache createResource(RedisCaches resources) throws Exception {
final String redisName = "redis" + this.testId;
final RedisCache[] redisCaches = new RedisCache[1];
final SettableFuture<RedisCache> future = SettableFuture.create();
Observable<Indexable> resourceStream = resources.define(redisName)
.withRegion(Region.US_EAST)
.withNewResourceGroup()
.withStandardSku()
.withTag("mytag", "testtag")
.createAsync();
Utils.<RedisCache>rootResource(resourceStream)
.subscribe(new Action1<RedisCache>() {
@Override
public void call(RedisCache redisCache) {
future.set(redisCache);
}
});
redisCaches[0] = future.get();
Assert.assertEquals(redisCaches[0].name(), redisName);
return redisCaches[0];
}
示例9: createResource
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
final VirtualMachine[] vms = new VirtualMachine[1];
final SettableFuture<VirtualMachine> future = SettableFuture.create();
Observable<Indexable> resourceStream = virtualMachines.define(vmName)
.withRegion(Region.US_EAST)
.withNewResourceGroup()
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER)
.withAdminUsername("testuser")
.withAdminPassword("12NewPA$$w0rd!")
.withNewDataDisk(150)
.withSize(VirtualMachineSizeTypes.STANDARD_D1_V2)
.createAsync();
Utils.<VirtualMachine>rootResource(resourceStream)
.subscribe(new Action1<VirtualMachine>() {
@Override
public void call(VirtualMachine virtualMachine) {
future.set(virtualMachine);
}
});
vms[0] = future.get();
Assert.assertEquals(1, vms[0].dataDisks().size());
VirtualMachineDataDisk dataDisk = vms[0].dataDisks().values().iterator().next();
Assert.assertEquals(150, dataDisk.size());
Assert.assertEquals(128, vms[0].osDiskSize());
Disk osDisk = virtualMachines.manager().disks().getById(vms[0].osDiskId());
Assert.assertNotNull(osDisk);
Assert.assertEquals(128, osDisk.sizeInGB());
return vms[0];
}
示例10: failsGracefullyForIncorrectHashes
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void failsGracefullyForIncorrectHashes() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final DependencyLocks locks = DependencyLocks.of(ImmutableList.of(
DependencyLock.of(
RecipeIdentifier.of("loopperfect", "valuable"),
ResolvedDependency.of(Either.right(
RemoteArchive.of(
new URI("https://github.com/LoopPerfect/valuable/archive/v0.1.0.zip"),
HashCode.fromString("aaaaaaaaaaaaaaaaaaaaaaa71dd4a1fd3400f1d04b84954beb2f514ec69934c0"),
"valuable-0.1.0"))))));
EvenMoreFiles.writeFile(fs.getPath("buckaroo.json"), Serializers.serialize(Project.of()));
EvenMoreFiles.writeFile(fs.getPath("buckaroo.lock.json"), Serializers.serialize(locks));
final SettableFuture<Throwable> futureException = SettableFuture.create();
InstallExistingTasks.installExistingDependenciesInWorkingDirectory(fs)
.subscribe(
next -> {
}, error -> {
futureException.set(error);
}, () -> {
});
final Throwable exception = futureException.get(5000L, TimeUnit.MILLISECONDS);
assertTrue(exception instanceof DownloadFileException);
assertTrue(exception.getCause() instanceof HashMismatchException);
}
示例11: writeNodeListenAugment
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void writeNodeListenAugment() throws Exception {
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
DataBroker dataBroker = testContext.getDataBroker();
ListenerRegistration<org.opendaylight.controller.md.sal.binding.api.DataChangeListener> dclRegistration =
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, AUGMENT_WILDCARDED_PATH,
change -> event.set(change), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
TopLevelList tll = new TopLevelListBuilder() //
.setKey(TLL_KEY) //
.addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build();
transaction.put(LogicalDatastoreType.OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
assertTrue(receivedEvent.getCreatedData().containsKey(AUGMENT_TLL_PATH));
dclRegistration.close();
final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
transaction2.put(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
transaction2.submit().get(5, TimeUnit.SECONDS);
TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(
LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH).checkedGet(5, TimeUnit.SECONDS).get();
assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
}
示例12: emitEvent
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
public synchronized <T extends GenericOutcome> T emitEvent(Message message,
Ack ack,
SettableFuture<T> future,
T genericError) {
socket.emit(message.getDescriptorForType().getFullName(), ack, message.toByteArray());
try {
return future.get(30, TimeUnit.SECONDS);
} catch (Throwable e) {
genericError.setError(new GameLiftError(genericError.getError().getErrorType(), e));
return genericError;
}
}
示例13: testNoChangeOnReplaceWithSameValue
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
// We wrote initial state NODE_0_FLOW
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
// We registered DataChangeListener
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture =
SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH,
dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
assertFalse(eventFuture.isDone());
final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
secondTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
assertNotNull(event);
// Data change should contains NODE_1 Flow - which was added
assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
// Data change must not containe NODE_0 Flow which was replaced with same value.
assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
示例14: testLongPollRefresh
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void testLongPollRefresh() throws Exception {
final String someKey = "someKey";
final String someValue = "someValue";
final String anotherValue = "anotherValue";
long someNotificationId = 1;
long pollTimeoutInMS = 50;
Map<String, String> configurations = Maps.newHashMap();
configurations.put(someKey, someValue);
ApolloConfig apolloConfig = assembleApolloConfig(configurations);
ContextHandler configHandler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
ContextHandler pollHandler =
mockPollNotificationHandler(pollTimeoutInMS, HttpServletResponse.SC_OK,
Lists.newArrayList(
new ApolloConfigNotification(apolloConfig.getNamespaceName(), someNotificationId)),
false);
startServerWithHandlers(configHandler, pollHandler);
Config config = ConfigService.getAppConfig();
assertEquals(someValue, config.getProperty(someKey, null));
final SettableFuture<Boolean> longPollFinished = SettableFuture.create();
config.addChangeListener(new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
longPollFinished.set(true);
}
});
apolloConfig.getConfigurations().put(someKey, anotherValue);
longPollFinished.get(pollTimeoutInMS * 20, TimeUnit.MILLISECONDS);
assertEquals(anotherValue, config.getProperty(someKey, null));
}
示例15: testSubmitLongPollNamespaceWith304Response
import com.google.common.util.concurrent.SettableFuture; //导入方法依赖的package包/类
@Test
public void testSubmitLongPollNamespaceWith304Response() throws Exception {
RemoteConfigRepository someRepository = mock(RemoteConfigRepository.class);
final String someNamespace = "someNamespace";
when(pollResponse.getStatusCode()).thenReturn(HttpServletResponse.SC_NOT_MODIFIED);
final SettableFuture<Boolean> longPollFinished = SettableFuture.create();
doAnswer(new Answer<HttpResponse<List<ApolloConfigNotification>>>() {
@Override
public HttpResponse<List<ApolloConfigNotification>> answer(InvocationOnMock invocation)
throws Throwable {
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException e) {
}
HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
assertTrue(request.getUrl().contains(someServerUrl + "/notifications/v2?"));
assertTrue(request.getUrl().contains("appId=" + someAppId));
assertTrue(request.getUrl().contains("cluster=" + someCluster));
assertTrue(request.getUrl().contains("notifications="));
assertTrue(request.getUrl().contains(someNamespace));
longPollFinished.set(true);
return pollResponse;
}
}).when(httpUtil).doGet(any(HttpRequest.class), eq(responseType));
remoteConfigLongPollService.submit(someNamespace, someRepository);
longPollFinished.get(5000, TimeUnit.MILLISECONDS);
remoteConfigLongPollService.stopLongPollingRefresh();
verify(someRepository, never()).onLongPollNotified(any(ServiceDTO.class), any(ApolloNotificationMessages.class));
}