Search in sources :

Example 1 with ModifyTransactionRequest

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());
}
Also used : ArrayList(java.util.ArrayList) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) Response(org.opendaylight.controller.cluster.access.concepts.Response) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) ConnectionEntry(org.opendaylight.controller.cluster.access.client.ConnectionEntry) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 2 with ModifyTransactionRequest

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());
}
Also used : AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 3 with ModifyTransactionRequest

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);
}
Also used : TestProbe(akka.testkit.TestProbe) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) Test(org.junit.Test)

Example 4 with ModifyTransactionRequest

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);
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 5 with ModifyTransactionRequest

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);
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Aggregations

ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)21 Test (org.junit.Test)12 TestProbe (akka.testkit.TestProbe)10 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)9 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)5 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)4 AbstractLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest)3 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)3 IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)3 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)3 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)3 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)3 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)3 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)3 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 Optional (com.google.common.base.Optional)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2