use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.
the class AbstractClientConnectionTest method testSendRequestReceiveResponse.
@Test
public void testSendRequestReceiveResponse() throws Exception {
final Consumer<Response<?, ?>> callback = mock(Consumer.class);
final Request<?, ?> request = createRequest(replyToProbe.ref());
connection.sendRequest(request, callback);
final RequestEnvelope requestEnvelope = backendProbe.expectMsgClass(RequestEnvelope.class);
Assert.assertEquals(request, requestEnvelope.getMessage());
final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(CLIENT_ID, 0L);
final RequestSuccess<?, ?> message = new TransactionAbortSuccess(new TransactionIdentifier(historyId, 0L), 0L);
final ResponseEnvelope<?> envelope = new SuccessEnvelope(message, 0L, 0L, 0L);
connection.receiveResponse(envelope);
verify(callback, timeout(1000)).accept(isA(TransactionAbortSuccess.class));
}
use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.
the class ConnectedClientConnectionTest method testSendSliceableMessageRequest.
@SuppressWarnings("unchecked")
@Test
public void testSendSliceableMessageRequest() {
final ClientActorConfig config = AccessClientUtil.newMockClientActorConfig();
doReturn(5).when(config).getMaximumMessageSliceSize();
context = new ClientActorContext(contextProbe.ref(), PERSISTENCE_ID, system, CLIENT_ID, config);
connection = createConnection();
final Consumer<Response<?, ?>> callback = mock(Consumer.class);
final TransactionIdentifier identifier = new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_ID, 0L), 0L);
ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(identifier, replyToProbe.ref());
reqBuilder.addModification(new TransactionWrite(YangInstanceIdentifier.EMPTY, Builders.containerBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build()));
reqBuilder.setSequence(0L);
final Request<?, ?> request = reqBuilder.build();
connection.sendRequest(request, callback);
backendProbe.expectMsgClass(MessageSlice.class);
}
use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.
the class ClientBackedTransactionChainTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
final FrontendIdentifier frontendId = FrontendIdentifier.create(MemberName.forName("member"), FrontendType.forName("frontend"));
final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(clientId, 0);
final TransactionIdentifier transactionId = new TransactionIdentifier(historyId, 0);
Mockito.when(history.getIdentifier()).thenReturn(historyId);
Mockito.when(transaction.getIdentifier()).thenReturn(transactionId);
Mockito.when(snapshot.getIdentifier()).thenReturn(transactionId);
Mockito.when(history.takeSnapshot()).thenReturn(snapshot);
Mockito.when(history.createTransaction()).thenReturn(transaction);
chain = new ClientBackedTransactionChain(history, false);
}
use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier in project controller by opendaylight.
the class ShardSnapshotCohort method create.
static ShardSnapshotCohort create(final ActorContext actorContext, final MemberName memberName, final ShardDataTree store, final Logger log, final String logId) {
final LocalHistoryIdentifier applyHistoryId = new LocalHistoryIdentifier(ClientIdentifier.create(FrontendIdentifier.create(memberName, SNAPSHOT_APPLY), 0), 0);
final String snapshotActorName = "shard-" + memberName.getName() + ':' + "snapshot-read";
// Create a snapshot actor. This actor will act as a worker to offload snapshot serialization for all
// requests.
final ActorRef snapshotActor = actorContext.actorOf(ShardSnapshotActor.props(), snapshotActorName);
return new ShardSnapshotCohort(applyHistoryId, snapshotActor, store, log, logId);
}
use of org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier 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