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%2FShardTransactionFailureTest.java;h=1ca294db5846d5083e3dda09bfa0bee9bf8d858c;hb=HEAD;hp=16b73040a5b6e5375a24570fb5b1617240eadb04;hpb=57769930716e9e5a55336145998525d3392c0ed8;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java index 16b73040a5..7a96f263c6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java @@ -1,312 +1,129 @@ /* + * 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.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + import akka.actor.ActorRef; import akka.actor.Props; import akka.testkit.TestActorRef; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; +import java.util.concurrent.TimeUnit; +import org.junit.Before; import org.junit.Test; +import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; +import org.opendaylight.controller.cluster.datastore.messages.DataExists; +import org.opendaylight.controller.cluster.datastore.messages.ReadData; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; -import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages; -import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.mdsal.common.api.ReadFailedException; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.tree.api.TreeType; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import scala.concurrent.Await; import scala.concurrent.Future; -import scala.concurrent.duration.Duration; - -import java.util.Collections; - -import static org.junit.Assert.assertTrue; +import scala.concurrent.duration.FiniteDuration; /** - * Covers negative test cases + * Covers negative test cases. * - * @author Basheeruddin Ahmed + * @author Basheeruddin Ahmed */ +@Deprecated(since = "9.0.0", forRemoval = true) public class ShardTransactionFailureTest extends AbstractActorTest { - private static ListeningExecutorService storeExecutor = - MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); + private static final EffectiveModelContext TEST_SCHEMA_CONTEXT = TestModel.createTestContext(); + private static final TransactionType RO = TransactionType.READ_ONLY; + private static final TransactionType RW = TransactionType.READ_WRITE; - private static final InMemoryDOMDataStore store = - new InMemoryDOMDataStore("OPER", storeExecutor, - MoreExecutors.sameThreadExecutor()); + private static final Shard MOCK_SHARD = mock(Shard.class); - private static final SchemaContext testSchemaContext = - TestModel.createTestContext(); + private static final ShardDataTree STORE = new ShardDataTree(MOCK_SHARD, TEST_SCHEMA_CONTEXT, TreeType.OPERATIONAL); private static final ShardIdentifier SHARD_IDENTIFIER = - ShardIdentifier.builder().memberName("member-1") - .shardName("inventory").type("operational").build(); - - static { - store.onGlobalContextUpdated(testSchemaContext); - } + ShardIdentifier.create("inventory", MemberName.forName("member-1"), "operational"); + private final DatastoreContext datastoreContext = DatastoreContext.newBuilder().build(); - @Test(expected = ReadFailedException.class) - public void testNegativeReadWithReadOnlyTransactionClosed() - throws Throwable { - - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, null)); - final Props props = - ShardTransaction.props(store.newReadOnlyTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, - "testNegativeReadWithReadOnlyTransactionClosed"); - - ShardTransactionMessages.ReadData readData = - ShardTransactionMessages.ReadData.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build() - ).build(); - Future future = - akka.pattern.Patterns.ask(subject, readData, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); - - ((ShardReadTransaction) subject.underlyingActor()) - .forUnitTestOnlyExplicitTransactionClose(); - - future = akka.pattern.Patterns.ask(subject, readData, 3000); - Await.result(future, Duration.Zero()); - + private final ShardStats shardStats = new ShardStats(SHARD_IDENTIFIER.toString(), "DataStore", null); + private ActorRef createShard() { + ActorRef shard = getSystem().actorOf(Shard.builder().id(SHARD_IDENTIFIER).datastoreContext(datastoreContext) + .schemaContextProvider(() -> TEST_SCHEMA_CONTEXT).props()); + ShardTestKit.waitUntilLeader(shard); + return shard; } - - @Test(expected = ReadFailedException.class) - public void testNegativeReadWithReadWriteOnlyTransactionClosed() - throws Throwable { - - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); - final Props props = - ShardTransaction.props(store.newReadWriteTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, - "testNegativeReadWithReadWriteOnlyTransactionClosed"); - - ShardTransactionMessages.ReadData readData = - ShardTransactionMessages.ReadData.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build() - ).build(); - Future future = - akka.pattern.Patterns.ask(subject, readData, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); - - ((ShardReadWriteTransaction) subject.underlyingActor()) - .forUnitTestOnlyExplicitTransactionClose(); - - future = akka.pattern.Patterns.ask(subject, readData, 3000); - Await.result(future, Duration.Zero()); - - + @Before + public void setup() { + doReturn(new ShardStats("inventory", "mxBeanType", MOCK_SHARD)).when(MOCK_SHARD).getShardMBean(); } @Test(expected = ReadFailedException.class) - public void testNegativeExistsWithReadWriteOnlyTransactionClosed() - throws Throwable { + public void testNegativeReadWithReadOnlyTransactionClosed() throws Exception { - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); - final Props props = - ShardTransaction.props(store.newReadWriteTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, - "testNegativeExistsWithReadWriteOnlyTransactionClosed"); - - ShardTransactionMessages.DataExists dataExists = - ShardTransactionMessages.DataExists.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build() - ).build(); - - Future future = - akka.pattern.Patterns.ask(subject, dataExists, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); - - ((ShardReadWriteTransaction) subject.underlyingActor()) - .forUnitTestOnlyExplicitTransactionClose(); - - future = akka.pattern.Patterns.ask(subject, dataExists, 3000); - Await.result(future, Duration.Zero()); - - - } + final ActorRef shard = createShard(); + final Props props = ShardTransaction.props(RO, STORE.newReadOnlyTransaction(nextTransactionId()), shard, + datastoreContext, shardStats); - @Test(expected = IllegalStateException.class) - public void testNegativeWriteWithTransactionReady() throws Exception { - - - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); - final Props props = - ShardTransaction.props(store.newWriteOnlyTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, - "testNegativeWriteWithTransactionReady"); - - ShardTransactionMessages.ReadyTransaction readyTransaction = - ShardTransactionMessages.ReadyTransaction.newBuilder().build(); - - Future future = - akka.pattern.Patterns.ask(subject, readyTransaction, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); - - ShardTransactionMessages.WriteData writeData = - ShardTransactionMessages.WriteData.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build()).setNormalizedNode( - NormalizedNodeMessages.Node.newBuilder().build() - - ).build(); - - future = akka.pattern.Patterns.ask(subject, writeData, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); - - - } - - - @Test(expected = IllegalStateException.class) - public void testNegativeReadWriteWithTransactionReady() throws Exception { - - - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); - final Props props = - ShardTransaction.props(store.newReadWriteTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, - "testNegativeReadWriteWithTransactionReady"); - - ShardTransactionMessages.ReadyTransaction readyTransaction = - ShardTransactionMessages.ReadyTransaction.newBuilder().build(); - - Future future = - akka.pattern.Patterns.ask(subject, readyTransaction, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); - - ShardTransactionMessages.WriteData writeData = - ShardTransactionMessages.WriteData.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build()).setNormalizedNode( - NormalizedNodeMessages.Node.newBuilder().build() - - ).build(); + final TestActorRef subject = TestActorRef.create(getSystem(), props, + "testNegativeReadWithReadOnlyTransactionClosed"); - future = akka.pattern.Patterns.ask(subject, writeData, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); + Future future = akka.pattern.Patterns.ask(subject, + new ReadData(YangInstanceIdentifier.of(), DataStoreVersions.CURRENT_VERSION), 3000); + Await.result(future, FiniteDuration.create(3, TimeUnit.SECONDS)); + subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor(); + future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.of(), + DataStoreVersions.CURRENT_VERSION), 3000); + Await.result(future, FiniteDuration.create(3, TimeUnit.SECONDS)); } - @Test(expected = IllegalStateException.class) - public void testNegativeMergeTransactionReady() throws Exception { - - - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); - final Props props = - ShardTransaction.props(store.newReadWriteTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, "testNegativeMergeTransactionReady"); - ShardTransactionMessages.ReadyTransaction readyTransaction = - ShardTransactionMessages.ReadyTransaction.newBuilder().build(); - - Future future = - akka.pattern.Patterns.ask(subject, readyTransaction, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); + @Test(expected = ReadFailedException.class) + public void testNegativeReadWithReadWriteTransactionClosed() throws Exception { - ShardTransactionMessages.MergeData mergeData = - ShardTransactionMessages.MergeData.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build()).setNormalizedNode( - NormalizedNodeMessages.Node.newBuilder().build() + final ActorRef shard = createShard(); + final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard, + datastoreContext, shardStats); - ).build(); + final TestActorRef subject = TestActorRef.create(getSystem(), props, + "testNegativeReadWithReadWriteTransactionClosed"); - future = akka.pattern.Patterns.ask(subject, mergeData, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); + Future future = akka.pattern.Patterns.ask(subject, + new ReadData(YangInstanceIdentifier.of(), DataStoreVersions.CURRENT_VERSION), 3000); + Await.result(future, FiniteDuration.create(3, TimeUnit.SECONDS)); + subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor(); + future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.of(), + DataStoreVersions.CURRENT_VERSION), 3000); + Await.result(future, FiniteDuration.create(3, TimeUnit.SECONDS)); } + @Test(expected = ReadFailedException.class) + public void testNegativeExistsWithReadWriteTransactionClosed() throws Exception { - @Test(expected = IllegalStateException.class) - public void testNegativeDeleteDataWhenTransactionReady() throws Exception { - - - final ActorRef shard = - getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); - final Props props = - ShardTransaction.props(store.newReadWriteTransaction(), shard, - TestModel.createTestContext()); - - final TestActorRef subject = TestActorRef - .create(getSystem(), props, - "testNegativeDeleteDataWhenTransactionReady"); - - ShardTransactionMessages.ReadyTransaction readyTransaction = - ShardTransactionMessages.ReadyTransaction.newBuilder().build(); - - Future future = - akka.pattern.Patterns.ask(subject, readyTransaction, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); + final ActorRef shard = createShard(); + final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard, + datastoreContext, shardStats); - ShardTransactionMessages.DeleteData deleteData = - ShardTransactionMessages.DeleteData.newBuilder() - .setInstanceIdentifierPathArguments( - NormalizedNodeMessages.InstanceIdentifier.newBuilder() - .build()).build(); + final TestActorRef subject = TestActorRef.create(getSystem(), props, + "testNegativeExistsWithReadWriteTransactionClosed"); - future = akka.pattern.Patterns.ask(subject, deleteData, 3000); - assertTrue(future.isCompleted()); - Await.result(future, Duration.Zero()); + Future future = akka.pattern.Patterns.ask(subject, + new DataExists(YangInstanceIdentifier.of(), DataStoreVersions.CURRENT_VERSION), 3000); + Await.result(future, FiniteDuration.create(3, TimeUnit.SECONDS)); + subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor(); + future = akka.pattern.Patterns.ask(subject, + new DataExists(YangInstanceIdentifier.of(), DataStoreVersions.CURRENT_VERSION), 3000); + Await.result(future, FiniteDuration.create(3, TimeUnit.SECONDS)); } }