Search in sources :

Example 1 with ConnectClientSuccess

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);
}
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 ConnectClientSuccess

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

Example 3 with ConnectClientSuccess

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());
    }
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) ABIVersion(org.opendaylight.controller.cluster.access.ABIVersion) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Failure(akka.actor.Status.Failure)

Example 4 with ConnectClientSuccess

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);
}
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 5 with ConnectClientSuccess

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

Aggregations

ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)6 TestProbe (akka.testkit.TestProbe)4 Test (org.junit.Test)3 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)2 Failure (akka.actor.Status.Failure)1 Before (org.junit.Before)1 ABIVersion (org.opendaylight.controller.cluster.access.ABIVersion)1 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)1 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)1 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)1 RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)1 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)1 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)1 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)1 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification)1 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)1 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)1