Search in sources :

Example 1 with RequestSuccess

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

the class AbstractClientHandleTest method backendRespondToRequest.

/**
 * Checks, whether backend actor has received request of expected class wrapped in RequestEnvelope.
 * Then given response wrapped in ResponseEnvelope is sent.
 *
 * @param expectedRequestClass expected request class
 * @param response             response
 * @param <R>                  expected request type
 * @return request message
 */
protected <R extends Request<?, R>> R backendRespondToRequest(final Class<R> expectedRequestClass, final Response<?, ?> response) {
    final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
    Assert.assertEquals(expectedRequestClass, envelope.getMessage().getClass());
    final AbstractClientConnection<ShardBackendInfo> connection = client.getConnection(0L);
    final long sessionId = envelope.getSessionId();
    final long txSequence = envelope.getTxSequence();
    final long executionTime = 0L;
    if (response instanceof RequestSuccess) {
        final RequestSuccess<?, ?> success = (RequestSuccess<?, ?>) response;
        final SuccessEnvelope responseEnvelope = new SuccessEnvelope(success, sessionId, txSequence, executionTime);
        AccessClientUtil.completeRequest(connection, responseEnvelope);
    } else if (response instanceof RequestFailure) {
        final RequestFailure<?, ?> fail = (RequestFailure<?, ?>) response;
        final FailureEnvelope responseEnvelope = new FailureEnvelope(fail, sessionId, txSequence, executionTime);
        AccessClientUtil.completeRequest(connection, responseEnvelope);
    }
    return expectedRequestClass.cast(envelope.getMessage());
}
Also used : SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) RequestSuccess(org.opendaylight.controller.cluster.access.concepts.RequestSuccess)

Aggregations

FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)1 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)1 RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)1 RequestSuccess (org.opendaylight.controller.cluster.access.concepts.RequestSuccess)1 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)1