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


Java SettableFuture.get方法代码示例

本文整理汇总了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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:DeleteNestedAugmentationListenParentTest.java

示例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];
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:27,代码来源:TestBatch.java

示例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);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:26,代码来源:CacheTasksTest.java

示例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);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:24,代码来源:GitHubGitProviderTest.java

示例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);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:27,代码来源:LazyCookbookRecipeSourceTest.java

示例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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:WildcardedDataChangeListenerTest.java

示例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);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:9,代码来源:TestWithNetworkConnections.java

示例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];
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:28,代码来源:TestRedis.java

示例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];
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:39,代码来源:TestVirtualMachine.java

示例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);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:35,代码来源:InstallExistingTasksTest.java

示例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());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:31,代码来源:WriteParentListenAugmentTest.java

示例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;
    }
}
 
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:14,代码来源:AuxProxyMessageSender.java

示例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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:30,代码来源:WildcardedDataChangeListenerTest.java

示例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));
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:39,代码来源:ConfigIntegrationTest.java

示例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));
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:38,代码来源:RemoteConfigLongPollServiceTest.java


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