Search in sources :

Example 1 with TestProbe

use of akka.testkit.TestProbe in project controller by opendaylight.

the class AbstractClientHandleTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    final TestProbe contextProbe = new TestProbe(system, "context");
    final TestProbe clientContextProbe = new TestProbe(system, "client-context");
    backendProbe = new TestProbe(system, "backend");
    // create handle dependencies
    final ActorContext actorContext = createActorContextMock(system, contextProbe.ref());
    final ClientActorContext clientContext = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    client = new SimpleDataStoreClientBehavior(clientContext, actorContext, "shard");
    client.createLocalHistory();
    parent = new SingleClientHistory(client, HISTORY_ID);
    // connect client
    client.getConnection(0L);
    contextProbe.expectMsgClass(ConnectClientRequest.class);
    final long sequence = 0L;
    contextProbe.reply(new ConnectClientSuccess(CLIENT_ID, sequence, backendProbe.ref(), Collections.emptyList(), dataTree, 3));
    final InternalCommand<ShardBackendInfo> command = clientContextProbe.expectMsgClass(InternalCommand.class);
    command.execute(client);
    // data tree mock
    when(dataTree.takeSnapshot()).thenReturn(dataTreeSnapshot);
    handle = createHandle(parent);
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) TestProbe(akka.testkit.TestProbe) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) Before(org.junit.Before)

Example 2 with TestProbe

use of akka.testkit.TestProbe in project controller by opendaylight.

the class AbstractProxyTransactionTest method createRemoteProxyTransactionTester.

@SuppressWarnings("checkstyle:hiddenField")
protected TransactionTester<RemoteProxyTransaction> createRemoteProxyTransactionTester() {
    final TestProbe clientContextProbe = new TestProbe(system, "remoteClientContext");
    final TestProbe backendProbe = new TestProbe(system, "remoteBackend");
    final AbstractClientHistory history = mock(AbstractClientHistory.class);
    final ClientActorContext context = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    final ShardBackendInfo backend = new ShardBackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, "default", UnsignedLong.ZERO, Optional.empty(), 5);
    final AbstractClientConnection<ShardBackendInfo> connection = AccessClientUtil.createConnectedConnection(context, 0L, backend);
    final ProxyHistory proxyHistory = ProxyHistory.createClient(history, connection, HISTORY_ID);
    final RemoteProxyTransaction transaction = new RemoteProxyTransaction(proxyHistory, TRANSACTION_ID, false, false, false);
    return new TransactionTester<>(transaction, connection, backendProbe);
}
Also used : TestProbe(akka.testkit.TestProbe) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext)

Example 3 with TestProbe

use of akka.testkit.TestProbe 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 4 with TestProbe

use of akka.testkit.TestProbe in project controller by opendaylight.

the class AbstractProxyTransactionTest method createLocalProxy.

@SuppressWarnings("checkstyle:hiddenField")
protected TransactionTester<LocalReadWriteProxyTransaction> createLocalProxy() {
    final TestProbe backendProbe = new TestProbe(system, "backend2");
    final TestProbe clientContextProbe = new TestProbe(system, "clientContext2");
    final ClientActorContext context = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    final ShardBackendInfo backend = new ShardBackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, "default", UnsignedLong.ZERO, Optional.empty(), 3);
    final AbstractClientConnection<ShardBackendInfo> connection = AccessClientUtil.createConnectedConnection(context, 0L, backend);
    final AbstractClientHistory history = mock(AbstractClientHistory.class);
    final ProxyHistory parent = ProxyHistory.createClient(history, connection, HISTORY_ID);
    final DataTreeSnapshot snapshot = mock(DataTreeSnapshot.class);
    when(snapshot.newModification()).thenReturn(mock(CursorAwareDataTreeModification.class));
    final LocalReadWriteProxyTransaction tx = new LocalReadWriteProxyTransaction(parent, TestUtils.TRANSACTION_ID, snapshot);
    return new TransactionTester<>(tx, connection, backendProbe);
}
Also used : TestProbe(akka.testkit.TestProbe) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification)

Example 5 with TestProbe

use of akka.testkit.TestProbe in project controller by opendaylight.

the class ClientLocalHistoryTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    final TestProbe clientContextProbe = new TestProbe(system, "client");
    final TestProbe actorContextProbe = new TestProbe(system, "actor-context");
    clientActorContext = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    final ActorContext actorContextMock = createActorContextMock(system, actorContextProbe.ref());
    behavior = new SimpleDataStoreClientBehavior(clientActorContext, actorContextMock, SHARD_NAME);
    object = new ClientLocalHistory(behavior, HISTORY_ID);
}
Also used : TestProbe(akka.testkit.TestProbe) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Before(org.junit.Before)

Aggregations

TestProbe (akka.testkit.TestProbe)51 Test (org.junit.Test)30 Before (org.junit.Before)13 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)10 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)8 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)7 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)5 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)4 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)4 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)4 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification)4 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)3 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)3 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)3 TransactionAbortRequest (org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest)3 ActorRef (akka.actor.ActorRef)2 ArrayList (java.util.ArrayList)2 TransactionDoCommitRequest (org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest)2 TransactionPreCommitRequest (org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest)2