Search in sources :

Example 1 with TransactionAbortSuccess

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

the class ReconnectingClientConnectionTest method testSendRequestReceiveResponse.

@Override
@Test
public void testSendRequestReceiveResponse() throws Exception {
    final Consumer<Response<?, ?>> callback = mock(Consumer.class);
    final Request<?, ?> request = createRequest(replyToProbe.ref());
    connection.sendRequest(request, callback);
    backendProbe.expectNoMsg();
    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, after(1000).never()).accept(any());
}
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) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Test(org.junit.Test)

Example 2 with TransactionAbortSuccess

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

the class FrontendReadWriteTransaction method handleTransactionAbort.

private TransactionAbortSuccess handleTransactionAbort(final long sequence, final RequestEnvelope envelope, final long now) {
    if (state instanceof Open) {
        final ReadWriteShardDataTreeTransaction openTransaction = checkOpen();
        startAbort();
        openTransaction.abort(() -> {
            recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), sequence));
            finishAbort();
        });
        return null;
    }
    if (ABORTING.equals(state)) {
        LOG.debug("{}: Transaction {} already aborting", persistenceId(), getIdentifier());
        return null;
    }
    if (ABORTED.equals(state)) {
        // We should have recorded the reply
        LOG.warn("{}: Transaction {} already aborted", persistenceId(), getIdentifier());
        return new TransactionAbortSuccess(getIdentifier(), sequence);
    }
    final Ready ready = checkReady();
    startAbort();
    ready.readyCohort.abort(new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {
            recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), sequence));
            finishAbort();
        }

        @Override
        public void onFailure(final Throwable failure) {
            recordAndSendFailure(envelope, now, new RuntimeRequestException("Abort failed", failure));
            LOG.warn("{}: Transaction {} abort failed", persistenceId(), getIdentifier(), failure);
            finishAbort();
        }
    });
    return null;
}
Also used : TransactionAbortSuccess(org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)

Example 3 with TransactionAbortSuccess

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

Aggregations

TransactionAbortSuccess (org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess)3 Test (org.junit.Test)2 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)2 Response (org.opendaylight.controller.cluster.access.concepts.Response)2 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)1 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)1