use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest 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.ModifyTransactionRequest in project controller by opendaylight.
the class LocalProxyTransactionTest method testForwardToRemoteAbort.
@Override
@Test
public void testForwardToRemoteAbort() throws Exception {
final TestProbe probe = createProbe();
final AbortLocalTransactionRequest request = new AbortLocalTransactionRequest(TRANSACTION_ID, probe.ref());
final ModifyTransactionRequest modifyRequest = testForwardToRemote(request, ModifyTransactionRequest.class);
Assert.assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
Assert.assertEquals(PersistenceProtocol.ABORT, modifyRequest.getPersistenceProtocol().get());
}
use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest in project controller by opendaylight.
the class LocalProxyTransactionTest method testForwardToRemoteCommit.
@Override
@Test
public void testForwardToRemoteCommit() throws Exception {
final TestProbe probe = createProbe();
final CursorAwareDataTreeModification modification = mock(CursorAwareDataTreeModification.class);
final CommitLocalTransactionRequest request = new CommitLocalTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), modification, null, true);
doAnswer(LocalProxyTransactionTest::applyToCursorAnswer).when(modification).applyToCursor(any());
final ModifyTransactionRequest modifyRequest = testForwardToRemote(request, ModifyTransactionRequest.class);
verify(modification).applyToCursor(any());
Assert.assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
Assert.assertEquals(PersistenceProtocol.THREE_PHASE, modifyRequest.getPersistenceProtocol().get());
checkModifications(modifyRequest);
}
use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest in project controller by opendaylight.
the class LocalReadOnlyProxyTransactionTest method testApplyModifyTransactionRequest.
@Test
public void testApplyModifyTransactionRequest() throws Exception {
final TestProbe probe = createProbe();
final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
builder.setSequence(0);
builder.setAbort();
final ModifyTransactionRequest request = builder.build();
transaction.replayModifyTransactionRequest(request, createCallbackMock(), Ticker.systemTicker().read());
getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
}
use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest in project controller by opendaylight.
the class LocalReadOnlyProxyTransactionTest method testApplyModifyTransactionRequestNotAbort.
@Test
public void testApplyModifyTransactionRequestNotAbort() throws Exception {
final TestProbe probe = createProbe();
final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
builder.setSequence(0);
builder.setReady();
final ModifyTransactionRequest request = builder.build();
assertOperationThrowsException(() -> transaction.replayModifyTransactionRequest(request, createCallbackMock(), Ticker.systemTicker().read()), VerifyException.class);
}
Aggregations