use of org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope 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());
}
use of org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope in project controller by opendaylight.
the class TransactionTester method replySuccess.
void replySuccess(final RequestSuccess<?, ?> success) {
final long sessionId = envelope.getSessionId();
final long txSequence = envelope.getTxSequence();
final long executionTime = 0L;
final SuccessEnvelope responseEnvelope = new SuccessEnvelope(success, sessionId, txSequence, executionTime);
AccessClientUtil.completeRequest(connection, responseEnvelope);
}
use of org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope in project controller by opendaylight.
the class AbstractTransmitQueueTest method testCompleteReponseNotMatchingRequest.
@Test
public void testCompleteReponseNotMatchingRequest() throws Exception {
final long requestSequence = 0L;
final long txSequence = 0L;
final long sessionId = 0L;
final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, requestSequence, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
final long now = Ticker.systemTicker().read();
queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
// different transaction id
final TransactionIdentifier anotherTxId = new TransactionIdentifier(HISTORY, 1L);
final RequestSuccess<?, ?> success1 = new TransactionPurgeResponse(anotherTxId, requestSequence);
final Optional<TransmittedConnectionEntry> completed1 = queue.complete(new SuccessEnvelope(success1, sessionId, txSequence, 1L), now);
Assert.assertFalse(completed1.isPresent());
// different response sequence
final long differentResponseSequence = 1L;
final RequestSuccess<?, ?> success2 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, differentResponseSequence);
final Optional<TransmittedConnectionEntry> completed2 = queue.complete(new SuccessEnvelope(success2, sessionId, txSequence, 1L), now);
Assert.assertFalse(completed2.isPresent());
// different tx sequence
final long differentTxSequence = 1L;
final RequestSuccess<?, ?> success3 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
final Optional<TransmittedConnectionEntry> completed3 = queue.complete(new SuccessEnvelope(success3, sessionId, differentTxSequence, 1L), now);
Assert.assertFalse(completed3.isPresent());
// different session id
final long differentSessionId = 1L;
final RequestSuccess<?, ?> success4 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
final Optional<TransmittedConnectionEntry> completed4 = queue.complete(new SuccessEnvelope(success4, differentSessionId, differentTxSequence, 1L), now);
Assert.assertFalse(completed4.isPresent());
}
use of org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope in project controller by opendaylight.
the class ReconnectingClientConnectionTest method testSendRequestReceiveResponse.
@Override
@Test
public void testSendRequestReceiveResponse() throws Exception {
final Consumer<Response<?, ?>> callback = mock(Consumer.class);
final Request<?, ?> request = createRequest(replyToProbe.ref());
connection.sendRequest(request, callback);
backendProbe.expectNoMsg();
final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(CLIENT_ID, 0L);
final RequestSuccess<?, ?> message = new TransactionAbortSuccess(new TransactionIdentifier(historyId, 0L), 0L);
final ResponseEnvelope<?> envelope = new SuccessEnvelope(message, 0L, 0L, 0L);
connection.receiveResponse(envelope);
verify(callback, after(1000).never()).accept(any());
}
use of org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testComplete.
@Test
public void testComplete() throws Exception {
final long sequence1 = 0L;
final long sequence2 = 1L;
final Request<?, ?> request1 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, sequence1, probe.ref());
final TransactionIdentifier transactionIdentifier2 = new TransactionIdentifier(HISTORY, 1L);
final Request<?, ?> request2 = new TransactionPurgeRequest(transactionIdentifier2, sequence2, probe.ref());
final Consumer<Response<?, ?>> callback1 = createConsumerMock();
final Consumer<Response<?, ?>> callback2 = createConsumerMock();
final long now1 = now();
final long now2 = now();
// enqueue 2 entries
queue.enqueueOrForward(new ConnectionEntry(request1, callback1, now1), now1);
queue.enqueueOrForward(new ConnectionEntry(request2, callback2, now2), now2);
final RequestSuccess<?, ?> success1 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, sequence1);
final RequestSuccess<?, ?> success2 = new TransactionPurgeResponse(transactionIdentifier2, sequence2);
// complete entries in different order
final Optional<TransmittedConnectionEntry> completed2 = queue.complete(new SuccessEnvelope(success2, 0L, sequence2, 1L), now2);
final Optional<TransmittedConnectionEntry> completed1 = queue.complete(new SuccessEnvelope(success1, 0L, sequence1, 1L), now1);
// check first entry
final TransmittedConnectionEntry transmittedEntry1 = completed1.orElseThrow(AssertionError::new);
assertEquals(transmittedEntry1.getRequest(), request1);
assertEquals(transmittedEntry1.getTxSequence(), sequence1);
assertEquals(transmittedEntry1.getCallback(), callback1);
// check second entry
final TransmittedConnectionEntry transmittedEntry2 = completed2.orElseThrow(AssertionError::new);
assertEquals(transmittedEntry2.getRequest(), request2);
assertEquals(transmittedEntry2.getTxSequence(), sequence2);
assertEquals(transmittedEntry2.getCallback(), callback2);
}
Aggregations