Search in sources :

Example 31 with TestProbe

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

the class AbstractDataStoreClientBehaviorTest method setUp.

@Before
public void setUp() throws Exception {
    system = ActorSystem.apply();
    clientActorProbe = new TestProbe(system, "client");
    actorContextProbe = new TestProbe(system, "actor-context");
    final ActorContext context = createActorContextMock(system, actorContextProbe.ref());
    clientContext = AccessClientUtil.createClientActorContext(system, clientActorProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    behavior = createBehavior(clientContext, context);
}
Also used : TestProbe(akka.testkit.TestProbe) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) Before(org.junit.Before)

Example 32 with TestProbe

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

the class AbstractDataStoreClientBehaviorTest method testGetConnection.

@Test
public void testGetConnection() throws Exception {
    // set up data tree mock
    final CursorAwareDataTreeModification modification = mock(CursorAwareDataTreeModification.class);
    when(modification.readNode(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.empty());
    final DataTreeSnapshot snapshot = mock(DataTreeSnapshot.class);
    when(snapshot.newModification()).thenReturn(modification);
    final DataTree dataTree = mock(DataTree.class);
    when(dataTree.takeSnapshot()).thenReturn(snapshot);
    final TestProbe backendProbe = new TestProbe(system, "backend");
    final long shard = 0L;
    behavior.createTransaction().read(YangInstanceIdentifier.EMPTY);
    final AbstractClientConnection<ShardBackendInfo> connection = behavior.getConnection(shard);
    // check cached connection for same shard
    Assert.assertSame(connection, behavior.getConnection(shard));
    final ConnectClientRequest connectClientRequest = actorContextProbe.expectMsgClass(ConnectClientRequest.class);
    Assert.assertEquals(CLIENT_ID, connectClientRequest.getTarget());
    final long sequence = 0L;
    Assert.assertEquals(sequence, connectClientRequest.getSequence());
    actorContextProbe.reply(new ConnectClientSuccess(CLIENT_ID, sequence, backendProbe.ref(), Collections.emptyList(), dataTree, 3));
    Assert.assertEquals(clientActorProbe.ref(), connection.localActor());
    // capture and execute command passed to client context
    final InternalCommand<ShardBackendInfo> command = clientActorProbe.expectMsgClass(InternalCommand.class);
    command.execute(behavior);
    // check, whether command was reaplayed
    verify(modification).readNode(YangInstanceIdentifier.EMPTY);
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) ConnectClientRequest(org.opendaylight.controller.cluster.access.commands.ConnectClientRequest) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TestProbe(akka.testkit.TestProbe) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification) Test(org.junit.Test)

Example 33 with TestProbe

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

the class AbstractProxyTransactionTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    clientContextProbe = new TestProbe(system, "clientContext");
    backendProbe = new TestProbe(system, "backend");
    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 ProxyHistory parent = ProxyHistory.createClient(history, connection, HISTORY_ID);
    transaction = createTransaction(parent, TestUtils.TRANSACTION_ID, snapshot);
    tester = new TransactionTester<>(transaction, connection, backendProbe);
}
Also used : TestProbe(akka.testkit.TestProbe) Before(org.junit.Before)

Example 34 with TestProbe

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

the class AbstractProxyTransactionTest method testForwardToRemotePurge.

@Test
public void testForwardToRemotePurge() throws Exception {
    final TestProbe probe = new TestProbe(system);
    final TransactionPurgeRequest request = new TransactionPurgeRequest(TRANSACTION_ID, 0L, probe.ref());
    testForwardToRemote(request, TransactionPurgeRequest.class);
}
Also used : TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TestProbe(akka.testkit.TestProbe) Test(org.junit.Test)

Example 35 with TestProbe

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

the class ClientTransactionCommitCohortTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    final TestProbe clientContextProbe = new TestProbe(system, "clientContext");
    final ClientActorContext context = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    transactions = new ArrayList<>();
    for (int i = 0; i < TRANSACTIONS; i++) {
        transactions.add(createTransactionTester(new TestProbe(system, "backend" + i), context, history));
    }
    final Collection<AbstractProxyTransaction> proxies = transactions.stream().map(TransactionTester::getTransaction).collect(Collectors.toList());
    proxies.forEach(AbstractProxyTransaction::seal);
    cohort = new ClientTransactionCommitCohort(history, TRANSACTION_ID, proxies);
}
Also used : TestProbe(akka.testkit.TestProbe) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) 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