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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations