Search in sources :

Example 6 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class FrontendReadWriteTransactionTest method testDuplicateCoordinated.

@Test
public void testDuplicateCoordinated() throws RequestException {
    final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(TX_ID, mock(ActorRef.class));
    b.setSequence(0);
    b.setCommit(true);
    final TransactionRequest<?> readyReq = b.build();
    assertNull(handleRequest(readyReq));
    verify(mockParent).finishTransaction(same(shardTransaction));
    assertNull(handleRequest(readyReq));
    verifyNoMoreInteractions(mockParent);
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) ActorRef(akka.actor.ActorRef) Test(org.junit.Test)

Example 7 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class FrontendReadWriteTransactionTest method testDuplicateModifyAbort.

@Test
public void testDuplicateModifyAbort() throws RequestException {
    final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(TX_ID, mock(ActorRef.class));
    b.setSequence(0);
    b.setAbort();
    final TransactionRequest<?> abortReq = b.build();
    assertNull(handleRequest(abortReq));
    verify(mockParent).abortTransaction(same(shardTransaction), any(Runnable.class));
    assertNull(handleRequest(abortReq));
    verifyNoMoreInteractions(mockParent);
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) ActorRef(akka.actor.ActorRef) Test(org.junit.Test)

Example 8 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class LocalReadWriteProxyTransaction method flushState.

@Override
Optional<ModifyTransactionRequest> flushState() {
    final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(getIdentifier(), localActor());
    b.setSequence(0);
    sealedModification.applyToCursor(new AbstractDataTreeModificationCursor() {

        @Override
        public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
            b.addModification(new TransactionWrite(current().node(child), data));
        }

        @Override
        public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
            b.addModification(new TransactionMerge(current().node(child), data));
        }

        @Override
        public void delete(final PathArgument child) {
            b.addModification(new TransactionDelete(current().node(child)));
        }
    });
    return Optional.of(b.build());
}
Also used : AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge)

Example 9 with ModifyTransactionRequestBuilder

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder in project controller by opendaylight.

the class TransmittingTransmitQueueTest method testSlicingFailureOnTransmit.

@Test
public void testSlicingFailureOnTransmit() throws Exception {
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, SliceOptions.class).getOnFailureCallback().accept(new Exception("mock"));
        return Boolean.FALSE;
    }).when(mockMessageSlicer).slice(any());
    ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(TRANSACTION_IDENTIFIER, probe.ref());
    reqBuilder.setSequence(0L);
    final long now = now();
    Optional<TransmittedConnectionEntry> transmitted = queue.transmit(new ConnectionEntry(reqBuilder.build(), createConsumerMock(), now), now);
    assertTrue(transmitted.isPresent());
    verify(mockMessageSlicer).slice(any());
    probe.expectMsgClass(FailureEnvelope.class);
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) Test(org.junit.Test)

Example 10 with ModifyTransactionRequestBuilder

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

Aggregations

ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)19 Test (org.junit.Test)17 ActorRef (akka.actor.ActorRef)7 TestProbe (akka.testkit.TestProbe)7 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)7 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)3 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)2 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)2 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)2 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)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 SliceOptions (org.opendaylight.controller.cluster.messaging.SliceOptions)2 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)1 FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1