use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testEnqueueCanTransmit.
@Test
public void testEnqueueCanTransmit() throws Exception {
final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
final long now = now();
queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
final RequestEnvelope requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
assertEquals(request, requestEnvelope.getMessage());
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testTransmit.
@Test
@Override
public void testTransmit() throws Exception {
final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
final long now = now();
final ConnectionEntry entry = new ConnectionEntry(request, callback, now);
Optional<TransmittedConnectionEntry> transmitted = queue.transmit(entry, now);
assertTrue(transmitted.isPresent());
assertEquals(request, transmitted.get().getRequest());
assertEquals(callback, transmitted.get().getCallback());
final RequestEnvelope requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
assertEquals(request, requestEnvelope.getMessage());
transmitted = queue.transmit(new ConnectionEntry(new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref()), callback, now), now);
assertTrue(transmitted.isPresent());
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class AbstractClientConnectionTest method testSendRequestReceiveResponse.
@Test
public void testSendRequestReceiveResponse() throws Exception {
final Consumer<Response<?, ?>> callback = mock(Consumer.class);
final Request<?, ?> request = createRequest(replyToProbe.ref());
connection.sendRequest(request, callback);
final RequestEnvelope requestEnvelope = backendProbe.expectMsgClass(RequestEnvelope.class);
Assert.assertEquals(request, requestEnvelope.getMessage());
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, timeout(1000)).accept(isA(TransactionAbortSuccess.class));
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testSlicedRequestOnComplete.
@Test
public void testSlicedRequestOnComplete() throws Exception {
doReturn(true).when(mockMessageSlicer).slice(any());
ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(TRANSACTION_IDENTIFIER, probe.ref());
reqBuilder.setSequence(0L);
final Request<?, ?> request = reqBuilder.build();
final long now = now();
final Consumer<Response<?, ?>> mockConsumer = createConsumerMock();
queue.enqueueOrForward(new ConnectionEntry(request, mockConsumer, now), now);
ArgumentCaptor<SliceOptions> sliceOptions = ArgumentCaptor.forClass(SliceOptions.class);
verify(mockMessageSlicer).slice(sliceOptions.capture());
assertTrue(sliceOptions.getValue().getMessage() instanceof RequestEnvelope);
final Request<?, ?> request2 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref());
queue.enqueueOrForward(new ConnectionEntry(request2, mockConsumer, now), now);
verifyNoMoreInteractions(mockMessageSlicer);
probe.expectNoMsg();
RequestEnvelope requestEnvelope = (RequestEnvelope) sliceOptions.getValue().getMessage();
queue.complete(new FailureEnvelope(request.toRequestFailure(mock(RequestException.class)), requestEnvelope.getSessionId(), requestEnvelope.getTxSequence(), 0), 0);
requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
assertEquals(request2, requestEnvelope.getMessage());
final Request<?, ?> request3 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 3L, probe.ref());
queue.enqueueOrForward(new ConnectionEntry(request3, mockConsumer, now), now);
requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
assertEquals(request3, requestEnvelope.getMessage());
}
Aggregations