Search in sources :

Example 6 with TransactionPurgeRequest

use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest 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 7 with TransactionPurgeRequest

use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest 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 8 with TransactionPurgeRequest

use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest 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 9 with TransactionPurgeRequest

use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest 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)

Example 10 with TransactionPurgeRequest

use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest 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)

Aggregations

TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)19 Test (org.junit.Test)12 Response (org.opendaylight.controller.cluster.access.concepts.Response)11 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)10 TestProbe (akka.testkit.TestProbe)4 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)4 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)4 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)4 Nullable (javax.annotation.Nullable)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)3 IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)3 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)3 TransactionSuccess (org.opendaylight.controller.cluster.access.commands.TransactionSuccess)3 Optional (com.google.common.base.Optional)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2 Consumer (java.util.function.Consumer)2