X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FThreePhaseCommitCohortProxyTest.java;h=8b5665244a6493414feeca9f58e11b45613dd2f5;hp=0a2a0d1bc0595a8932f2e2ee3ab27c6b8f422855;hb=ecccb6d5b43dd73aef0d2d19349d19ee9b4728f7;hpb=64db87e8fb5de25e68ba824ec2eaa17e3f217c96 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java index 0a2a0d1bc0..8b5665244a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java @@ -1,13 +1,18 @@ +/* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import akka.actor.ActorPath; @@ -39,6 +44,7 @@ import org.opendaylight.controller.cluster.datastore.messages.SerializableMessag import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor; import scala.concurrent.Future; +import scala.concurrent.duration.Duration; public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @@ -68,11 +74,15 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { doReturn(getSystem()).when(actorContext).getActorSystem(); doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher(); doReturn(datastoreContext).when(actorContext).getDatastoreContext(); - doReturn(100).when(datastoreContext).getShardTransactionCommitTimeoutInSeconds(); + doReturn(30).when(datastoreContext).getShardTransactionCommitTimeoutInSeconds(); doReturn(commitTimer).when(actorContext).getOperationTimer("commit"); doReturn(commitTimerContext).when(commitTimer).time(); doReturn(commitSnapshot).when(commitTimer).getSnapshot(); - doReturn(TimeUnit.MILLISECONDS.toNanos(2000) * 1.0).when(commitSnapshot).get95thPercentile(); + for(int i=1;i<11;i++){ + // Keep on increasing the amount of time it takes to complete transaction for each tenth of a + // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on. + doReturn(TimeUnit.MILLISECONDS.toNanos(i) * 1D).when(commitSnapshot).getValue(i * 0.1); + } doReturn(10.0).when(actorContext).getTxCreationLimit(); } @@ -113,6 +123,9 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { stubber.when(actorContext).executeOperationAsync(any(ActorSelection.class), isA(requestType), any(Timeout.class)); + + doReturn(new Timeout(Duration.apply(1000, TimeUnit.MILLISECONDS))) + .when(actorContext).getTransactionCommitOperationTimeout(); } private void verifyCohortInvocations(int nCohorts, Class requestType) { @@ -120,7 +133,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { any(ActorSelection.class), isA(requestType), any(Timeout.class)); } - private void propagateExecutionExceptionCause(ListenableFuture future) throws Throwable { + private static void propagateExecutionExceptionCause(ListenableFuture future) throws Throwable { try { future.get(5, TimeUnit.SECONDS); @@ -177,9 +190,11 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { ListenableFuture future = proxy.canCommit(); - assertEquals("canCommit", false, future.get(5, TimeUnit.SECONDS)); + Boolean actual = future.get(5, TimeUnit.SECONDS); + + assertEquals("canCommit", false, actual); - verifyCohortInvocations(3, CanCommitTransaction.SERIALIZABLE_CLASS); + verifyCohortInvocations(2, CanCommitTransaction.SERIALIZABLE_CLASS); } @Test(expected = TestException.class) @@ -303,7 +318,6 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { propagateExecutionExceptionCause(proxy.commit()); } finally { - verify(actorContext, never()).setTxCreationLimit(anyLong()); verifyCohortInvocations(0, CommitTransaction.SERIALIZABLE_CLASS); } @@ -332,8 +346,6 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { verifyCohortInvocations(2, CanCommitTransaction.SERIALIZABLE_CLASS); verifyCohortInvocations(2, CommitTransaction.SERIALIZABLE_CLASS); - // Verify that the creation limit was changed to 0.5 (based on setup) - verify(actorContext, timeout(5000)).setTxCreationLimit(0.5); } @Test @@ -347,6 +359,5 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { proxy.preCommit().get(5, TimeUnit.SECONDS); proxy.commit().get(5, TimeUnit.SECONDS); - verify(actorContext, never()).setTxCreationLimit(anyLong()); } }