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());
}
Aggregations