Search in sources :

Example 1 with ReadRequest

use of org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest in project netconf by opendaylight.

the class ReadTransactionActorTestAdapter method testRead.

@Test
public void testRead() {
    doReturn(immediateFluentFuture(Optional.of(NODE))).when(mockReadTx).read(STORE, PATH);
    actorRef.tell(new ReadRequest(STORE, PATH), probe.ref());
    verify(mockReadTx).read(STORE, PATH);
    final NormalizedNodeMessage response = probe.expectMsgClass(NormalizedNodeMessage.class);
    assertEquals(NODE, response.getNode());
}
Also used : NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) ReadRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest) Test(org.junit.Test)

Example 2 with ReadRequest

use of org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest in project netconf by opendaylight.

the class ProxyReadWriteTransactionTest method testRead.

@Test
public void testRead() throws Exception {
    ProxyReadWriteTransaction tx = newSuccessfulProxyTx();
    final ListenableFuture<Optional<NormalizedNode>> read = tx.read(STORE, PATH);
    final ReadRequest readRequest = masterActor.expectMsgClass(ReadRequest.class);
    assertEquals(STORE, readRequest.getStore());
    assertEquals(PATH, readRequest.getPath());
    masterActor.reply(new NormalizedNodeMessage(PATH, node));
    final Optional<NormalizedNode> result = read.get(5, TimeUnit.SECONDS);
    assertTrue(result.isPresent());
    assertEquals(node, result.get());
}
Also used : NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) Optional(java.util.Optional) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ReadRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest) Test(org.junit.Test)

Example 3 with ReadRequest

use of org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest in project netconf by opendaylight.

the class ReadTransactionActorTestAdapter method testReadEmpty.

@Test
public void testReadEmpty() {
    doReturn(immediateFluentFuture(Optional.empty())).when(mockReadTx).read(STORE, PATH);
    actorRef.tell(new ReadRequest(STORE, PATH), probe.ref());
    verify(mockReadTx).read(STORE, PATH);
    probe.expectMsgClass(EmptyReadResponse.class);
}
Also used : ReadRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest) Test(org.junit.Test)

Example 4 with ReadRequest

use of org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest in project netconf by opendaylight.

the class ReadTransactionActorTestAdapter method testReadFailure.

@Test
public void testReadFailure() {
    final ReadFailedException cause = new ReadFailedException("fail");
    doReturn(immediateFailedFluentFuture(cause)).when(mockReadTx).read(STORE, PATH);
    actorRef.tell(new ReadRequest(STORE, PATH), probe.ref());
    verify(mockReadTx).read(STORE, PATH);
    final Failure response = probe.expectMsgClass(Failure.class);
    assertEquals(cause, response.cause());
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Failure(akka.actor.Status.Failure) ReadRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest) Test(org.junit.Test)

Example 5 with ReadRequest

use of org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest in project netconf by opendaylight.

the class ActorProxyTransactionFacade method read.

@Override
public FluentFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
    LOG.debug("{}: Read {} {} via actor {}", id, store, path, masterTxActor);
    final Future<Object> future = Patterns.ask(masterTxActor, new ReadRequest(store, path), askTimeout);
    final SettableFuture<Optional<NormalizedNode>> settableFuture = SettableFuture.create();
    future.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.debug("{}: Read {} {} failed", id, store, path, failure);
                final Throwable processedFailure = processFailure(failure);
                if (processedFailure instanceof ReadFailedException) {
                    settableFuture.setException(processedFailure);
                } else {
                    settableFuture.setException(new ReadFailedException("Read of store " + store + " path " + path + " failed", processedFailure));
                }
                return;
            }
            LOG.debug("{}: Read {} {} succeeded: {}", id, store, path, response);
            if (response instanceof EmptyReadResponse) {
                settableFuture.set(Optional.empty());
                return;
            }
            if (response instanceof NormalizedNodeMessage) {
                final NormalizedNodeMessage data = (NormalizedNodeMessage) response;
                settableFuture.set(Optional.of(data.getNode()));
            }
        }
    }, executionContext);
    return FluentFuture.from(settableFuture);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) Optional(java.util.Optional) EmptyReadResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyReadResponse) ReadRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest)

Aggregations

ReadRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest)6 Test (org.junit.Test)4 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)3 Optional (java.util.Optional)2 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)2 Failure (akka.actor.Status.Failure)1 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)1 EmptyReadResponse (org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyReadResponse)1 ExistsRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.ExistsRequest)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1