import akka.testkit.TestActorRef;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
-import org.junit.Assert;
import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
+import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
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 java.util.Collections;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Covers negative test cases
+ *
* @author Basheeruddin Ahmed <syedbahm@cisco.com>
*/
public class ShardTransactionFailureTest extends AbstractActorTest {
private static final SchemaContext testSchemaContext =
TestModel.createTestContext();
+ private static final ShardIdentifier SHARD_IDENTIFIER =
+ ShardIdentifier.builder().memberName("member-1")
+ .shardName("inventory").type("operational").build();
+
static {
store.onGlobalContextUpdated(testSchemaContext);
}
- @Test
- public void testNegativePerformingWriteOperationOnReadTransaction()
- throws Exception {
- try {
-
- final ActorRef
- shard = getSystem()
- .actorOf(Shard.props("config", Collections.EMPTY_MAP));
- final Props props =
- ShardTransaction
- .props(store.newReadOnlyTransaction(), shard, TestModel
- .createTestContext());
- final TestActorRef subject = TestActorRef.apply(props, getSystem());
-
- subject
- .receive(new DeleteData(TestModel.TEST_PATH).toSerializable(),
- ActorRef.noSender());
- Assert.assertFalse(true);
-
-
- } catch (Exception cs) {
- assertEquals(cs.getClass().getSimpleName(),
- Exception.class.getSimpleName());
- assertTrue(cs.getMessage().startsWith(
- "ShardTransaction:handleRecieve received an unknown message"));
- }
- }
-
@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadOnlyTransactionClosed()
throws Throwable {
final ActorRef shard =
- getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP));
+ getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, null));
final Props props =
ShardTransaction.props(store.newReadOnlyTransaction(), shard,
TestModel.createTestContext());
throws Throwable {
final ActorRef shard =
- getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP));
+ getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null));
final Props props =
ShardTransaction.props(store.newReadWriteTransaction(), shard,
TestModel.createTestContext());
}
+ @Test(expected = ReadFailedException.class)
+ public void testNegativeExistsWithReadWriteOnlyTransactionClosed()
+ 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<ShardTransaction> subject = TestActorRef
+ .create(getSystem(), props,
+ "testNegativeExistsWithReadWriteOnlyTransactionClosed");
+
+ ShardTransactionMessages.DataExists dataExists =
+ ShardTransactionMessages.DataExists.newBuilder()
+ .setInstanceIdentifierPathArguments(
+ NormalizedNodeMessages.InstanceIdentifier.newBuilder()
+ .build()
+ ).build();
+
+ Future<Object> 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());
+
+
+ }
@Test(expected = IllegalStateException.class)
public void testNegativeWriteWithTransactionReady() throws Exception {
final ActorRef shard =
- getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP));
+ getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null));
final Props props =
ShardTransaction.props(store.newWriteOnlyTransaction(), shard,
TestModel.createTestContext());
final ActorRef shard =
- getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP));
+ getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null));
final Props props =
ShardTransaction.props(store.newReadWriteTransaction(), shard,
TestModel.createTestContext());
final ActorRef shard =
- getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP));
+ getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null));
final Props props =
ShardTransaction.props(store.newReadWriteTransaction(), shard,
TestModel.createTestContext());
final ActorRef shard =
- getSystem().actorOf(Shard.props("config", Collections.EMPTY_MAP));
+ getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null));
final Props props =
ShardTransaction.props(store.newReadWriteTransaction(), shard,
TestModel.createTestContext());