use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.
the class EntityOwnershipShardCommitCoordinator method newBatchedModifications.
private BatchedModifications newBatchedModifications() {
BatchedModifications modifications = new BatchedModifications(new TransactionIdentifier(historyId, ++transactionIDCounter), DataStoreVersions.CURRENT_VERSION);
modifications.setDoCommitOnReady(true);
modifications.setReady(true);
modifications.setTotalMessagesSent(1);
return modifications;
}
use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.
the class ShardTest method testOnBatchedModificationsWhenNotLeader.
@Test
public void testOnBatchedModificationsWhenNotLeader() {
final AtomicBoolean overrideLeaderCalls = new AtomicBoolean();
new ShardTestKit(getSystem()) {
{
final Creator<Shard> creator = new Creator<Shard>() {
private static final long serialVersionUID = 1L;
@Override
public Shard create() throws Exception {
return new Shard(newShardBuilder()) {
@Override
protected boolean isLeader() {
return overrideLeaderCalls.get() ? false : super.isLeader();
}
@Override
public ActorSelection getLeader() {
return overrideLeaderCalls.get() ? getSystem().actorSelection(getRef().path()) : super.getLeader();
}
};
}
};
final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testOnBatchedModificationsWhenNotLeader");
waitUntilLeader(shard);
overrideLeaderCalls.set(true);
final BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
shard.tell(batched, ActorRef.noSender());
expectMsgEquals(batched);
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.
the class ShardTest method testBatchedModificationsReadyWithIncorrectTotalMessageCount.
@Test(expected = IllegalStateException.class)
public void testBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsReadyWithIncorrectTotalMessageCount");
waitUntilLeader(shard);
final TransactionIdentifier transactionID = nextTransactionId();
final BatchedModifications batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
shard.tell(batched, getRef());
final Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
if (failure != null) {
Throwables.propagateIfPossible(failure.cause(), Exception.class);
throw new RuntimeException(failure.cause());
}
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount.
@Test(expected = IllegalStateException.class)
public void testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
if (failure != null) {
Throwables.throwIfInstanceOf(failure.cause(), Exception.class);
Throwables.throwIfUnchecked(failure.cause());
throw new RuntimeException(failure.cause());
}
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.BatchedModifications in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithImmediateCommit.
@Test
public void testOnReceiveBatchedModificationsReadyWithImmediateCommit() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithImmediateCommit");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
batched.setReady(true);
batched.setDoCommitOnReady(true);
batched.setTotalMessagesSent(1);
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), CommitTransactionReply.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
}
};
}
Aggregations