import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
+import org.opendaylight.controller.cluster.datastore.messages.ActorInitialized;
import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard;
import org.opendaylight.controller.cluster.datastore.messages.FindPrimary;
import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound;
import org.opendaylight.controller.cluster.datastore.messages.PrimaryFound;
import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound;
import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
+import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
public class ShardManagerTest {
private static ActorSystem system;
+ Configuration mockConfig = new MockConfiguration();
+ private static ActorRef defaultShardMockActor;
@BeforeClass
public static void setUpClass() {
myJournal.put("class", "org.opendaylight.controller.cluster.datastore.ShardManagerTest$MyJournal");
myJournal.put("plugin-dispatcher", "akka.actor.default-dispatcher");
Config config = ConfigFactory.load()
- .withValue("akka.persistence.journal.plugin",
- ConfigValueFactory.fromAnyRef("my-journal"))
- .withValue("my-journal", ConfigValueFactory.fromMap(myJournal));
+ .withValue("akka.persistence.journal.plugin",
+ ConfigValueFactory.fromAnyRef("my-journal"))
+ .withValue("my-journal", ConfigValueFactory.fromMap(myJournal));
MyJournal.clear();
system = ActorSystem.create("test", config);
+
+ String name = new ShardIdentifier(Shard.DEFAULT_NAME, "member-1","config").toString();
+ defaultShardMockActor = system.actorOf(Props.create(DoNothingActor.class), name);
+
+
}
@AfterClass
new JavaTestKit(system) {
{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
subject.tell(new FindPrimary("inventory").toSerializable(), getRef());
expectMsgEquals(duration("2 seconds"),
- new PrimaryNotFound("inventory").toSerializable());
+ new PrimaryNotFound("inventory").toSerializable());
}};
}
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
subject.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
+ subject.tell(new ActorInitialized(), defaultShardMockActor);
subject.tell(new FindPrimary(Shard.DEFAULT_NAME).toSerializable(), getRef());
expectMsgClass(duration("1 seconds"), PrimaryFound.SERIALIZABLE_CLASS);
- }};
+ }
+ };
}
@Test
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", mockClusterWrapper,
- new MockConfiguration(), new DatastoreContext());
+ .props("config", mockClusterWrapper,
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
subject.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
+ subject.tell(new ActorInitialized(), defaultShardMockActor);
subject.tell(new FindLocalShard(Shard.DEFAULT_NAME), getRef());
}.get(); // this extracts the received message
assertTrue(out.path().toString(),
- out.path().toString().contains("member-1-shard-default-config"));
+ out.path().toString().contains("member-1-shard-default-config"));
}};
}
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
@Test
public void testOnRecoveryJournalIsEmptied(){
MyJournal.addToJournal(1L, new ShardManager.SchemaContextModules(
- ImmutableSet.of("foo")));
+ ImmutableSet.of("foo")));
assertEquals(1, MyJournal.get().size());
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final ActorRef subject = getSystem().actorOf(props);
public void testOnRecoveryPreviouslyKnownModulesAreDiscovered() throws Exception {
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final TestActorRef<ShardManager> subject =
- TestActorRef.create(system, props);
+ TestActorRef.create(system, props);
subject.underlyingActor().onReceiveRecover(new ShardManager.SchemaContextModules(ImmutableSet.of("foo")));
@Test
public void testOnUpdateSchemaContextUpdateKnownModulesIfTheyContainASuperSetOfTheKnownModules()
- throws Exception {
+ throws Exception {
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final TestActorRef<ShardManager> subject =
- TestActorRef.create(system, props);
+ TestActorRef.create(system, props);
Collection<String> knownModules = subject.underlyingActor().getKnownModules();
@Test
public void testOnUpdateSchemaContextDoNotUpdateKnownModulesIfTheyDoNotContainASuperSetOfKnownModules()
- throws Exception {
+ throws Exception {
new JavaTestKit(system) {{
final Props props = ShardManager
- .props("config", new MockClusterWrapper(),
- new MockConfiguration(), new DatastoreContext());
+ .props("config", new MockClusterWrapper(),
+ new MockConfiguration(), new DatastoreContext());
final TestActorRef<ShardManager> subject =
- TestActorRef.create(system, props);
+ TestActorRef.create(system, props);
Collection<String> knownModules = subject.underlyingActor().getKnownModules();
}
@Override public Future<Void> doAsyncReplayMessages(final String persistenceId, long fromSequenceNr, long toSequenceNr, long max,
- final Procedure<PersistentRepr> replayCallback) {
+ final Procedure<PersistentRepr> replayCallback) {
if(journal.size() == 0){
return Futures.successful(null);
}
public Void call() throws Exception {
for (Map.Entry<Long, Object> entry : journal.entrySet()) {
PersistentRepr persistentMessage =
- new PersistentImpl(entry.getValue(), entry.getKey(), persistenceId,
- false, null, null);
+ new PersistentImpl(entry.getValue(), entry.getKey(), persistenceId,
+ false, null, null);
replayCallback.apply(persistentMessage);
}
return null;
}
@Override public Future<Void> doAsyncWriteMessages(
- final Iterable<PersistentRepr> persistentReprs) {
+ final Iterable<PersistentRepr> persistentReprs) {
return Futures.future(new Callable<Void>() {
@Override
public Void call() throws Exception {
}
@Override public Future<Void> doAsyncWriteConfirmations(
- Iterable<PersistentConfirmation> persistentConfirmations) {
+ Iterable<PersistentConfirmation> persistentConfirmations) {
return Futures.successful(null);
}
@Override public Future<Void> doAsyncDeleteMessages(Iterable<PersistentId> persistentIds,
- boolean b) {
+ boolean b) {
clear();
return Futures.successful(null);
}