Search in sources :

Example 1 with ReadTransactionSuccess

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

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

the class RemoteProxyTransactionTest method testRead.

@Override
@Test
public void testRead() throws Exception {
    final TransactionTester<RemoteProxyTransaction> tester = getTester();
    final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = transaction.read(PATH_2);
    final ReadTransactionRequest req = tester.expectTransactionRequest(ReadTransactionRequest.class);
    final Optional<NormalizedNode<?, ?>> result = Optional.of(DATA_1);
    tester.replySuccess(new ReadTransactionSuccess(TRANSACTION_ID, req.getSequence(), result));
    assertFutureEquals(result, read);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) Test(org.junit.Test)

Example 3 with ReadTransactionSuccess

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

the class LocalProxyTransaction method handleReadRequest.

private boolean handleReadRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback) {
    // listeners, which we do not want to execute while we are reconnecting.
    if (request instanceof ReadTransactionRequest) {
        final YangInstanceIdentifier path = ((ReadTransactionRequest) request).getPath();
        final Optional<NormalizedNode<?, ?>> result = Optional.fromJavaUtil(readOnlyView().readNode(path));
        if (callback != null) {
            // XXX: FB does not see that callback is final, on stack and has be check for non-null.
            final Consumer<Response<?, ?>> fbIsStupid = Preconditions.checkNotNull(callback);
            executeInActor(() -> fbIsStupid.accept(new ReadTransactionSuccess(request.getTarget(), request.getSequence(), result)));
        }
        return true;
    } else if (request instanceof ExistsTransactionRequest) {
        final YangInstanceIdentifier path = ((ExistsTransactionRequest) request).getPath();
        final boolean result = readOnlyView().readNode(path).isPresent();
        if (callback != null) {
            // XXX: FB does not see that callback is final, on stack and has be check for non-null.
            final Consumer<Response<?, ?>> fbIsStupid = Preconditions.checkNotNull(callback);
            executeInActor(() -> fbIsStupid.accept(new ExistsTransactionSuccess(request.getTarget(), request.getSequence(), result)));
        }
        return true;
    } else {
        return false;
    }
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) Consumer(java.util.function.Consumer) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)

Aggregations

ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)3 ReadTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)3 Test (org.junit.Test)2 Response (org.opendaylight.controller.cluster.access.concepts.Response)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 TestProbe (akka.testkit.TestProbe)1 Optional (com.google.common.base.Optional)1 Consumer (java.util.function.Consumer)1 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)1 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)1 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1