Search in sources :

Example 16 with ModifyTransactionRequest

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

the class LocalReadWriteProxyTransactionTest method testApplyModifyTransactionRequestAbort.

@Test
public void testApplyModifyTransactionRequestAbort() throws Exception {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    builder.setSequence(0L);
    builder.setAbort();
    final ModifyTransactionRequest request = builder.build();
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    transaction.replayModifyTransactionRequest(request, callback, Ticker.systemTicker().read());
    getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 17 with ModifyTransactionRequest

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

the class RemoteProxyTransactionTest method testForwardToRemoteModifyCommitSimple.

@Test
public void testForwardToRemoteModifyCommitSimple() throws Exception {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    builder.setSequence(0L);
    builder.setCommit(false);
    final ModifyTransactionRequest request = builder.build();
    final ModifyTransactionRequest received = testForwardToRemote(request, ModifyTransactionRequest.class);
    Assert.assertEquals(request.getPersistenceProtocol(), received.getPersistenceProtocol());
    Assert.assertEquals(request.getModifications(), received.getModifications());
    Assert.assertEquals(request.getTarget(), received.getTarget());
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 18 with ModifyTransactionRequest

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

the class RemoteProxyTransactionTest method testForwardToRemoteModifyCommit3Phase.

@Test
public void testForwardToRemoteModifyCommit3Phase() throws Exception {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    builder.setSequence(0L);
    builder.setCommit(true);
    final ModifyTransactionRequest request = builder.build();
    final ModifyTransactionRequest received = testForwardToRemote(request, ModifyTransactionRequest.class);
    Assert.assertEquals(request.getPersistenceProtocol(), received.getPersistenceProtocol());
    Assert.assertEquals(request.getModifications(), received.getModifications());
    Assert.assertEquals(request.getTarget(), received.getTarget());
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 19 with ModifyTransactionRequest

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

the class RemoteProxyTransactionTest method testDirectCommit.

@Override
@Test
public void testDirectCommit() throws Exception {
    transaction.seal();
    final ListenableFuture<Boolean> result = transaction.directCommit();
    final TransactionTester<RemoteProxyTransaction> tester = getTester();
    final ModifyTransactionRequest req = tester.expectTransactionRequest(ModifyTransactionRequest.class);
    Assert.assertTrue(req.getPersistenceProtocol().isPresent());
    Assert.assertEquals(PersistenceProtocol.SIMPLE, req.getPersistenceProtocol().get());
    tester.replySuccess(new TransactionCommitSuccess(TRANSACTION_ID, req.getSequence()));
    assertFutureEquals(true, result);
}
Also used : TransactionCommitSuccess(org.opendaylight.controller.cluster.access.commands.TransactionCommitSuccess) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 20 with ModifyTransactionRequest

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

the class AbstractProxyTransaction method replayMessages.

// Called with the connection locked
final void replayMessages(final ProxyHistory successorHistory, final Iterable<ConnectionEntry> enqueuedEntries) {
    final SuccessorState local = getSuccessorState();
    final State prevState = local.getPrevState();
    final AbstractProxyTransaction successor = successorHistory.createTransactionProxy(getIdentifier(), isSnapshotOnly(), local.isDone());
    LOG.debug("{} created successor {}", this, successor);
    local.setSuccessor(successor);
    // Replay successful requests first
    if (!successfulRequests.isEmpty()) {
        // We need to find a good timestamp to use for successful requests, as we do not want to time them out
        // nor create timing inconsistencies in the queue -- requests are expected to be ordered by their enqueue
        // time. We will pick the time of the first entry available. If there is none, we will just use current
        // time, as all other requests will get enqueued afterwards.
        final ConnectionEntry firstInQueue = Iterables.getFirst(enqueuedEntries, null);
        final long now = firstInQueue != null ? firstInQueue.getEnqueuedTicks() : parent.currentTime();
        for (Object obj : successfulRequests) {
            if (obj instanceof TransactionRequest) {
                LOG.debug("Forwarding successful request {} to successor {}", obj, successor);
                successor.doReplayRequest((TransactionRequest<?>) obj, resp -> {
                /*NOOP*/
                }, now);
            } else {
                Verify.verify(obj instanceof IncrementSequence);
                final IncrementSequence increment = (IncrementSequence) obj;
                successor.doReplayRequest(new IncrementTransactionSequenceRequest(getIdentifier(), increment.getSequence(), localActor(), isSnapshotOnly(), increment.getDelta()), resp -> {
                /*NOOP*/
                }, now);
                LOG.debug("Incrementing sequence {} to successor {}", obj, successor);
            }
        }
        LOG.debug("{} replayed {} successful requests", getIdentifier(), successfulRequests.size());
        successfulRequests.clear();
    }
    // Now replay whatever is in the connection
    final Iterator<ConnectionEntry> it = enqueuedEntries.iterator();
    while (it.hasNext()) {
        final ConnectionEntry e = it.next();
        final Request<?, ?> req = e.getRequest();
        if (getIdentifier().equals(req.getTarget())) {
            Verify.verify(req instanceof TransactionRequest, "Unhandled request %s", req);
            LOG.debug("Replaying queued request {} to successor {}", req, successor);
            successor.doReplayRequest((TransactionRequest<?>) req, e.getCallback(), e.getEnqueuedTicks());
            it.remove();
        }
    }
    /*
         * Check the state at which we have started the reconnect attempt. State transitions triggered while we were
         * reconnecting have been forced to slow paths, which will be unlocked once we unblock the state latch
         * at the end of this method.
         */
    if (SEALED.equals(prevState)) {
        LOG.debug("Proxy {} reconnected while being sealed, propagating state to successor {}", this, successor);
        final long enqueuedTicks = parent.currentTime();
        final java.util.Optional<ModifyTransactionRequest> optState = flushState();
        if (optState.isPresent()) {
            successor.handleReplayedRemoteRequest(optState.get(), null, enqueuedTicks);
        }
        if (successor.markSealed()) {
            successor.sealAndSend(Optional.of(enqueuedTicks));
        }
    }
}
Also used : TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) ConnectionEntry(org.opendaylight.controller.cluster.access.client.ConnectionEntry) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)

Aggregations

ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)21 Test (org.junit.Test)12 TestProbe (akka.testkit.TestProbe)10 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)9 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)5 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)4 AbstractLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest)3 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)3 IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)3 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)3 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)3 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)3 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)3 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)3 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 Optional (com.google.common.base.Optional)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2