Search in sources :

Example 6 with RequestEnvelope

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

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());
}
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 8 with RequestEnvelope

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));
}
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) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Test(org.junit.Test)

Example 9 with RequestEnvelope

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());
}
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) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) SliceOptions(org.opendaylight.controller.cluster.messaging.SliceOptions) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) Test(org.junit.Test)

Aggregations

RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)9 Test (org.junit.Test)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)4 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)4 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)2 FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)2 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 SliceOptions (org.opendaylight.controller.cluster.messaging.SliceOptions)2 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 TransactionAbortSuccess (org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)1 RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)1 RequestSuccess (org.opendaylight.controller.cluster.access.concepts.RequestSuccess)1 MessageTracker (org.opendaylight.controller.cluster.common.actor.MessageTracker)1 Error (org.opendaylight.controller.cluster.common.actor.MessageTracker.Error)1 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)1 ForwardedReadyTransaction (org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction)1