use of org.opendaylight.controller.cluster.datastore.messages.CreateTransaction in project controller by opendaylight.
the class ShardTest method testCreateTransaction.
@Test
public void testCreateTransaction() {
new ShardTestKit(getSystem()) {
{
final ActorRef shard = actorFactory.createActor(newShardProps(), "testCreateTransaction");
waitUntilLeader(shard);
shard.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shard.tell(new CreateTransaction(nextTransactionId(), TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
final CreateTransactionReply reply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
final String path = reply.getTransactionPath().toString();
assertTrue("Unexpected transaction path " + path, path.startsWith(String.format("akka://test/user/testCreateTransaction/shard-%s-%s:ShardTransactionTest@0:", shardID.getShardName(), shardID.getMemberName().getName())));
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.CreateTransaction in project controller by opendaylight.
the class ShardTest method testCreateTransactionOnChain.
@Test
public void testCreateTransactionOnChain() {
new ShardTestKit(getSystem()) {
{
final ActorRef shard = actorFactory.createActor(newShardProps(), "testCreateTransactionOnChain");
waitUntilLeader(shard);
shard.tell(new CreateTransaction(nextTransactionId(), TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
final CreateTransactionReply reply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
final String path = reply.getTransactionPath().toString();
assertTrue("Unexpected transaction path " + path, path.startsWith(String.format("akka://test/user/testCreateTransactionOnChain/shard-%s-%s:ShardTransactionTest@0:", shardID.getShardName(), shardID.getMemberName().getName())));
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.CreateTransaction in project controller by opendaylight.
the class RemoteTransactionContextSupport method tryCreateTransaction.
/**
* Performs a CreateTransaction try async.
*/
private void tryCreateTransaction() {
LOG.debug("Tx {} Primary shard {} found - trying create transaction", getIdentifier(), primaryShardInfo.getPrimaryShardActor());
Object serializedCreateMessage = new CreateTransaction(getIdentifier(), getTransactionType().ordinal(), primaryShardInfo.getPrimaryShardVersion()).toSerializable();
Future<Object> createTxFuture = getActorContext().executeOperationAsync(primaryShardInfo.getPrimaryShardActor(), serializedCreateMessage, createTxMessageTimeout);
createTxFuture.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
onCreateTransactionComplete(failure, response);
}
}, getActorContext().getClientDispatcher());
}
use of org.opendaylight.controller.cluster.datastore.messages.CreateTransaction in project controller by opendaylight.
the class ShardTest method testBatchedModificationsOnTransactionChain.
@Test
public void testBatchedModificationsOnTransactionChain() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsOnTransactionChain");
waitUntilLeader(shard);
final LocalHistoryIdentifier historyId = nextHistoryId();
final TransactionIdentifier transactionID1 = new TransactionIdentifier(historyId, 0);
final TransactionIdentifier transactionID2 = new TransactionIdentifier(historyId, 1);
final FiniteDuration duration = duration("5 seconds");
// Send a BatchedModifications to start a chained write
// transaction and ready it.
final ContainerNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
final YangInstanceIdentifier path = TestModel.TEST_PATH;
shard.tell(newBatchedModifications(transactionID1, path, containerNode, true, false, 1), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// Create a read Tx on the same chain.
shard.tell(new CreateTransaction(transactionID2, TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
final CreateTransactionReply createReply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
getSystem().actorSelection(createReply.getTransactionPath()).tell(new ReadData(path, DataStoreVersions.CURRENT_VERSION), getRef());
final ReadDataReply readReply = expectMsgClass(duration("3 seconds"), ReadDataReply.class);
assertEquals("Read node", containerNode, readReply.getNormalizedNode());
// Commit the write transaction.
shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(duration, CanCommitTransactionReply.class));
assertEquals("Can commit", true, canCommitReply.getCanCommit());
shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CommitTransactionReply.class);
// Verify data in the data store.
final NormalizedNode<?, ?> actualNode = readStore(shard, path);
assertEquals("Stored node", containerNode, actualNode);
}
};
}
Aggregations