Search in sources :

Example 1 with Response

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

the class AbstractProxyTransactionTest method testReplayMessages.

@Test
public void testReplayMessages() throws Exception {
    final TestProbe probe = new TestProbe(system);
    final List<ConnectionEntry> entries = new ArrayList<>();
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    final ReadTransactionRequest request1 = new ReadTransactionRequest(TRANSACTION_ID, 2L, probe.ref(), PATH_2, true);
    final ExistsTransactionRequest request2 = new ExistsTransactionRequest(TRANSACTION_ID, 3L, probe.ref(), PATH_3, true);
    entries.add(AccessClientUtil.createConnectionEntry(request1, callback, 0L));
    entries.add(AccessClientUtil.createConnectionEntry(request2, callback, 0L));
    final TransactionTester<RemoteProxyTransaction> successor = createRemoteProxyTransactionTester();
    final AbortLocalTransactionRequest successful1 = new AbortLocalTransactionRequest(TRANSACTION_ID, probe.ref());
    transaction.recordSuccessfulRequest(successful1);
    final ReadTransactionRequest successful2 = new ReadTransactionRequest(TRANSACTION_ID, 1L, probe.ref(), PATH_1, true);
    transaction.recordSuccessfulRequest(successful2);
    transaction.startReconnect();
    final ProxyHistory mockSuccessor = mock(ProxyHistory.class);
    when(mockSuccessor.createTransactionProxy(TRANSACTION_ID, transaction.isSnapshotOnly(), false)).thenReturn(successor.getTransaction());
    transaction.replayMessages(mockSuccessor, entries);
    final ModifyTransactionRequest transformed = successor.expectTransactionRequest(ModifyTransactionRequest.class);
    Assert.assertNotNull(transformed);
    Assert.assertEquals(successful1.getSequence(), transformed.getSequence());
    Assert.assertTrue(transformed.getPersistenceProtocol().isPresent());
    Assert.assertEquals(PersistenceProtocol.ABORT, transformed.getPersistenceProtocol().get());
    ReadTransactionRequest tmpRead = successor.expectTransactionRequest(ReadTransactionRequest.class);
    Assert.assertNotNull(tmpRead);
    Assert.assertEquals(successful2.getTarget(), tmpRead.getTarget());
    Assert.assertEquals(successful2.getSequence(), tmpRead.getSequence());
    Assert.assertEquals(successful2.getPath(), tmpRead.getPath());
    Assert.assertEquals(successor.localActor(), tmpRead.getReplyTo());
    tmpRead = successor.expectTransactionRequest(ReadTransactionRequest.class);
    Assert.assertNotNull(tmpRead);
    Assert.assertEquals(request1.getTarget(), tmpRead.getTarget());
    Assert.assertEquals(request1.getSequence(), tmpRead.getSequence());
    Assert.assertEquals(request1.getPath(), tmpRead.getPath());
    Assert.assertEquals(successor.localActor(), tmpRead.getReplyTo());
    final ExistsTransactionRequest tmpExist = successor.expectTransactionRequest(ExistsTransactionRequest.class);
    Assert.assertNotNull(tmpExist);
    Assert.assertEquals(request2.getTarget(), tmpExist.getTarget());
    Assert.assertEquals(request2.getSequence(), tmpExist.getSequence());
    Assert.assertEquals(request2.getPath(), tmpExist.getPath());
    Assert.assertEquals(successor.localActor(), tmpExist.getReplyTo());
}
Also used : ArrayList(java.util.ArrayList) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) Response(org.opendaylight.controller.cluster.access.concepts.Response) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) ConnectionEntry(org.opendaylight.controller.cluster.access.client.ConnectionEntry) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 2 with Response

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

the class LocalProxyTransactionTest method testHandleForwardedRemoteReadRequest.

@Test
public void testHandleForwardedRemoteReadRequest() throws Exception {
    final TestProbe probe = createProbe();
    final ReadTransactionRequest request = new ReadTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, true);
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    setupExecuteInActor();
    transaction.handleReplayedRemoteRequest(request, callback, Ticker.systemTicker().read());
    final ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(callback).accept(captor.capture());
    final Response<?, ?> value = captor.getValue();
    Assert.assertTrue(value instanceof ReadTransactionSuccess);
    final ReadTransactionSuccess success = (ReadTransactionSuccess) value;
    Assert.assertTrue(success.getData().isPresent());
    Assert.assertEquals(DATA_1, success.getData().get());
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) TestProbe(akka.testkit.TestProbe) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) Test(org.junit.Test)

Example 3 with Response

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

the class RemoteProxyTransaction method handleReplayedRemoteRequest.

@Override
void handleReplayedRemoteRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
    final Consumer<Response<?, ?>> cb = callback != null ? callback : resp -> {
    };
    final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
    if (request instanceof ModifyTransactionRequest) {
        handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request);
    } else if (request instanceof ReadTransactionRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof ExistsTransactionRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof TransactionPreCommitRequest) {
        ensureFlushedBuider(optTicks);
        final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
        enqueueRequest(tmp, resp -> {
            recordSuccessfulRequest(tmp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof TransactionDoCommitRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback, enqueuedTicks);
    } else if (request instanceof TransactionAbortRequest) {
        ensureFlushedBuider(optTicks);
        enqueueDoAbort(callback, enqueuedTicks);
    } else if (request instanceof TransactionPurgeRequest) {
        enqueuePurge(callback, enqueuedTicks);
    } else if (request instanceof IncrementTransactionSequenceRequest) {
        final IncrementTransactionSequenceRequest req = (IncrementTransactionSequenceRequest) request;
        ensureFlushedBuider(optTicks);
        enqueueRequest(new IncrementTransactionSequenceRequest(getIdentifier(), nextSequence(), localActor(), snapshotOnly, req.getIncrement()), callback, enqueuedTicks);
        incrementSequence(req.getIncrement());
    } 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) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) 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) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest)

Example 4 with Response

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

the class AbstractClientConnectionTest method testPoison.

@Test
public void testPoison() throws Exception {
    final Consumer<Response<?, ?>> callback = mock(Consumer.class);
    final Request<?, ?> request = createRequest(replyToProbe.ref());
    final ConnectionEntry entry = new ConnectionEntry(request, callback, 0L);
    connection.enqueueEntry(entry, 0L);
    connection.poison(new RuntimeRequestException("fail", new RuntimeException("fail")));
    verify(callback, timeout(1000)).accept(isA(TransactionFailure.class));
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionFailure(org.opendaylight.controller.cluster.access.commands.TransactionFailure) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Test(org.junit.Test)

Example 5 with Response

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

the class AbstractTransmitQueueTest method testCompleteReponseNotMatchingRequest.

@Test
public void testCompleteReponseNotMatchingRequest() throws Exception {
    final long requestSequence = 0L;
    final long txSequence = 0L;
    final long sessionId = 0L;
    final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, requestSequence, probe.ref());
    final Consumer<Response<?, ?>> callback = createConsumerMock();
    final long now = Ticker.systemTicker().read();
    queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
    // different transaction id
    final TransactionIdentifier anotherTxId = new TransactionIdentifier(HISTORY, 1L);
    final RequestSuccess<?, ?> success1 = new TransactionPurgeResponse(anotherTxId, requestSequence);
    final Optional<TransmittedConnectionEntry> completed1 = queue.complete(new SuccessEnvelope(success1, sessionId, txSequence, 1L), now);
    Assert.assertFalse(completed1.isPresent());
    // different response sequence
    final long differentResponseSequence = 1L;
    final RequestSuccess<?, ?> success2 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, differentResponseSequence);
    final Optional<TransmittedConnectionEntry> completed2 = queue.complete(new SuccessEnvelope(success2, sessionId, txSequence, 1L), now);
    Assert.assertFalse(completed2.isPresent());
    // different tx sequence
    final long differentTxSequence = 1L;
    final RequestSuccess<?, ?> success3 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
    final Optional<TransmittedConnectionEntry> completed3 = queue.complete(new SuccessEnvelope(success3, sessionId, differentTxSequence, 1L), now);
    Assert.assertFalse(completed3.isPresent());
    // different session id
    final long differentSessionId = 1L;
    final RequestSuccess<?, ?> success4 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
    final Optional<TransmittedConnectionEntry> completed4 = queue.complete(new SuccessEnvelope(success4, differentSessionId, differentTxSequence, 1L), now);
    Assert.assertFalse(completed4.isPresent());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) 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