X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FTransactionChainProxyTest.java;h=874556c0ec3ecc13520072765b0550cb4fad85b4;hb=5273c33b6f2051a7e3b1afcc4eeae4e457b6f26c;hp=026b5490288c1bbdeb1ec44d37e998abddad813e;hpb=a54ec60368110d22794602343c934902f6833c65;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java index 026b549028..874556c0ec 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java @@ -1,29 +1,28 @@ /* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. * - * Copyright (c) 2014 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 - * + * 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.anyObject; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; 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 static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.READ_WRITE; -import static org.opendaylight.controller.cluster.datastore.TransactionProxy.TransactionType.WRITE_ONLY; +import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE; +import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY; import akka.actor.ActorRef; +import akka.util.Timeout; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -32,7 +31,6 @@ import org.junit.Test; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; import org.opendaylight.controller.cluster.datastore.modification.WriteModification; import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; -import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -48,7 +46,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testNewReadOnlyTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockActorContext).newReadOnlyTransaction(); + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newReadOnlyTransaction(); Assert.assertTrue(dst instanceof DOMStoreReadTransaction); } @@ -56,7 +54,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @SuppressWarnings("resource") @Test public void testNewReadWriteTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockActorContext).newReadWriteTransaction(); + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newReadWriteTransaction(); Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction); } @@ -64,29 +62,29 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @SuppressWarnings("resource") @Test public void testNewWriteOnlyTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockActorContext).newWriteOnlyTransaction(); + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newWriteOnlyTransaction(); Assert.assertTrue(dst instanceof DOMStoreWriteTransaction); } @Test public void testClose() throws Exception { - new TransactionChainProxy(mockActorContext).close(); + new TransactionChainProxy(mockComponentFactory).close(); verify(mockActorContext, times(1)).broadcast(anyObject()); } @Test public void testTransactionChainsHaveUniqueId(){ - TransactionChainProxy one = new TransactionChainProxy(mock(ActorContext.class)); - TransactionChainProxy two = new TransactionChainProxy(mock(ActorContext.class)); + TransactionChainProxy one = new TransactionChainProxy(mockComponentFactory); + TransactionChainProxy two = new TransactionChainProxy(mockComponentFactory); Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId()); } @Test public void testRateLimitingUsedInReadWriteTxCreation(){ - TransactionChainProxy txChainProxy = new TransactionChainProxy(mockActorContext); + TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory); txChainProxy.newReadWriteTransaction(); @@ -95,7 +93,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testRateLimitingUsedInWriteOnlyTxCreation(){ - TransactionChainProxy txChainProxy = new TransactionChainProxy(mockActorContext); + TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory); txChainProxy.newWriteOnlyTransaction(); @@ -105,7 +103,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testRateLimitingNotUsedInReadOnlyTxCreation(){ - TransactionChainProxy txChainProxy = new TransactionChainProxy(mockActorContext); + TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory); txChainProxy.newReadOnlyTransaction(); @@ -120,7 +118,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { public void testChainedWriteOnlyTransactions() throws Exception { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); - TransactionChainProxy txChainProxy = new TransactionChainProxy(mockActorContext); + TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory); ActorRef txActorRef1 = setupActorContextWithoutInitialCreateTransaction(getSystem()); @@ -186,7 +184,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { */ @Test public void testChainedReadWriteTransactions() throws Exception { - TransactionChainProxy txChainProxy = new TransactionChainProxy(mockActorContext); + TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory); ActorRef txActorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); @@ -205,8 +203,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { verifyOneBatchedModification(txActorRef1, new WriteModification(TestModel.TEST_PATH, writeNode1), true); - String tx2MemberName = "tx2MemberName"; - doReturn(tx2MemberName).when(mockActorContext).getCurrentMemberName(); + String tx2MemberName = "mock-member"; ActorRef shardActorRef2 = setupActorContextWithoutInitialCreateTransaction(getSystem()); ActorRef txActorRef2 = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE, DataStoreVersions.CURRENT_VERSION, tx2MemberName, shardActorRef2); @@ -248,7 +245,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { readyReplyPromise1.success(readyTxReply(txActorRef1.path().toString()).value().get().get()); verify(mockActorContext, timeout(5000)).executeOperationAsync(eq(getSystem().actorSelection(shardActorRef2.path())), - eqCreateTransaction(tx2MemberName, READ_WRITE)); + eqCreateTransaction(tx2MemberName, READ_WRITE), any(Timeout.class)); } @Test(expected=IllegalStateException.class) @@ -257,7 +254,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { expectBatchedModifications(actorRef, 1); - TransactionChainProxy txChainProxy = new TransactionChainProxy(mockActorContext); + TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory); DOMStoreWriteTransaction writeTx1 = txChainProxy.newWriteOnlyTransaction();