use of org.opendaylight.controller.cluster.access.concepts.Response 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.Response in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testRequestSlicingOnTransmit.
@Test
public void testRequestSlicingOnTransmit() 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();
Optional<TransmittedConnectionEntry> transmitted = queue.transmit(new ConnectionEntry(request, mockConsumer, now), now);
assertTrue(transmitted.isPresent());
ArgumentCaptor<SliceOptions> sliceOptions = ArgumentCaptor.forClass(SliceOptions.class);
verify(mockMessageSlicer).slice(sliceOptions.capture());
assertTrue(sliceOptions.getValue().getMessage() instanceof RequestEnvelope);
RequestEnvelope requestEnvelope = (RequestEnvelope) sliceOptions.getValue().getMessage();
assertEquals(request, requestEnvelope.getMessage());
final Request<?, ?> request2 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref());
transmitted = queue.transmit(new ConnectionEntry(request2, mockConsumer, now), now);
assertFalse(transmitted.isPresent());
}
use of org.opendaylight.controller.cluster.access.concepts.Response in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testCompleteOrdering.
@Test
public void testCompleteOrdering() {
final Request<?, ?> req0 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
final Request<?, ?> req1 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref());
final Request<?, ?> req2 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 2L, probe.ref());
final Request<?, ?> req3 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 3L, probe.ref());
final Request<?, ?> req4 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 4L, probe.ref());
final Request<?, ?> req5 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 5L, probe.ref());
final Request<?, ?> req6 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 6L, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
// Fill the queue up to capacity + 1
queue.enqueueOrForward(new ConnectionEntry(req0, callback, 0), 0);
queue.enqueueOrForward(new ConnectionEntry(req1, callback, 0), 0);
queue.enqueueOrForward(new ConnectionEntry(req2, callback, 0), 0);
queue.enqueueOrForward(new ConnectionEntry(req3, callback, 0), 0);
assertEqualRequests(queue.getInflight(), req0, req1, req2);
assertEqualRequests(queue.getPending(), req3);
// Now complete req0, which should transmit req3
queue.complete(new FailureEnvelope(req0.toRequestFailure(mock(RequestException.class)), 0, 0, 0), 0);
assertEqualRequests(queue.getInflight(), req1, req2, req3);
assertEqualRequests(queue.getPending());
// Now complete req1, which should leave an empty slot
queue.complete(new FailureEnvelope(req1.toRequestFailure(mock(RequestException.class)), 0, 1, 0), 0);
assertEqualRequests(queue.getInflight(), req2, req3);
assertEqualRequests(queue.getPending());
// Enqueue req4, which should be immediately transmitted
queue.enqueueOrForward(new ConnectionEntry(req4, callback, 0), 0);
assertEqualRequests(queue.getInflight(), req2, req3, req4);
assertEqualRequests(queue.getPending());
// Enqueue req5, which should move to pending
queue.enqueueOrForward(new ConnectionEntry(req5, callback, 0), 0);
assertEqualRequests(queue.getInflight(), req2, req3, req4);
assertEqualRequests(queue.getPending(), req5);
// Remove req4, creating an inconsistency...
queue.getInflight().removeLast();
assertEqualRequests(queue.getInflight(), req2, req3);
assertEqualRequests(queue.getPending(), req5);
// ... and enqueue req6, which should cause req5 to be transmitted
queue.enqueueOrForward(new ConnectionEntry(req6, callback, 0), 0);
assertEqualRequests(queue.getInflight(), req2, req3, req5);
assertEqualRequests(queue.getPending(), req6);
}
use of org.opendaylight.controller.cluster.access.concepts.Response 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.Response 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