本文整理汇总了Java中org.opendaylight.controller.cluster.datastore.messages.FindLocalShard类的典型用法代码示例。如果您正苦于以下问题:Java FindLocalShard类的具体用法?Java FindLocalShard怎么用?Java FindLocalShard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FindLocalShard类属于org.opendaylight.controller.cluster.datastore.messages包,在下文中一共展示了FindLocalShard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findLocalShardAsync
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
/**
* Finds a local shard async given its shard name and return a Future from which to obtain the
* ActorRef.
*
* @param shardName the name of the local shard that needs to be found
*/
public Future<ActorRef> findLocalShardAsync(final String shardName) {
Future<Object> future = executeOperationAsync(shardManager,
new FindLocalShard(shardName, true), shardInitializationTimeout);
return future.map(new Mapper<Object, ActorRef>() {
@Override
public ActorRef checkedApply(Object response) throws Throwable {
if (response instanceof LocalShardFound) {
LocalShardFound found = (LocalShardFound)response;
LOG.debug("Local shard found {}", found.getPath());
return found.getPath();
} else if (response instanceof NotInitializedException) {
throw (NotInitializedException)response;
} else if (response instanceof LocalShardNotFound) {
throw new LocalShardNotFoundException(
String.format("Local shard for %s does not exist.", shardName));
}
throw new UnknownMessageException(String.format(
"FindLocalShard returned unkown response: %s", response));
}
}, getClientDispatcher());
}
示例2: findLocalShard
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
private void findLocalShard(final FindLocalShard message) {
LOG.debug("{}: findLocalShard : {}", persistenceId(), message.getShardName());
final ShardInformation shardInformation = localShards.get(message.getShardName());
if (shardInformation == null) {
LOG.debug("{}: Local shard {} not found - shards present: {}",
persistenceId(), message.getShardName(), localShards.keySet());
getSender().tell(new LocalShardNotFound(message.getShardName()), getSelf());
return;
}
sendResponse(shardInformation, message.isWaitUntilInitialized(), false,
() -> new LocalShardFound(shardInformation.getActor()));
}
示例3: onReceive
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Override public void onReceive(final Object message) throws Exception {
if (message instanceof FindPrimary) {
FindPrimary fp = (FindPrimary)message;
Object resp = findPrimaryResponses.get(fp.getShardName());
if (resp == null) {
LOG.error("No expected FindPrimary response found for shard name {}", fp.getShardName());
} else {
getSender().tell(resp, getSelf());
}
return;
}
if (found) {
getSender().tell(new LocalShardFound(actorRef), getSelf());
} else {
getSender().tell(new LocalShardNotFound(((FindLocalShard) message).getShardName()), getSelf());
}
}
示例4: waitForShardInitialized
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
private static void waitForShardInitialized(final ActorRef shardManager, final String shardName,
final JavaTestKit kit) {
AssertionError last = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
try {
shardManager.tell(new FindLocalShard(shardName, true), kit.getRef());
kit.expectMsgClass(LocalShardFound.class);
return;
} catch (AssertionError e) {
last = e;
}
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
throw last;
}
示例5: testOnReceiveFindLocalShardForNonExistentShard
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnReceiveFindLocalShardForNonExistentShard() throws Exception {
new JavaTestKit(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());
}
};
}
示例6: testOnReceiveFindLocalShardForExistentShard
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnReceiveFindLocalShardForExistentShard() throws Exception {
new JavaTestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
LocalShardFound found = expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertTrue("Found path contains " + found.getPath().path().toString(),
found.getPath().path().toString().contains("member-1-shard-default-config"));
}
};
}
示例7: testOnReceiveFindLocalShardWaitForShardInitialized
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnReceiveFindLocalShardWaitForShardInitialized() throws Exception {
LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
new JavaTestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
// We're passing waitUntilInitialized = true to FindLocalShard
// so the response should be
// delayed until we send ActorInitialized.
Future<Object> future = Patterns.ask(shardManager, new FindLocalShard(Shard.DEFAULT_NAME, true),
new Timeout(5, TimeUnit.SECONDS));
shardManager.tell(new ActorInitialized(), mockShardActor);
Object resp = Await.result(future, duration("5 seconds"));
assertTrue("Expected: LocalShardFound, Actual: " + resp, resp instanceof LocalShardFound);
}
};
LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
}
示例8: findLocalShard
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
/**
* Finds a local shard given its shard name and return it's ActorRef.
*
* @param shardName the name of the local shard that needs to be found
* @return a reference to a local shard actor which represents the shard
* specified by the shardName
*/
public Optional<ActorRef> findLocalShard(String shardName) {
Object result = executeOperation(shardManager, new FindLocalShard(shardName, false));
if (result instanceof LocalShardFound) {
LocalShardFound found = (LocalShardFound) result;
LOG.debug("Local shard found {}", found.getPath());
return Optional.of(found.getPath());
}
return Optional.absent();
}
示例9: testOnReceiveFindLocalShardForNotInitializedShard
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnReceiveFindLocalShardForNotInitializedShard() throws Exception {
new JavaTestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
}
};
}
示例10: testOnCreateShardWithLocalMemberNotInShardConfig
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnCreateShardWithLocalMemberNotInShardConfig() {
LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig starting");
new JavaTestKit(getSystem()) {
{
datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
ActorRef shardManager = actorFactory
.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider()))
.withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module",
"foo", null, members("member-5", "member-6"));
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertEquals("peerMembers size", 0, shardBuilder.getPeerAddresses().size());
assertEquals("schemaContext", DisableElectionsRaftPolicy.class.getName(), shardBuilder
.getDatastoreContext().getShardRaftConfig().getCustomRaftPolicyImplementationClass());
}
};
LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig ending");
}
示例11: testOnCreateShardWithNoInitialSchemaContext
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnCreateShardWithNoInitialSchemaContext() {
LOG.info("testOnCreateShardWithNoInitialSchemaContext starting");
new JavaTestKit(getSystem()) {
{
ActorRef shardManager = actorFactory
.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider()))
.withDispatcher(Dispatchers.DefaultDispatcherId()));
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module",
"foo", null, members("member-1"));
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
SchemaContext schemaContext = TestModel.createTestContext();
shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
assertNotNull("schemaContext is null", shardBuilder.getDatastoreContext());
}
};
LOG.info("testOnCreateShardWithNoInitialSchemaContext ending");
}
示例12: testAddShardReplicaWithPreExistingLocalReplicaLeader
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testAddShardReplicaWithPreExistingLocalReplicaLeader() throws Exception {
LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader starting");
new JavaTestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class),
DataStoreVersions.CURRENT_VERSION), getRef());
shardManager.tell(
new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()),
mockShardActor);
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
}
};
LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader ending");
}
示例13: testShardPersistenceWithRestoredData
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testShardPersistenceWithRestoredData() throws Exception {
LOG.info("testShardPersistenceWithRestoredData starting");
new JavaTestKit(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");
}
示例14: testOnCreateShard
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testOnCreateShard() {
LOG.info("testOnCreateShard starting");
new JavaTestKit(getSystem()) {
{
datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
ActorRef shardManager = actorFactory
.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider()))
.withDispatcher(Dispatchers.DefaultDispatcherId()));
SchemaContext schemaContext = TestModel.createTestContext();
shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
DatastoreContext datastoreContext = DatastoreContext.newBuilder().shardElectionTimeoutFactor(100)
.persistent(false).build();
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module",
"foo", null, members("member-1", "member-5", "member-6"));
shardManager.tell(new CreateShard(config, shardBuilder, datastoreContext), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertEquals("isRecoveryApplicable", false, shardBuilder.getDatastoreContext().isPersistent());
assertTrue("Epxected ShardPeerAddressResolver", shardBuilder.getDatastoreContext().getShardRaftConfig()
.getPeerAddressResolver() instanceof ShardPeerAddressResolver);
assertEquals("peerMembers", Sets.newHashSet(
ShardIdentifier.create("foo", MemberName.forName("member-5"), shardMrgIDSuffix).toString(),
ShardIdentifier.create("foo", MemberName.forName("member-6"), shardMrgIDSuffix).toString()),
shardBuilder.getPeerAddresses().keySet());
assertEquals("ShardIdentifier", ShardIdentifier.create("foo", MEMBER_1, shardMrgIDSuffix),
shardBuilder.getId());
assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
// Send CreateShard with same name - should return Success with
// a message.
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
Success success = expectMsgClass(duration("5 seconds"), Success.class);
assertNotNull("Success status is null", success.status());
}
};
LOG.info("testOnCreateShard ending");
}
示例15: testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard; //导入依赖的package包/类
@Test
public void testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader() throws Exception {
LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader starting");
new JavaTestKit(getSystem()) {
{
TestActorRef<TestShardManager> shardManager = actorFactory
.createTestActor(newPropsShardMgrWithMockShardActor(), shardMgrID);
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
String leaderId = "leader-member-shard-default-" + shardMrgIDSuffix;
AddServerReply addServerReply = new AddServerReply(ServerChangeStatus.ALREADY_EXISTS, null);
ActorRef leaderShardActor = shardManager.underlyingActor().getContext()
.actorOf(Props.create(MockRespondActor.class, AddServer.class, addServerReply), leaderId);
MockClusterWrapper.sendMemberUp(shardManager, "leader-member", leaderShardActor.path().toString());
String newReplicaId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(
new RoleChangeNotification(newReplicaId, RaftState.Candidate.name(), RaftState.Follower.name()),
mockShardActor);
shardManager.tell(
new ShardLeaderStateChanged(newReplicaId, leaderId, DataStoreVersions.CURRENT_VERSION),
mockShardActor);
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
MessageCollectorActor.expectFirstMatching(leaderShardActor, AddServer.class);
Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
// Send message again to verify previous in progress state is
// cleared
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
resp = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
// Send message again with an AddServer timeout to verify the
// pre-existing shard actor isn't terminated.
shardManager.tell(
newDatastoreContextFactory(
datastoreContextBuilder.shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build()),
getRef());
leaderShardActor.tell(MockRespondActor.CLEAR_RESPONSE, ActorRef.noSender());
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
expectMsgClass(duration("5 seconds"), Failure.class);
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
}
};
LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader ending");
}