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


Java DefaultShardStrategy类代码示例

本文整理汇总了Java中org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy的典型用法代码示例。如果您正苦于以下问题:Java DefaultShardStrategy类的具体用法?Java DefaultShardStrategy怎么用?Java DefaultShardStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultShardStrategy类属于org.opendaylight.controller.cluster.datastore.shardstrategy包,在下文中一共展示了DefaultShardStrategy类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInvalidCreateTransactionReply

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testInvalidCreateTransactionReply() throws Exception {
    ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));

    doReturn(getSystem().actorSelection(actorRef.path())).when(mockActorContext)
            .actorSelection(actorRef.path().toString());

    doReturn(primaryShardInfoReply(getSystem(), actorRef)).when(mockActorContext)
            .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));

    doReturn(Futures.successful(new Object())).when(mockActorContext).executeOperationAsync(
        eq(getSystem().actorSelection(actorRef.path())), eqCreateTransaction(memberName, READ_ONLY),
        any(Timeout.class));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);

    propagateReadFailedExceptionCause(transactionProxy.read(TestModel.TEST_PATH));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:TransactionProxyTest.java

示例2: testReadyWithLocalTransaction

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
@Test
public void testReadyWithLocalTransaction() throws Exception {
    ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));

    doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext)
            .actorSelection(shardActorRef.path().toString());

    doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, createDataTree()))).when(mockActorContext)
            .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);

    expectReadyLocalTransaction(shardActorRef, true);

    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);

    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy)ready, new CommitTransactionReply().toSerializable());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:TransactionProxyTest.java

示例3: completeOperationLocal

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
private void completeOperationLocal(final TransactionProxyOperation operation, final DataTree dataTree) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));

    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext)
            .actorSelection(shardActorRef.path().toString());

    doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, dataTree))).when(mockActorContext)
            .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);

    long start = System.nanoTime();

    operation.run(transactionProxy);

    long end = System.nanoTime();

    long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext()
            .getOperationTimeoutInMillis());
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s", expected, end - start),
            end - start <= expected);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:TransactionProxyTest.java

示例4: completeOperation

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
private void completeOperation(final TransactionProxyOperation operation, final boolean shardFound) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));

    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext)
            .actorSelection(shardActorRef.path().toString());

    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext)
                .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    } else {
        doReturn(Futures.failed(new PrimaryNotFoundException("test"))).when(mockActorContext)
                .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }

    ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    String actorPath = txActorRef.path().toString();
    CreateTransactionReply createTransactionReply = new CreateTransactionReply(actorPath, nextTransactionId(),
            DataStoreVersions.CURRENT_VERSION);

    doReturn(actorSystem.actorSelection(actorPath)).when(mockActorContext).actorSelection(actorPath);

    doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).executeOperationAsync(
            eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE),
            any(Timeout.class));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);

    long start = System.nanoTime();

    operation.run(transactionProxy);

    long end = System.nanoTime();

    long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext()
            .getOperationTimeoutInMillis());
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
            expected, end - start), end - start <= expected);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:TransactionProxyTest.java

示例5: setupActorContextWithoutInitialCreateTransaction

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
protected ActorRef setupActorContextWithoutInitialCreateTransaction(final ActorSystem actorSystem) {
    return setupActorContextWithoutInitialCreateTransaction(actorSystem, DefaultShardStrategy.DEFAULT_SHARD);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:4,代码来源:AbstractTransactionProxyTest.java

示例6: setupActorContextWithInitialCreateTransaction

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
protected ActorRef setupActorContextWithInitialCreateTransaction(final ActorSystem actorSystem,
        final TransactionType type) {
    return setupActorContextWithInitialCreateTransaction(actorSystem, type, DataStoreVersions.CURRENT_VERSION,
            DefaultShardStrategy.DEFAULT_SHARD);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:6,代码来源:AbstractTransactionProxyTest.java

示例7: testWriteAfterAsyncRead

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testWriteAfterAsyncRead() throws Exception {
    ActorRef actorRef = setupActorContextWithoutInitialCreateTransaction(getSystem(),
            DefaultShardStrategy.DEFAULT_SHARD);

    Promise<Object> createTxPromise = akka.dispatch.Futures.promise();
    doReturn(createTxPromise).when(mockActorContext).executeOperationAsync(
            eq(getSystem().actorSelection(actorRef.path())),
            eqCreateTransaction(memberName, READ_WRITE), any(Timeout.class));

    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(
            eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));

    expectBatchedModificationsReady(actorRef);

    final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);

    final TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);

    final CountDownLatch readComplete = new CountDownLatch(1);
    final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
    com.google.common.util.concurrent.Futures.addCallback(transactionProxy.read(TestModel.TEST_PATH),
            new  FutureCallback<Optional<NormalizedNode<?, ?>>>() {
                @Override
                public void onSuccess(final Optional<NormalizedNode<?, ?>> result) {
                    try {
                        transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
                    } catch (Exception e) {
                        caughtEx.set(e);
                    } finally {
                        readComplete.countDown();
                    }
                }

                @Override
                public void onFailure(final Throwable failure) {
                    caughtEx.set(failure);
                    readComplete.countDown();
                }
            }, MoreExecutors.directExecutor());

    createTxPromise.success(createTransactionReply(actorRef, DataStoreVersions.CURRENT_VERSION));

    Uninterruptibles.awaitUninterruptibly(readComplete, 5, TimeUnit.SECONDS);

    final Throwable t = caughtEx.get();
    if (t != null) {
        Throwables.propagateIfPossible(t, Exception.class);
        throw new RuntimeException(t);
    }

    // This sends the batched modification.
    transactionProxy.ready();

    verifyOneBatchedModification(actorRef, new WriteModification(TestModel.TEST_PATH, nodeToWrite), true);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:58,代码来源:TransactionProxyTest.java

示例8: throttleOperation

import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; //导入依赖的package包/类
private void throttleOperation(final TransactionProxyOperation operation, final int outstandingOpsLimit,
        final boolean shardFound, final long expectedCompletionTime) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));

    // Note that we setting batchedModificationCount to one less than what we need because in TransactionProxy
    // we now allow one extra permit to be allowed for ready
    doReturn(dataStoreContextBuilder.operationTimeoutInSeconds(2)
            .shardBatchedModificationCount(outstandingOpsLimit - 1).build()).when(mockActorContext)
                    .getDatastoreContext();

    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext)
            .actorSelection(shardActorRef.path().toString());

    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext)
                .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext)
                .findPrimaryShardAsync(eq("cars"));

    } else {
        doReturn(Futures.failed(new Exception("not found")))
                .when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }

    doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
            eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE),
            any(Timeout.class));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);

    long start = System.nanoTime();

    operation.run(transactionProxy);

    long end = System.nanoTime();

    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
            expectedCompletionTime, end - start),
            end - start > expectedCompletionTime && end - start < expectedCompletionTime * 2);

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:43,代码来源:TransactionProxyTest.java


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