Search in sources :

Example 11 with Response

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

the class TransmittingTransmitQueueTest method testTransmit.

@Test
@Override
public void testTransmit() throws Exception {
    final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
    final Consumer<Response<?, ?>> callback = createConsumerMock();
    final long now = now();
    final ConnectionEntry entry = new ConnectionEntry(request, callback, now);
    Optional<TransmittedConnectionEntry> transmitted = queue.transmit(entry, now);
    assertTrue(transmitted.isPresent());
    assertEquals(request, transmitted.get().getRequest());
    assertEquals(callback, transmitted.get().getCallback());
    final RequestEnvelope requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
    assertEquals(request, requestEnvelope.getMessage());
    transmitted = queue.transmit(new ConnectionEntry(new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref()), callback, now), now);
    assertTrue(transmitted.isPresent());
}
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) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) Test(org.junit.Test)

Example 12 with Response

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

the class RemoteProxyTransaction method handleForwardedRequest.

void handleForwardedRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
    if (request instanceof ModifyTransactionRequest) {
        handleForwardedModifyTransactionRequest(callback, (ModifyTransactionRequest) request);
    } else if (request instanceof ReadTransactionRequest) {
        ensureFlushedBuider();
        sendRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            callback.accept(resp);
        });
    } else if (request instanceof ExistsTransactionRequest) {
        ensureFlushedBuider();
        sendRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            callback.accept(resp);
        });
    } else if (request instanceof TransactionPreCommitRequest) {
        ensureFlushedBuider();
        final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
        sendRequest(tmp, resp -> {
            recordSuccessfulRequest(tmp);
            callback.accept(resp);
        });
    } else if (request instanceof TransactionDoCommitRequest) {
        ensureFlushedBuider();
        sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback);
    } else if (request instanceof TransactionAbortRequest) {
        ensureFlushedBuider();
        sendDoAbort(callback);
    } else if (request instanceof TransactionPurgeRequest) {
        enqueuePurge(callback);
    } else {
        throw new IllegalArgumentException("Unhandled request {}" + request);
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) LoggerFactory(org.slf4j.LoggerFactory) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) Response(org.opendaylight.controller.cluster.access.concepts.Response) MappingCheckedFuture(org.opendaylight.mdsal.common.api.MappingCheckedFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) TransactionModification(org.opendaylight.controller.cluster.access.commands.TransactionModification) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) Optional(com.google.common.base.Optional) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) Nullable(javax.annotation.Nullable) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Logger(org.slf4j.Logger) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge) PersistenceProtocol(org.opendaylight.controller.cluster.access.commands.PersistenceProtocol) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) TransactionSuccess(org.opendaylight.controller.cluster.access.commands.TransactionSuccess) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest)

Example 13 with Response

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

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

the class AbstractTransmitQueueTest method testPoison.

@Test
public void testPoison() throws Exception {
    final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
    final Consumer<Response<?, ?>> callback = createConsumerMock();
    final long now = Ticker.systemTicker().read();
    queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
    queue.poison(new RuntimeRequestException("fail", new RuntimeException("fail")));
    verify(callback).accept(any(TransactionFailure.class));
    Assert.assertTrue(queue.isEmpty());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionFailure(org.opendaylight.controller.cluster.access.commands.TransactionFailure) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Test(org.junit.Test)

Example 15 with Response

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

Aggregations

Response (org.opendaylight.controller.cluster.access.concepts.Response)21 Test (org.junit.Test)17 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)11 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)9 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 TestProbe (akka.testkit.TestProbe)5 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)5 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)5 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)5 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)5 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)4 ReadTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)4 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)4 Consumer (java.util.function.Consumer)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)3 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)3 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)3 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)3