use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse 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.commands.TransactionPurgeResponse 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.commands.TransactionPurgeResponse in project controller by opendaylight.
the class RequestEnvelopeTest method doAdditionalAssertions.
@Override
protected void doAdditionalAssertions(final RequestEnvelope envelope, final RequestEnvelope resolvedObject) {
final Request<?, ?> actual = resolvedObject.getMessage();
Assert.assertTrue(actual instanceof TransactionPurgeRequest);
final TransactionPurgeRequest purgeRequest = (TransactionPurgeRequest) actual;
Assert.assertEquals(replyTo, purgeRequest.getReplyTo());
final TransactionPurgeResponse response = new TransactionPurgeResponse(OBJECT, 2L);
resolvedObject.sendSuccess(response, 11L);
final SuccessEnvelope successEnvelope = replyToProbe.expectMsgClass(SuccessEnvelope.class);
Assert.assertEquals(response, successEnvelope.getMessage());
final RuntimeRequestException failResponse = new RuntimeRequestException("fail", new RuntimeException());
resolvedObject.sendFailure(failResponse, 11L);
final FailureEnvelope failureEnvelope = replyToProbe.expectMsgClass(FailureEnvelope.class);
Assert.assertEquals(failResponse, failureEnvelope.getMessage().getCause());
}
use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse in project controller by opendaylight.
the class AbstractFrontendHistory method handleTransactionPurgeRequest.
private TransactionSuccess<?> handleTransactionPurgeRequest(final TransactionRequest<?> request, final RequestEnvelope envelope, final long now) {
final TransactionIdentifier id = request.getTarget();
final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId());
if (purgedTransactions.contains(ul)) {
// Retransmitted purge request: nothing to do
LOG.debug("{}: transaction {} already purged", persistenceId, id);
return new TransactionPurgeResponse(id, request.getSequence());
}
// to an ImmutableMap, which does not allow remove().
if (closedTransactions.containsKey(ul)) {
tree.purgeTransaction(id, () -> {
closedTransactions.remove(ul);
if (closedTransactions.isEmpty()) {
closedTransactions = ImmutableMap.of();
}
purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul)));
LOG.debug("{}: finished purging inherited transaction {}", persistenceId(), id);
envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now);
});
return null;
}
final FrontendTransaction tx = transactions.get(id);
if (tx == null) {
// This should never happen because the purge callback removes the transaction and puts it into
// purged transactions in one go. If it does, we warn about the situation and
LOG.warn("{}: transaction {} not tracked in {}, but not present in active transactions", persistenceId, id, purgedTransactions);
purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul)));
return new TransactionPurgeResponse(id, request.getSequence());
}
tree.purgeTransaction(id, () -> {
purgedTransactions.add(Range.closedOpen(ul, UnsignedLong.ONE.plus(ul)));
transactions.remove(id);
LOG.debug("{}: finished purging transaction {}", persistenceId(), id);
envelope.sendSuccess(new TransactionPurgeResponse(id, request.getSequence()), readTime() - now);
});
return null;
}
Aggregations