Search in sources :

Example 11 with LocalHistoryIdentifier

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));
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionAbortSuccess(org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess) SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Test(org.junit.Test)

Example 12 with LocalHistoryIdentifier

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);
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Test(org.junit.Test)

Example 13 with LocalHistoryIdentifier

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);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier) Before(org.junit.Before)

Example 14 with LocalHistoryIdentifier

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);
}
Also used : ActorRef(akka.actor.ActorRef) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)

Example 15 with LocalHistoryIdentifier

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);
        }
    };
}
Also used : CreateTransaction(org.opendaylight.controller.cluster.datastore.messages.CreateTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ReadDataReply(org.opendaylight.controller.cluster.datastore.messages.ReadDataReply) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Aggregations

LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)16 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)5 Test (org.junit.Test)4 LocalHistorySuccess (org.opendaylight.controller.cluster.access.commands.LocalHistorySuccess)3 Response (org.opendaylight.controller.cluster.access.concepts.Response)3 DeadHistoryException (org.opendaylight.controller.cluster.access.commands.DeadHistoryException)2 TransactionAbortSuccess (org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess)2 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)2 FrontendIdentifier (org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)2 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)2 ActorRef (akka.actor.ActorRef)1 HashMap (java.util.HashMap)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 GuardedBy (javax.annotation.concurrent.GuardedBy)1 Before (org.junit.Before)1 CreateLocalHistoryRequest (org.opendaylight.controller.cluster.access.commands.CreateLocalHistoryRequest)1 LocalHistoryRequest (org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest)1 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)1 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)1