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=72d47711da6da82afb273df07365bc403ad29d05;hb=4f1f2ae598588f6aa5aac59b2206d97ad402a193;hp=8338e7083ab4a64f1c8e7883bdeeec60934a35b5;hpb=c8accd29069c3e7e874949e71ae1518371e660f0;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 8338e7083a..72d47711da 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 @@ -11,7 +11,6 @@ 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; @@ -21,14 +20,15 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; 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; +import java.util.function.Function; import org.junit.Assert; import org.junit.Test; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; import org.opendaylight.controller.cluster.datastore.modification.WriteModification; import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; @@ -42,52 +42,49 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import scala.concurrent.Promise; public class TransactionChainProxyTest extends AbstractTransactionProxyTest { + private LocalHistoryIdentifier historyId; + + @Override + public void setUp() { + super.setUp(); + historyId = MockIdentifiers.historyIdentifier(TransactionChainProxyTest.class, memberName); + } @SuppressWarnings("resource") @Test - public void testNewReadOnlyTransaction() throws Exception { + public void testNewReadOnlyTransaction() { - DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newReadOnlyTransaction(); + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newReadOnlyTransaction(); Assert.assertTrue(dst instanceof DOMStoreReadTransaction); } @SuppressWarnings("resource") @Test - public void testNewReadWriteTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newReadWriteTransaction(); + public void testNewReadWriteTransaction() { + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newReadWriteTransaction(); Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction); } @SuppressWarnings("resource") @Test - public void testNewWriteOnlyTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newWriteOnlyTransaction(); + public void testNewWriteOnlyTransaction() { + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newWriteOnlyTransaction(); Assert.assertTrue(dst instanceof DOMStoreWriteTransaction); } @Test - public void testClose() throws Exception { - new TransactionChainProxy(mockComponentFactory).close(); - - verify(mockActorContext, times(1)).broadcast(anyObject()); - } + public void testClose() { + new TransactionChainProxy(mockComponentFactory, historyId).close(); - @Test - public void testTransactionChainsHaveUniqueId() { - try (TransactionChainProxy one = new TransactionChainProxy(mockComponentFactory)) { - try (TransactionChainProxy two = new TransactionChainProxy(mockComponentFactory)) { - - Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId()); - } - } + verify(mockActorContext, times(1)).broadcast(any(Function.class), any(Class.class)); } @Test public void testRateLimitingUsedInReadWriteTxCreation() { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { txChainProxy.newReadWriteTransaction(); @@ -97,7 +94,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testRateLimitingUsedInWriteOnlyTxCreation() { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { txChainProxy.newWriteOnlyTransaction(); @@ -107,7 +104,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testRateLimitingNotUsedInReadOnlyTxCreation() { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { txChainProxy.newReadOnlyTransaction(); @@ -123,13 +120,13 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { public void testChainedWriteOnlyTransactions() throws Exception { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { ActorRef txActorRef1 = setupActorContextWithoutInitialCreateTransaction(getSystem()); Promise batchedReplyPromise1 = akka.dispatch.Futures.promise(); doReturn(batchedReplyPromise1.future()).when(mockActorContext).executeOperationAsync( - eq(actorSelection(txActorRef1)), isA(BatchedModifications.class)); + eq(actorSelection(txActorRef1)), isA(BatchedModifications.class), any(Timeout.class)); DOMStoreWriteTransaction writeTx1 = txChainProxy.newWriteOnlyTransaction(); @@ -191,7 +188,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { */ @Test public void testChainedReadWriteTransactions() throws Exception { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { ActorRef txActorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); @@ -199,7 +196,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { Promise readyReplyPromise1 = akka.dispatch.Futures.promise(); doReturn(readyReplyPromise1.future()).when(mockActorContext).executeOperationAsync( - eq(actorSelection(txActorRef1)), isA(BatchedModifications.class)); + eq(actorSelection(txActorRef1)), isA(BatchedModifications.class), any(Timeout.class)); DOMStoreWriteTransaction writeTx1 = txChainProxy.newReadWriteTransaction(); @@ -259,12 +256,12 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { } @Test(expected = IllegalStateException.class) - public void testChainedWriteTransactionsWithPreviousTxNotReady() throws Exception { + public void testChainedWriteTransactionsWithPreviousTxNotReady() { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); expectBatchedModifications(actorRef, 1); - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { DOMStoreWriteTransaction writeTx1 = txChainProxy.newWriteOnlyTransaction();