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


Java CheckedFuture.checkedGet方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.CheckedFuture.checkedGet方法的典型用法代码示例。如果您正苦于以下问题:Java CheckedFuture.checkedGet方法的具体用法?Java CheckedFuture.checkedGet怎么用?Java CheckedFuture.checkedGet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.CheckedFuture的用法示例。


在下文中一共展示了CheckedFuture.checkedGet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCheckedGetThrowsApplicationExceptionOnCancellation

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
/**
 * Tests that the {@link CheckedFuture#checkedGet()} method throws the correct
 * type of cancellation exception when it is cancelled.
 */
public void testCheckedGetThrowsApplicationExceptionOnCancellation() {

  final CheckedFuture<Boolean, ?> future =
      createCheckedFuture(Boolean.TRUE, null, latch);

  assertFalse(future.isDone());
  assertFalse(future.isCancelled());

  new Thread(new Runnable() {
    @Override
    public void run() {
      future.cancel(true);
    }
  }).start();

  try {
    future.checkedGet();
    fail("RPC Should have been cancelled.");
  } catch (Exception e) {
    checkCancelledException(e);
  }

  assertTrue(future.isDone());
  assertTrue(future.isCancelled());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:30,代码来源:AbstractCheckedFutureTest.java

示例2: testCheckedGetThrowsApplicationExceptionOnError

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
public void testCheckedGetThrowsApplicationExceptionOnError() {
  final CheckedFuture<Boolean, ?> future =
      createCheckedFuture(Boolean.TRUE, new Exception("Error"), latch);

  assertFalse(future.isDone());
  assertFalse(future.isCancelled());

  new Thread(new Runnable() {
    @Override
    public void run() {
      latch.countDown();
    }
  }).start();

  try {
    future.checkedGet();
    fail();
  } catch (Exception e) {
    checkExecutionException(e);
  }

  assertTrue(future.isDone());
  assertFalse(future.isCancelled());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:AbstractCheckedFutureTest.java

示例3: readFromGreetingRegistry

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
private String readFromGreetingRegistry(HelloWorldInput input) {
    String result = "Hello " + input.getName();
    ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
    InstanceIdentifier<GreetingRegistryEntry> iid = toInstanceIdentifier(input);
    CheckedFuture<Optional<GreetingRegistryEntry>, ReadFailedException> future =
            transaction.read(LogicalDatastoreType.CONFIGURATION, iid);
    Optional<GreetingRegistryEntry> optional = Optional.absent();
    try {
        optional = future.checkedGet();
    } catch (ReadFailedException e) {
        LOG.warn("Reading greeting failed:",e);
    }
    if(optional.isPresent()) {
        result = optional.get().getGreeting();
    }
    return result;
}
 
开发者ID:lrodrin,项目名称:opendaylight,代码行数:18,代码来源:HelloProvider.java

示例4: testBasicProducer

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
/**
 * A simple unbound producer. It write some basic things into the data store based on the
 * test model.
 * @throws DOMDataTreeProducerException
 * @throws TransactionCommitFailedException
 */
@Test
public final void testBasicProducer() throws DOMDataTreeProducerException, TransactionCommitFailedException {
    // Create a producer. It is an AutoCloseable resource, hence the try-with pattern
    try (final DOMDataTreeProducer prod = service().createProducer(Collections.singleton(UNORDERED_CONTAINER_TREE))) {
        assertNotNull(prod);

        final DOMDataWriteTransaction tx = prod.createTransaction(true);
        assertNotNull(tx);

        tx.put(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID, ImmutableContainerNodeBuilder.create().build());

        final CheckedFuture<Void, TransactionCommitFailedException> f = tx.submit();
        assertNotNull(f);

        f.checkedGet();
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:AbstractDOMDataTreeServiceTestSuite.java

示例5: getModuleSource

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
@Override
public String getModuleSource(final org.opendaylight.yangtools.yang.model.api.ModuleIdentifier moduleIdentifier) {
    final CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source = this.sourceProvider
            .getSource(SourceIdentifier.create(moduleIdentifier.getName(),
                    Optional.fromNullable(QName.formattedRevision(moduleIdentifier.getRevision()))));

    try {
        final YangTextSchemaSource yangTextSchemaSource = source.checkedGet();
        try (InputStream inStream = yangTextSchemaSource.openStream()) {
            return new String(ByteStreams.toByteArray(inStream), StandardCharsets.UTF_8);
        }
    } catch (SchemaSourceException | IOException e) {
        LOG.warn("Unable to provide source for {}", moduleIdentifier, e);
        throw new IllegalArgumentException("Unable to provide source for " + moduleIdentifier, e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:YangStoreSnapshot.java

示例6: testInvokeRpcWithRemoteFailedFuture

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
/**
 * This test method invokes and executes the remote rpc.
 */
@Test(expected = DOMRpcException.class)
public void testInvokeRpcWithRemoteFailedFuture() throws Exception {
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    @SuppressWarnings({"unchecked", "rawtypes"})
    final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
            (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);

    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
            Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new RemoteDOMRpcException(
                    "Test Exception", null)));

    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture =
            remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:RemoteRpcImplementationTest.java

示例7: testInvokeRpc

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpc() throws Exception {
    final ContainerNode rpcOutput = makeRPCOutput("bar");
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);

    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    @SuppressWarnings({"unchecked", "rawtypes"})
    final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
            (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);

    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
            Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));

    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture =
            remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);

    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertEquals(rpcOutput, result.getResult());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:RemoteRpcImplementationTest.java

示例8: testCheckedGetThrowsApplicationExceptionOnInterruption

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
public void testCheckedGetThrowsApplicationExceptionOnInterruption()
    throws InterruptedException {

  final CheckedFuture<Boolean, ?> future =
      createCheckedFuture(Boolean.TRUE, null, latch);

  final CountDownLatch startingGate = new CountDownLatch(1);
  final CountDownLatch successLatch = new CountDownLatch(1);

  assertFalse(future.isDone());
  assertFalse(future.isCancelled());

  Thread getThread = new Thread(new Runnable() {
    @Override
    public void run() {
      startingGate.countDown();

      try {
        future.checkedGet();
      } catch (Exception e) {
        checkInterruptedException(e);

        // This only gets hit if the original call throws an exception and
        // the check call above passes.
        successLatch.countDown();
      }
    }
  });
  getThread.start();

  assertTrue(startingGate.await(500, TimeUnit.MILLISECONDS));
  getThread.interrupt();

  assertTrue(successLatch.await(500, TimeUnit.MILLISECONDS));

  assertFalse(future.isDone());
  assertFalse(future.isCancelled());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:39,代码来源:AbstractCheckedFutureTest.java

示例9: validateGreetingRegistry

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
private void validateGreetingRegistry(String name) {
    InstanceIdentifier<GreetingRegistryEntry> iid = InstanceIdentifier.create(GreetingRegistry.class)
            .child(GreetingRegistryEntry.class, new GreetingRegistryEntryKey(name));
    DataBroker db = getSession().getSALService(DataBroker.class);
    ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
    CheckedFuture<Optional<GreetingRegistryEntry>, ReadFailedException> future =
            transaction.read(LogicalDatastoreType.OPERATIONAL, iid);
    Optional<GreetingRegistryEntry> optional = Optional.absent();
    try {
        optional = future.checkedGet();
    } catch (ReadFailedException e) {
        LOG.warn("Reading greeting failed:",e);
    }
    Assert.assertTrue(name + " not recorded in greeting registry",optional.isPresent());
}
 
开发者ID:lrodrin,项目名称:opendaylight,代码行数:16,代码来源:HelloIT.java

示例10: testInvokeRpcWithAkkaTimeoutException

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
/**
 * This test method invokes and tests exceptions when akka timeout occured
 * Currently ignored since this test with current config takes around 15 seconds to complete.
 */
@Ignore
@Test(expected = RemoteDOMRpcException.class)
public void testInvokeRpcWithAkkaTimeoutException() throws Exception {
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture =
            remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);

    frontEndFuture.checkedGet(20, TimeUnit.SECONDS);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:15,代码来源:RemoteRpcImplementationTest.java

示例11: getNonExistingSchemaSource

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
@Test(expected = SchemaSourceException.class)
public void getNonExistingSchemaSource() throws Exception {
    Futures.failed(new Exception("halo"));

    Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(
            Futures.failed(
                    new SchemaSourceException("Source not provided")));

    CheckedFuture<?, ?> sourceFuture = remoteSchemaProvider.getSource(ID);
    assertTrue(sourceFuture.isDone());
    sourceFuture.checkedGet();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:13,代码来源:RemoteSchemaProviderTest.java

示例12: testInvokeRpcWithLookupException

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
/**
 * This test method invokes remote rpc and lookup failed
 * with runtime exception.
 */
@Test(expected = DOMRpcException.class)
public void testInvokeRpcWithLookupException() throws Exception {
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");

    doThrow(new RuntimeException("test")).when(domRpcService2).invokeRpc(any(SchemaPath.class),
        any(NormalizedNode.class));

    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture =
            remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);

    frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:RemoteRpcImplementationTest.java

示例13: executeList

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();

    try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
        for (long l = 0; l < outerListElem; l++) {

            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
                    .child(OuterList.class, new OuterListKey((int) l));
            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture =
                    tx.read(dsType, iid);

            try {
                Optional<OuterList> optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    OuterList outerList = optionalDataObject.get();

                    String[] objectsArray = new String[outerList.getInnerList().size()];
                    for (InnerList innerList : outerList.getInnerList()) {
                        if (objectsArray[innerList.getName()] != null) {
                            LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
                                innerList.getValue());
                        }
                        objectsArray[innerList.getName()] = innerList.getValue();
                    }
                    for (int i = 0; i < outerList.getInnerList().size(); i++) {
                        String itemStr = objectsArray[i];
                        if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
                            LOG.error("innerList: name: {}, value: {}", i, itemStr);
                            break;
                        }
                    }
                    txOk++;
                } else {
                    txError++;
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:44,代码来源:TxchainBaRead.java

示例14: executeList

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();

    try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
        for (long l = 0; l < outerListElem; l++) {

            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
                    .child(OuterList.class, new OuterListKey((int)l));
            Optional<OuterList> optionalDataObject;
            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
            try {
                optionalDataObject = submitFuture.checkedGet();
                if (optionalDataObject != null && optionalDataObject.isPresent()) {
                    OuterList outerList = optionalDataObject.get();

                    String[] objectsArray = new String[outerList.getInnerList().size()];

                    for (InnerList innerList : outerList.getInnerList()) {
                        if (objectsArray[innerList.getName()] != null) {
                            LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
                                innerList.getValue());
                        }
                        objectsArray[innerList.getName()] = innerList.getValue();
                    }
                    for (int i = 0; i < outerList.getInnerList().size(); i++) {
                        String itemStr = objectsArray[i];
                        if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
                            LOG.error("innerList: name: {}, value: {}", i, itemStr);
                            break;
                        }
                    }
                    txOk++;
                } else {
                    txError++;
                }
            } catch (final ReadFailedException e) {
                LOG.warn("failed to ....", e);
                txError++;
            }
        }
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:44,代码来源:SimpletxBaRead.java

示例15: testCreateChainedTransactionsInQuickSuccession

import com.google.common.util.concurrent.CheckedFuture; //导入方法依赖的package包/类
@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(
                    testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {

                final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
                        ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
                                .put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
                        MoreExecutors.directExecutor());

                final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
                DOMTransactionChain txChain = broker.createTransactionChain(listener);

                final List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();

                final DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
                writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
                writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
                futures.add(writeTx.submit());

                int numCars = 100;
                for (int i = 0; i < numCars; i++) {
                    final DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();

                    rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i),
                            CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));

                    futures.add(rwTx.submit());
                }

                for (final CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
                    f.checkedGet();
                }

                final Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
                        .read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());

                txChain.close();

                broker.close();
            }
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:49,代码来源:DistributedDataStoreIntegrationTest.java


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