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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations