use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.
the class ShardManager method findLocalShard.
private void findLocalShard(final String shardName, final ActorRef sender, final Consumer<LocalShardFound> onLocalShardFound) {
Timeout findLocalTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().getShardInitializationTimeout().duration().$times(2));
Future<Object> futureObj = ask(getSelf(), new FindLocalShard(shardName, true), findLocalTimeout);
futureObj.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
LOG.debug("{}: Received failure from FindLocalShard for shard {}", persistenceId, shardName, failure);
sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to find local shard %s", shardName), failure)), self());
} else {
if (response instanceof LocalShardFound) {
getSelf().tell((RunnableMessage) () -> onLocalShardFound.accept((LocalShardFound) response), sender);
} else if (response instanceof LocalShardNotFound) {
String msg = String.format("Local shard %s does not exist", shardName);
LOG.debug("{}: {}", persistenceId, msg);
sender.tell(new Status.Failure(new IllegalArgumentException(msg)), self());
} else {
String msg = String.format("Failed to find local shard %s: received response: %s", shardName, response);
LOG.debug("{}: {}", persistenceId, msg);
sender.tell(new Status.Failure(response instanceof Throwable ? (Throwable) response : new RuntimeException(msg)), self());
}
}
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testLocalShardNotFound.
@Test(timeout = 10000)
public void testLocalShardNotFound() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
new Thread(() -> proxy.init(path, scope)).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardNotFound("shard-1"));
expectNoMsg(duration("1 seconds"));
proxy.close();
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.
the class DataTreeChangeListenerProxyTest method testLocalShardNotFound.
@Test(timeout = 10000)
public void testLocalShardNotFound() {
new TestKit(getSystem()) {
{
ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
new Thread(() -> proxy.init("shard-1")).start();
FiniteDuration timeout = duration("5 seconds");
FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
reply(new LocalShardNotFound("shard-1"));
expectNoMsg(duration("1 seconds"));
proxy.close();
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.
the class ShardManagerTest method testShardPersistenceWithRestoredData.
@Test
public void testShardPersistenceWithRestoredData() throws Exception {
LOG.info("testShardPersistenceWithRestoredData starting");
new TestKit(getSystem()) {
{
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
String[] restoredShards = { "default", "astronauts" };
ShardManagerSnapshot snapshot = new ShardManagerSnapshot(Arrays.asList(restoredShards), Collections.emptyMap());
InMemorySnapshotStore.addSnapshot("shard-manager-" + shardMrgIDSuffix, snapshot);
// create shardManager to come up with restored data
TestActorRef<TestShardManager> newRestoredShardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
newRestoredShardManager.underlyingActor().waitForRecoveryComplete();
newRestoredShardManager.tell(new FindLocalShard("people", false), getRef());
LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
assertEquals("for uninitialized shard", "people", notFound.getShardName());
// Verify a local shard is created for the restored shards,
// although we expect a NotInitializedException for the shards
// as the actor initialization
// message is not sent for them
newRestoredShardManager.tell(new FindLocalShard("default", false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
newRestoredShardManager.tell(new FindLocalShard("astronauts", false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
}
};
LOG.info("testShardPersistenceWithRestoredData ending");
}
use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindLocalShardForNonExistentShard.
@Test
public void testOnReceiveFindLocalShardForNonExistentShard() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new FindLocalShard("non-existent", false), getRef());
LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
assertEquals("getShardName", "non-existent", notFound.getShardName());
}
};
}
Aggregations