Search in sources :

Example 16 with TransactionPurgeRequest

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

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

the class TransmittingTransmitQueueTest method testSetForwarder.

@Test
public void testSetForwarder() throws Exception {
    final FakeTicker ticker = new FakeTicker();
    ticker.setAutoIncrementStep(1, TimeUnit.MICROSECONDS);
    final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
    final Consumer<Response<?, ?>> callback = createConsumerMock();
    final ConnectionEntry entry = new ConnectionEntry(request, callback, ticker.read());
    final ReconnectForwarder forwarder = mock(ReconnectForwarder.class);
    queue.setForwarder(forwarder, ticker.read());
    final long secondEnqueueNow = ticker.read();
    queue.enqueueOrForward(entry, secondEnqueueNow);
    verify(forwarder).forwardEntry(entry, secondEnqueueNow);
}
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) FakeTicker(com.google.common.testing.FakeTicker) Test(org.junit.Test)

Example 18 with TransactionPurgeRequest

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

the class LocalProxyTransactionTest method testHandleForwardedRemotePurgeRequest.

@Test
public void testHandleForwardedRemotePurgeRequest() throws Exception {
    final TestProbe probe = createProbe();
    final TransactionPurgeRequest request = new TransactionPurgeRequest(TRANSACTION_ID, 0L, probe.ref());
    testHandleForwardedRemoteRequest(request);
}
Also used : TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TestProbe(akka.testkit.TestProbe) Test(org.junit.Test)

Example 19 with TransactionPurgeRequest

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

the class LocalProxyTransaction method forwardToRemote.

@Override
final void forwardToRemote(final RemoteProxyTransaction successor, final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
    if (request instanceof CommitLocalTransactionRequest) {
        final CommitLocalTransactionRequest req = (CommitLocalTransactionRequest) request;
        final DataTreeModification mod = req.getModification();
        LOG.debug("Applying modification {} to successor {}", mod, successor);
        mod.applyToCursor(new AbstractDataTreeModificationCursor() {

            @Override
            public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
                successor.write(current().node(child), data);
            }

            @Override
            public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
                successor.merge(current().node(child), data);
            }

            @Override
            public void delete(final PathArgument child) {
                successor.delete(current().node(child));
            }
        });
        successor.sealOnly();
        final ModifyTransactionRequest successorReq = successor.commitRequest(req.isCoordinated());
        successor.sendRequest(successorReq, callback);
    } else if (request instanceof AbortLocalTransactionRequest) {
        LOG.debug("Forwarding abort {} to successor {}", request, successor);
        successor.abort();
    } else if (request instanceof TransactionPurgeRequest) {
        LOG.debug("Forwarding purge {} to successor {}", request, successor);
        successor.enqueuePurge(callback);
    } else if (request instanceof ModifyTransactionRequest) {
        successor.handleForwardedRequest(request, callback);
    } else {
        throwUnhandledRequest(request);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)

Aggregations

TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)19 Test (org.junit.Test)12 Response (org.opendaylight.controller.cluster.access.concepts.Response)11 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)10 TestProbe (akka.testkit.TestProbe)4 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)4 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)4 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)4 Nullable (javax.annotation.Nullable)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)3 IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)3 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)3 TransactionSuccess (org.opendaylight.controller.cluster.access.commands.TransactionSuccess)3 Optional (com.google.common.base.Optional)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2 Consumer (java.util.function.Consumer)2