Search in sources :

Example 6 with Response

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());
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionAbortSuccess(org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess) SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Test(org.junit.Test)

Example 7 with Response

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());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) SliceOptions(org.opendaylight.controller.cluster.messaging.SliceOptions) Test(org.junit.Test)

Example 8 with Response

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);
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) Test(org.junit.Test)

Example 9 with Response

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());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) Test(org.junit.Test)

Example 10 with Response

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);
}
Also used : SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Test(org.junit.Test)

Aggregations

Response (org.opendaylight.controller.cluster.access.concepts.Response)21 Test (org.junit.Test)17 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)11 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)9 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 TestProbe (akka.testkit.TestProbe)5 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)5 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)5 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)5 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)5 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)4 ReadTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)4 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)4 Consumer (java.util.function.Consumer)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)3 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)3 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)3 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)3