Search in sources :

Example 36 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier 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 37 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier 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 38 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.

@Test
public void testToAndFromBinary() throws NotSerializableException {
    DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
    MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
    new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
    TransactionIdentifier txId = nextTransactionId();
    ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
    final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
    final Object deserialized;
    try {
        final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
        final byte[] bytes = serializer.toBinary(readyMessage);
        deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
    } finally {
        JavaTestKit.shutdownActorSystem(system);
    }
    assertNotNull("fromBinary returned null", deserialized);
    assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
    BatchedModifications batched = (BatchedModifications) deserialized;
    assertEquals("getTransactionID", txId, batched.getTransactionId());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
    List<Modification> batchedMods = batched.getModifications();
    assertEquals("getModifications size", 2, batchedMods.size());
    Modification mod = batchedMods.get(0);
    assertEquals("Modification type", WriteModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
    assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
    mod = batchedMods.get(1);
    assertEquals("Modification type", MergeModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
    assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ExtendedActorSystem(akka.actor.ExtendedActorSystem) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 39 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class BatchedModificationsTest method testSerialization.

@Test
public void testSerialization() {
    YangInstanceIdentifier writePath = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
    YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
    YangInstanceIdentifier deletePath = TestModel.TEST_PATH;
    final TransactionIdentifier tx1 = nextTransactionId();
    BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
    batched.addModification(new WriteModification(writePath, writeData));
    batched.addModification(new MergeModification(mergePath, mergeData));
    batched.addModification(new DeleteModification(deletePath));
    batched.setReady(true);
    batched.setTotalMessagesSent(5);
    BatchedModifications clone = (BatchedModifications) SerializationUtils.clone((Serializable) batched.toSerializable());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
    assertEquals("getTransactionID", tx1, clone.getTransactionId());
    assertEquals("isReady", true, clone.isReady());
    assertEquals("getTotalMessagesSent", 5, clone.getTotalMessagesSent());
    assertEquals("getModifications size", 3, clone.getModifications().size());
    WriteModification write = (WriteModification) clone.getModifications().get(0);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, write.getVersion());
    assertEquals("getPath", writePath, write.getPath());
    assertEquals("getData", writeData, write.getData());
    MergeModification merge = (MergeModification) clone.getModifications().get(1);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, merge.getVersion());
    assertEquals("getPath", mergePath, merge.getPath());
    assertEquals("getData", mergeData, merge.getData());
    DeleteModification delete = (DeleteModification) clone.getModifications().get(2);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, delete.getVersion());
    assertEquals("getPath", deletePath, delete.getPath());
    // Test with different params.
    final TransactionIdentifier tx2 = nextTransactionId();
    batched = new BatchedModifications(tx2, (short) 10000);
    clone = (BatchedModifications) SerializationUtils.clone((Serializable) batched.toSerializable());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
    assertEquals("getTransactionID", tx2, clone.getTransactionId());
    assertEquals("isReady", false, clone.isReady());
    assertEquals("getModifications size", 0, clone.getModifications().size());
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) Serializable(java.io.Serializable) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 40 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier 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)

Aggregations

TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)57 Test (org.junit.Test)37 FiniteDuration (scala.concurrent.duration.FiniteDuration)17 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)16 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)12 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)11 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)10 ActorRef (akka.actor.ActorRef)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)7 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)7 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)6 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)6 Failure (akka.actor.Status.Failure)5 Timeout (akka.util.Timeout)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)5