Search in sources :

Example 26 with TransactionIdentifier

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

the class TransactionChainProxy method onTransactionReady.

@Override
protected <T> void onTransactionReady(final TransactionIdentifier transaction, final Collection<Future<T>> cohortFutures) {
    final State localState = currentState;
    Preconditions.checkState(localState instanceof Allocated, "Readying transaction %s while state is %s", transaction, localState);
    final TransactionIdentifier currentTx = ((Allocated) localState).getIdentifier();
    Preconditions.checkState(transaction.equals(currentTx), "Readying transaction %s while %s is allocated", transaction, currentTx);
    // Transaction ready and we are not waiting for futures -- go to idle
    if (cohortFutures.isEmpty()) {
        currentState = IDLE_STATE;
        return;
    }
    // Combine the ready Futures into 1
    final Future<Iterable<T>> combined = Futures.sequence(cohortFutures, getActorContext().getClientDispatcher());
    // Record the we have outstanding futures
    final State newState = new Submitted(transaction, combined);
    currentState = newState;
    // Attach a completion reset, but only if we do not allocate a transaction
    // in-between
    combined.onComplete(new OnComplete<Iterable<T>>() {

        @Override
        public void onComplete(final Throwable arg0, final Iterable<T> arg1) {
            STATE_UPDATER.compareAndSet(TransactionChainProxy.this, newState, IDLE_STATE);
        }
    }, getActorContext().getClientDispatcher());
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)

Example 27 with TransactionIdentifier

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

the class AbstractTransmitQueueTest method testCompleteReponseNotMatchingRequest.

@Test
public void testCompleteReponseNotMatchingRequest() throws Exception {
    final long requestSequence = 0L;
    final long txSequence = 0L;
    final long sessionId = 0L;
    final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, requestSequence, probe.ref());
    final Consumer<Response<?, ?>> callback = createConsumerMock();
    final long now = Ticker.systemTicker().read();
    queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
    // different transaction id
    final TransactionIdentifier anotherTxId = new TransactionIdentifier(HISTORY, 1L);
    final RequestSuccess<?, ?> success1 = new TransactionPurgeResponse(anotherTxId, requestSequence);
    final Optional<TransmittedConnectionEntry> completed1 = queue.complete(new SuccessEnvelope(success1, sessionId, txSequence, 1L), now);
    Assert.assertFalse(completed1.isPresent());
    // different response sequence
    final long differentResponseSequence = 1L;
    final RequestSuccess<?, ?> success2 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, differentResponseSequence);
    final Optional<TransmittedConnectionEntry> completed2 = queue.complete(new SuccessEnvelope(success2, sessionId, txSequence, 1L), now);
    Assert.assertFalse(completed2.isPresent());
    // different tx sequence
    final long differentTxSequence = 1L;
    final RequestSuccess<?, ?> success3 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
    final Optional<TransmittedConnectionEntry> completed3 = queue.complete(new SuccessEnvelope(success3, sessionId, differentTxSequence, 1L), now);
    Assert.assertFalse(completed3.isPresent());
    // different session id
    final long differentSessionId = 1L;
    final RequestSuccess<?, ?> success4 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
    final Optional<TransmittedConnectionEntry> completed4 = queue.complete(new SuccessEnvelope(success4, differentSessionId, differentTxSequence, 1L), now);
    Assert.assertFalse(completed4.isPresent());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Test(org.junit.Test)

Example 28 with TransactionIdentifier

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

the class ReconnectingClientConnectionTest method testSendRequestReceiveResponse.

@Override
@Test
public void testSendRequestReceiveResponse() throws Exception {
    final Consumer<Response<?, ?>> callback = mock(Consumer.class);
    final Request<?, ?> request = createRequest(replyToProbe.ref());
    connection.sendRequest(request, callback);
    backendProbe.expectNoMsg();
    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, after(1000).never()).accept(any());
}
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) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Test(org.junit.Test)

Example 29 with TransactionIdentifier

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

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

the class ModifyTransactionRequestBuilderTest method testGetIdentifier.

@Test
public void testGetIdentifier() throws Exception {
    final TransactionIdentifier identifier = modifyTransactionRequestBuilder.getIdentifier();
    Assert.assertEquals(transactionIdentifier, identifier);
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Test(org.junit.Test)

Aggregations

TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)57 Test (org.junit.Test)37 FiniteDuration (scala.concurrent.duration.FiniteDuration)17 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)16 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)12 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)11 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)10 ActorRef (akka.actor.ActorRef)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)7 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)7 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)6 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)6 Failure (akka.actor.Status.Failure)5 Timeout (akka.util.Timeout)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)5