use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class AbstractProxyTransactionTest method testReplayMessages.
@Test
public void testReplayMessages() throws Exception {
final TestProbe probe = new TestProbe(system);
final List<ConnectionEntry> entries = new ArrayList<>();
final Consumer<Response<?, ?>> callback = createCallbackMock();
final ReadTransactionRequest request1 = new ReadTransactionRequest(TRANSACTION_ID, 2L, probe.ref(), PATH_2, true);
final ExistsTransactionRequest request2 = new ExistsTransactionRequest(TRANSACTION_ID, 3L, probe.ref(), PATH_3, true);
entries.add(AccessClientUtil.createConnectionEntry(request1, callback, 0L));
entries.add(AccessClientUtil.createConnectionEntry(request2, callback, 0L));
final TransactionTester<RemoteProxyTransaction> successor = createRemoteProxyTransactionTester();
final AbortLocalTransactionRequest successful1 = new AbortLocalTransactionRequest(TRANSACTION_ID, probe.ref());
transaction.recordSuccessfulRequest(successful1);
final ReadTransactionRequest successful2 = new ReadTransactionRequest(TRANSACTION_ID, 1L, probe.ref(), PATH_1, true);
transaction.recordSuccessfulRequest(successful2);
transaction.startReconnect();
final ProxyHistory mockSuccessor = mock(ProxyHistory.class);
when(mockSuccessor.createTransactionProxy(TRANSACTION_ID, transaction.isSnapshotOnly(), false)).thenReturn(successor.getTransaction());
transaction.replayMessages(mockSuccessor, entries);
final ModifyTransactionRequest transformed = successor.expectTransactionRequest(ModifyTransactionRequest.class);
Assert.assertNotNull(transformed);
Assert.assertEquals(successful1.getSequence(), transformed.getSequence());
Assert.assertTrue(transformed.getPersistenceProtocol().isPresent());
Assert.assertEquals(PersistenceProtocol.ABORT, transformed.getPersistenceProtocol().get());
ReadTransactionRequest tmpRead = successor.expectTransactionRequest(ReadTransactionRequest.class);
Assert.assertNotNull(tmpRead);
Assert.assertEquals(successful2.getTarget(), tmpRead.getTarget());
Assert.assertEquals(successful2.getSequence(), tmpRead.getSequence());
Assert.assertEquals(successful2.getPath(), tmpRead.getPath());
Assert.assertEquals(successor.localActor(), tmpRead.getReplyTo());
tmpRead = successor.expectTransactionRequest(ReadTransactionRequest.class);
Assert.assertNotNull(tmpRead);
Assert.assertEquals(request1.getTarget(), tmpRead.getTarget());
Assert.assertEquals(request1.getSequence(), tmpRead.getSequence());
Assert.assertEquals(request1.getPath(), tmpRead.getPath());
Assert.assertEquals(successor.localActor(), tmpRead.getReplyTo());
final ExistsTransactionRequest tmpExist = successor.expectTransactionRequest(ExistsTransactionRequest.class);
Assert.assertNotNull(tmpExist);
Assert.assertEquals(request2.getTarget(), tmpExist.getTarget());
Assert.assertEquals(request2.getSequence(), tmpExist.getSequence());
Assert.assertEquals(request2.getPath(), tmpExist.getPath());
Assert.assertEquals(successor.localActor(), tmpExist.getReplyTo());
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class LocalProxyTransactionTest method testHandleForwardedRemoteReadRequest.
@Test
public void testHandleForwardedRemoteReadRequest() throws Exception {
final TestProbe probe = createProbe();
final ReadTransactionRequest request = new ReadTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, true);
final Consumer<Response<?, ?>> callback = createCallbackMock();
setupExecuteInActor();
transaction.handleReplayedRemoteRequest(request, callback, Ticker.systemTicker().read());
final ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
verify(callback).accept(captor.capture());
final Response<?, ?> value = captor.getValue();
Assert.assertTrue(value instanceof ReadTransactionSuccess);
final ReadTransactionSuccess success = (ReadTransactionSuccess) value;
Assert.assertTrue(success.getData().isPresent());
Assert.assertEquals(DATA_1, success.getData().get());
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class RemoteProxyTransactionTest method testForwardToRemoteModifyRead.
@Test
public void testForwardToRemoteModifyRead() throws Exception {
final TestProbe probe = createProbe();
final ReadTransactionRequest request = new ReadTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, false);
final ReadTransactionRequest received = testForwardToRemote(request, ReadTransactionRequest.class);
Assert.assertEquals(request.getTarget(), received.getTarget());
Assert.assertEquals(request.getPath(), received.getPath());
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class FrontendReadWriteTransactionTest method testReadAfterReady.
@Test(expected = IllegalStateException.class)
public void testReadAfterReady() throws RequestException {
final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(TX_ID, mock(ActorRef.class));
b.setSequence(0);
b.setReady();
final TransactionRequest<?> readyReq = b.build();
assertNotNull(handleRequest(readyReq));
verify(mockParent).finishTransaction(same(shardTransaction));
handleRequest(new ReadTransactionRequest(TX_ID, 0, mock(ActorRef.class), YangInstanceIdentifier.EMPTY, true));
}
use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.
the class RemoteProxyTransaction method handleReplayedRemoteRequest.
@Override
void handleReplayedRemoteRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
final Consumer<Response<?, ?>> cb = callback != null ? callback : resp -> {
};
final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
if (request instanceof ModifyTransactionRequest) {
handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request);
} else if (request instanceof ReadTransactionRequest) {
ensureFlushedBuider(optTicks);
enqueueRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
cb.accept(resp);
}, enqueuedTicks);
} else if (request instanceof ExistsTransactionRequest) {
ensureFlushedBuider(optTicks);
enqueueRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
cb.accept(resp);
}, enqueuedTicks);
} else if (request instanceof TransactionPreCommitRequest) {
ensureFlushedBuider(optTicks);
final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
enqueueRequest(tmp, resp -> {
recordSuccessfulRequest(tmp);
cb.accept(resp);
}, enqueuedTicks);
} else if (request instanceof TransactionDoCommitRequest) {
ensureFlushedBuider(optTicks);
enqueueRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback, enqueuedTicks);
} else if (request instanceof TransactionAbortRequest) {
ensureFlushedBuider(optTicks);
enqueueDoAbort(callback, enqueuedTicks);
} else if (request instanceof TransactionPurgeRequest) {
enqueuePurge(callback, enqueuedTicks);
} else if (request instanceof IncrementTransactionSequenceRequest) {
final IncrementTransactionSequenceRequest req = (IncrementTransactionSequenceRequest) request;
ensureFlushedBuider(optTicks);
enqueueRequest(new IncrementTransactionSequenceRequest(getIdentifier(), nextSequence(), localActor(), snapshotOnly, req.getIncrement()), callback, enqueuedTicks);
incrementSequence(req.getIncrement());
} else {
throw new IllegalArgumentException("Unhandled request {}" + request);
}
}
Aggregations