use of org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess 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 org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess in project controller by opendaylight.
the class ModuleShardBackendResolverTest method testRefreshBackendInfo.
@Test
public void testRefreshBackendInfo() throws Exception {
final CompletionStage<ShardBackendInfo> backendInfo = moduleShardBackendResolver.getBackendInfo(0L);
// handle first connect
contextProbe.expectMsgClass(ConnectClientRequest.class);
final TestProbe staleBackendProbe = new TestProbe(system, "staleBackend");
final ConnectClientSuccess msg = new ConnectClientSuccess(CLIENT_ID, 0L, staleBackendProbe.ref(), Collections.emptyList(), dataTree, 3);
contextProbe.reply(msg);
// get backend info
final ShardBackendInfo staleBackendInfo = TestUtils.getWithTimeout(backendInfo.toCompletableFuture());
// refresh
final CompletionStage<ShardBackendInfo> refreshed = moduleShardBackendResolver.refreshBackendInfo(0L, staleBackendInfo);
// stale backend info should be removed and new connect request issued to the context
contextProbe.expectMsgClass(ConnectClientRequest.class);
final TestProbe refreshedBackendProbe = new TestProbe(system, "refreshedBackend");
final ConnectClientSuccess msg2 = new ConnectClientSuccess(CLIENT_ID, 1L, refreshedBackendProbe.ref(), Collections.emptyList(), dataTree, 3);
contextProbe.reply(msg2);
final ShardBackendInfo refreshedBackendInfo = TestUtils.getWithTimeout(refreshed.toCompletableFuture());
Assert.assertEquals(staleBackendInfo.getCookie(), refreshedBackendInfo.getCookie());
Assert.assertEquals(refreshedBackendProbe.ref(), refreshedBackendInfo.getActor());
}
use of org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess in project controller by opendaylight.
the class Shard method handleConnectClient.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleConnectClient(final ConnectClientRequest message) {
try {
final ClientIdentifier clientId = message.getTarget();
final LeaderFrontendState existing = findFrontend(clientId);
if (existing != null) {
existing.touch();
}
if (!isLeader() || !isLeaderActive()) {
LOG.info("{}: not currently leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}.", persistenceId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
throw new NotLeaderException(getSelf());
}
final ABIVersion selectedVersion = selectVersion(message);
final LeaderFrontendState frontend;
if (existing == null) {
frontend = new LeaderFrontendState(persistenceId(), clientId, store);
knownFrontends.put(clientId.getFrontendId(), frontend);
LOG.debug("{}: created state {} for client {}", persistenceId(), frontend, clientId);
} else {
frontend = existing;
}
frontend.reconnect();
message.getReplyTo().tell(new ConnectClientSuccess(message.getTarget(), message.getSequence(), getSelf(), ImmutableList.of(), store.getDataTree(), CLIENT_MAX_MESSAGES).toVersion(selectedVersion), ActorRef.noSender());
} catch (RequestException | RuntimeException e) {
message.getReplyTo().tell(new Failure(e), ActorRef.noSender());
}
}
use of org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess 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);
}
use of org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess in project controller by opendaylight.
the class ModuleShardBackendResolverTest method testGetBackendInfo.
@Test
public void testGetBackendInfo() throws Exception {
final CompletionStage<ShardBackendInfo> i = moduleShardBackendResolver.getBackendInfo(0L);
contextProbe.expectMsgClass(ConnectClientRequest.class);
final TestProbe backendProbe = new TestProbe(system, "backend");
final ConnectClientSuccess msg = new ConnectClientSuccess(CLIENT_ID, 0L, backendProbe.ref(), Collections.emptyList(), dataTree, 3);
contextProbe.reply(msg);
final CompletionStage<ShardBackendInfo> stage = moduleShardBackendResolver.getBackendInfo(0L);
final ShardBackendInfo shardBackendInfo = TestUtils.getWithTimeout(stage.toCompletableFuture());
Assert.assertEquals(0L, shardBackendInfo.getCookie().longValue());
Assert.assertEquals(dataTree, shardBackendInfo.getDataTree().get());
Assert.assertEquals("default", shardBackendInfo.getShardName());
}
Aggregations