Search in sources :

Example 1 with FailureEnvelope

use of org.opendaylight.controller.cluster.access.concepts.FailureEnvelope 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());
}
Also used : SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) RequestSuccess(org.opendaylight.controller.cluster.access.concepts.RequestSuccess)

Example 2 with FailureEnvelope

use of org.opendaylight.controller.cluster.access.concepts.FailureEnvelope in project controller by opendaylight.

the class TransactionTester method replyFailure.

void replyFailure(final RequestException cause) {
    final long sessionId = envelope.getSessionId();
    final long txSequence = envelope.getTxSequence();
    final long executionTime = 0L;
    final RequestFailure<?, ?> fail = new MockFailure(transaction.getIdentifier(), envelope.getMessage().getSequence(), cause);
    final FailureEnvelope responseEnvelope = new FailureEnvelope(fail, sessionId, txSequence, executionTime);
    AccessClientUtil.completeRequest(connection, responseEnvelope);
}
Also used : FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)

Example 3 with FailureEnvelope

use of org.opendaylight.controller.cluster.access.concepts.FailureEnvelope 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 4 with FailureEnvelope

use of org.opendaylight.controller.cluster.access.concepts.FailureEnvelope in project controller by opendaylight.

the class ConnectingClientConnectionTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    doNothing().when(mockCallback).accept(any(MockFailure.class));
    ticker = new FakeTicker();
    ticker.advance(ThreadLocalRandom.current().nextLong());
    doReturn(ticker).when(mockContext).ticker();
    final ClientActorConfig mockConfig = AccessClientUtil.newMockClientActorConfig();
    doReturn(mockConfig).when(mockContext).config();
    doReturn(mock(MessageSlicer.class)).when(mockContext).messageSlicer();
    mockActor = TestProbe.apply(actorSystem);
    mockBackendInfo = new BackendInfo(mockActor.ref(), 0, ABIVersion.current(), 5);
    mockRequest = new MockRequest(mockIdentifier, mockReplyTo);
    mockRequest2 = new MockRequest(mockIdentifier, mockReplyTo);
    mockResponse = mockRequest.toRequestFailure(mockCause);
    mockResponseEnvelope = new FailureEnvelope(mockResponse, 0, 0, 0);
    mockCookie = ThreadLocalRandom.current().nextLong();
    queue = new ConnectingClientConnection<>(mockContext, mockCookie);
}
Also used : FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) FakeTicker(com.google.common.testing.FakeTicker) MessageSlicer(org.opendaylight.controller.cluster.messaging.MessageSlicer) Before(org.junit.Before)

Example 5 with FailureEnvelope

use of org.opendaylight.controller.cluster.access.concepts.FailureEnvelope 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

FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)5 Test (org.junit.Test)2 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)2 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)2 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)2 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)2 Response (org.opendaylight.controller.cluster.access.concepts.Response)2 FakeTicker (com.google.common.testing.FakeTicker)1 Before (org.junit.Before)1 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)1 RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)1 RequestSuccess (org.opendaylight.controller.cluster.access.concepts.RequestSuccess)1 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)1 MessageSlicer (org.opendaylight.controller.cluster.messaging.MessageSlicer)1 SliceOptions (org.opendaylight.controller.cluster.messaging.SliceOptions)1