Search in sources :

Example 11 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder 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 12 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class TransmittingTransmitQueueTest method testSlicedRequestOnComplete.

@Test
public void testSlicedRequestOnComplete() throws Exception {
    doReturn(true).when(mockMessageSlicer).slice(any());
    ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(TRANSACTION_IDENTIFIER, probe.ref());
    reqBuilder.setSequence(0L);
    final Request<?, ?> request = reqBuilder.build();
    final long now = now();
    final Consumer<Response<?, ?>> mockConsumer = createConsumerMock();
    queue.enqueueOrForward(new ConnectionEntry(request, mockConsumer, now), now);
    ArgumentCaptor<SliceOptions> sliceOptions = ArgumentCaptor.forClass(SliceOptions.class);
    verify(mockMessageSlicer).slice(sliceOptions.capture());
    assertTrue(sliceOptions.getValue().getMessage() instanceof RequestEnvelope);
    final Request<?, ?> request2 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref());
    queue.enqueueOrForward(new ConnectionEntry(request2, mockConsumer, now), now);
    verifyNoMoreInteractions(mockMessageSlicer);
    probe.expectNoMsg();
    RequestEnvelope requestEnvelope = (RequestEnvelope) sliceOptions.getValue().getMessage();
    queue.complete(new FailureEnvelope(request.toRequestFailure(mock(RequestException.class)), requestEnvelope.getSessionId(), requestEnvelope.getTxSequence(), 0), 0);
    requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
    assertEquals(request2, requestEnvelope.getMessage());
    final Request<?, ?> request3 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 3L, probe.ref());
    queue.enqueueOrForward(new ConnectionEntry(request3, mockConsumer, now), now);
    requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
    assertEquals(request3, requestEnvelope.getMessage());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) SliceOptions(org.opendaylight.controller.cluster.messaging.SliceOptions) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) Test(org.junit.Test)

Example 13 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class LocalReadWriteProxyTransactionTest method applyModifyTransactionRequest.

private void applyModifyTransactionRequest(final boolean coordinated) {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    final TransactionModification write = new TransactionWrite(PATH_1, DATA_1);
    final TransactionModification merge = new TransactionMerge(PATH_2, DATA_2);
    final TransactionModification delete = new TransactionDelete(PATH_3);
    builder.addModification(write);
    builder.addModification(merge);
    builder.addModification(delete);
    builder.setSequence(0L);
    builder.setCommit(coordinated);
    final ModifyTransactionRequest request = builder.build();
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    transaction.replayModifyTransactionRequest(request, callback, Ticker.systemTicker().read());
    verify(modification).write(PATH_1, DATA_1);
    verify(modification).merge(PATH_2, DATA_2);
    verify(modification).delete(PATH_3);
    final CommitLocalTransactionRequest commitRequest = getTester().expectTransactionRequest(CommitLocalTransactionRequest.class);
    Assert.assertEquals(modification, commitRequest.getModification());
    Assert.assertEquals(coordinated, commitRequest.isCoordinated());
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionModification(org.opendaylight.controller.cluster.access.commands.TransactionModification) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)

Example 14 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class LocalReadWriteProxyTransactionTest method testApplyModifyTransactionRequestAbort.

@Test
public void testApplyModifyTransactionRequestAbort() throws Exception {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    builder.setSequence(0L);
    builder.setAbort();
    final ModifyTransactionRequest request = builder.build();
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    transaction.replayModifyTransactionRequest(request, callback, Ticker.systemTicker().read());
    getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 15 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class RemoteProxyTransactionTest method testForwardToRemoteModifyCommitSimple.

@Test
public void testForwardToRemoteModifyCommitSimple() throws Exception {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    builder.setSequence(0L);
    builder.setCommit(false);
    final ModifyTransactionRequest request = builder.build();
    final ModifyTransactionRequest received = testForwardToRemote(request, ModifyTransactionRequest.class);
    Assert.assertEquals(request.getPersistenceProtocol(), received.getPersistenceProtocol());
    Assert.assertEquals(request.getModifications(), received.getModifications());
    Assert.assertEquals(request.getTarget(), received.getTarget());
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Aggregations

ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)19 Test (org.junit.Test)17 ActorRef (akka.actor.ActorRef)7 TestProbe (akka.testkit.TestProbe)7 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)7 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)3 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)2 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)2 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)2 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)2 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)2 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)2 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)2 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)2 SliceOptions (org.opendaylight.controller.cluster.messaging.SliceOptions)2 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)1 FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1