Search in sources :

Example 16 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.

the class OpendaylightDirectStatisticsServiceImplTest method testGetMeterStatisticsFail.

@Test
public void testGetMeterStatisticsFail() throws Exception {
    RpcResult<GetMeterStatisticsOutput> result = emptyService.getMeterStatistics(getMeterStatisticsInput).get();
    assertFalse(result.isSuccessful());
    for (RpcError error : result.getErrors()) {
        assertTrue(error.getMessage().contains(AbstractMeterDirectStatisticsService.class.getSimpleName()));
    }
    verify(meterDirectStatisticsService, times(0)).handleAndReply(getMeterStatisticsInput);
}
Also used : GetMeterStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput) RpcError(org.opendaylight.yangtools.yang.common.RpcError) Test(org.junit.Test)

Example 17 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.

the class AbstractRequestCallbackTest method provideRpcError.

private RpcError provideRpcError(ListenableFuture futureResult) throws InterruptedException, java.util.concurrent.ExecutionException {
    final Object result = futureResult.get();
    assertTrue(result instanceof RpcResult);
    RpcResult rpcResult = (RpcResult) result;
    final Collection errors = rpcResult.getErrors();
    assertEquals(1, errors.size());
    final Object error = errors.iterator().next();
    assertTrue(error instanceof RpcError);
    return (RpcError) error;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) Collection(java.util.Collection)

Example 18 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.

the class AbstractRequestCallbackTest method testOnFailureWithDeviceRequestFailedException.

@Test
public void testOnFailureWithDeviceRequestFailedException() throws Exception {
    ErrorMessage dummyErrorMessage = new ErrorMessageBuilder().build();
    abstractRequestCallback.onFailure(new DeviceRequestFailedException(DUMMY_EXCEPTION_DESCRIPTION, dummyErrorMessage));
    final ListenableFuture futureResult = dummyRequestContext.getFuture();
    RpcError rpcError = provideRpcError(futureResult);
    assertEquals("Device reported error type null code null", rpcError.getMessage());
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) RpcError(org.opendaylight.yangtools.yang.common.RpcError) DeviceRequestFailedException(org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) Test(org.junit.Test)

Example 19 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.

the class AbstractRequestCallbackTest method testOnFailure.

@Test
public void testOnFailure() throws Exception {
    abstractRequestCallback.onFailure(new IllegalStateException(DUMMY_MESSAGE_ILLEGAL_STATE_EXCEPTION));
    final ListenableFuture futureResult = dummyRequestContext.getFuture();
    RpcError rpcError = provideRpcError(futureResult);
    assertEquals(DUMMY_MESSAGE_ILLEGAL_STATE_EXCEPTION, rpcError.getMessage());
}
Also used : RpcError(org.opendaylight.yangtools.yang.common.RpcError) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Test(org.junit.Test)

Example 20 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.

the class ResponseExpectedRpcListenerTest method testDiscard.

/**
 * Test object creation.
 */
@Test
public void testDiscard() {
    RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());
    ResponseExpectedRpcListener<OfHeader> listener = new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key);
    listener.discard();
    RpcError rpcError = AbstractRpcListener.buildRpcError("Failed to send message", "check switch connection", new TimeoutException("Request timed out"));
    SettableFuture<RpcResult<?>> result = SettableFuture.create();
    result.set(RpcResultBuilder.failed().withRpcError(rpcError).build());
    try {
        Assert.assertEquals("Wrong result", result.get().getErrors().iterator().next().getMessage(), listener.getResult().get().getErrors().iterator().next().getMessage());
        Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
        Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());
    } catch (InterruptedException | ExecutionException e) {
        fail("Problem accessing result");
    }
}
Also used : OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) BarrierOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

RpcError (org.opendaylight.yangtools.yang.common.RpcError)49 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)20 Test (org.junit.Test)13 ExecutionException (java.util.concurrent.ExecutionException)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 ArrayList (java.util.ArrayList)5 TimeoutException (java.util.concurrent.TimeoutException)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Collection (java.util.Collection)3 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)2 RoutedGetConstantService (org.opendaylight.controller.clustering.it.provider.impl.RoutedGetConstantService)2 YnlListener (org.opendaylight.controller.clustering.it.provider.impl.YnlListener)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 ActorRef (akka.actor.ActorRef)1 Props (akka.actor.Props)1 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1