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%2FShardTransactionFailureTest.java;h=8fa72b0f81962e409c8827475541580b6f2729ed;hp=5781c19b252717c24c1795d83131ea6c158bcf32;hb=d594cf3be29ab746695eb5a3b0d220be89b57566;hpb=621ad520d61103e0e5c19cff5a1b00bdd11db86f 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 5781c19b25..8fa72b0f81 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,11 +1,9 @@ /* + * 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; @@ -14,19 +12,14 @@ import akka.actor.ActorRef; import akka.actor.Props; import akka.pattern.AskTimeoutException; import akka.testkit.TestActorRef; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; import java.util.Collections; import java.util.concurrent.TimeUnit; -import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; -import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer; 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.data.api.YangInstanceIdentifier; @@ -42,15 +35,13 @@ import scala.concurrent.duration.Duration; * @author Basheeruddin Ahmed */ public class ShardTransactionFailureTest extends AbstractActorTest { - private static ListeningExecutorService storeExecutor = - MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); - - private static final InMemoryDOMDataStore store = - new InMemoryDOMDataStore("OPER", storeExecutor, - MoreExecutors.sameThreadExecutor()); - private static final SchemaContext testSchemaContext = - TestModel.createTestContext(); + TestModel.createTestContext(); + private static final TransactionType RO = TransactionType.READ_ONLY; + private static final TransactionType RW = TransactionType.READ_WRITE; + private static final TransactionType WO = TransactionType.WRITE_ONLY; + + private static final ShardDataTree store = new ShardDataTree(testSchemaContext); private static final ShardIdentifier SHARD_IDENTIFIER = ShardIdentifier.builder().memberName("member-1") @@ -60,13 +51,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { private final ShardStats shardStats = new ShardStats(SHARD_IDENTIFIER.toString(), "DataStore"); - @BeforeClass - public static void staticSetup() { - store.onGlobalContextUpdated(testSchemaContext); - } - private ActorRef createShard(){ - return getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.emptyMap(), datastoreContext, + return getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.emptyMap(), datastoreContext, TestModel.createTestContext())); } @@ -75,9 +61,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { throws Throwable { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newReadOnlyTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(RO, store.newReadOnlyTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -93,7 +78,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { akka.pattern.Patterns.ask(subject, readData, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); - subject.underlyingActor().getDOMStoreTransaction().close(); + subject.underlyingActor().getDOMStoreTransaction().abort(); future = akka.pattern.Patterns.ask(subject, readData, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); @@ -105,9 +90,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { throws Throwable { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(RW, store.newReadWriteTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -124,7 +108,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { akka.pattern.Patterns.ask(subject, readData, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); - subject.underlyingActor().getDOMStoreTransaction().close(); + subject.underlyingActor().getDOMStoreTransaction().abort(); future = akka.pattern.Patterns.ask(subject, readData, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); @@ -135,9 +119,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { throws Throwable { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(RW, store.newReadWriteTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -154,7 +137,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { akka.pattern.Patterns.ask(subject, dataExists, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); - subject.underlyingActor().getDOMStoreTransaction().close(); + subject.underlyingActor().getDOMStoreTransaction().abort(); future = akka.pattern.Patterns.ask(subject, dataExists, 3000); Await.result(future, Duration.create(3, TimeUnit.SECONDS)); @@ -165,9 +148,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newWriteOnlyTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(WO, store.newReadWriteTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -198,9 +180,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(RW, store.newReadWriteTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -226,7 +207,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest { Await.result(future, Duration.create(3, TimeUnit.SECONDS)); } - private NormalizedNodeMessages.Node buildNormalizedNode() { + private static NormalizedNodeMessages.Node buildNormalizedNode() { return NormalizedNodeSerializer .serialize(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).build()); } @@ -236,9 +217,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(RW, store.newReadWriteTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props, "testNegativeMergeTransactionReady"); @@ -269,9 +249,8 @@ public class ShardTransactionFailureTest extends AbstractActorTest { final ActorRef shard = createShard(); - final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard, - testSchemaContext, datastoreContext, shardStats, "txn", - CreateTransaction.CURRENT_VERSION); + final Props props = ShardTransaction.props(RW, store.newReadWriteTransaction("test-txn", null), shard, + datastoreContext, shardStats, "txn", DataStoreVersions.CURRENT_VERSION); final TestActorRef subject = TestActorRef .create(getSystem(), props,