2011-11-17 23:15:19 +01:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-11-17 23:15:19 +01:00
|
|
|
*/
|
|
|
|
|
package akka.actor;
|
|
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
2011-11-17 23:15:19 +01:00
|
|
|
import org.junit.Test;
|
2011-11-21 15:58:01 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
import akka.testkit.AkkaSpec;
|
|
|
|
|
|
2011-11-21 15:58:01 +01:00
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
|
2011-11-17 23:15:19 +01:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
public class JavaExtension {
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-25 10:45:22 +01:00
|
|
|
static class Provider implements ExtensionIdProvider {
|
2011-11-30 15:16:20 +01:00
|
|
|
public ExtensionId<TestExtension> lookup() {
|
|
|
|
|
return defaultInstance;
|
|
|
|
|
}
|
2011-11-24 18:53:18 +01:00
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-25 10:45:22 +01:00
|
|
|
public final static TestExtensionId defaultInstance = new TestExtensionId();
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-25 10:45:22 +01:00
|
|
|
static class TestExtensionId extends AbstractExtensionId<TestExtension> {
|
|
|
|
|
public TestExtension createExtension(ActorSystemImpl i) {
|
|
|
|
|
return new TestExtension(i);
|
2011-11-17 23:15:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-25 10:45:22 +01:00
|
|
|
static class TestExtension implements Extension {
|
2011-11-29 11:50:22 +01:00
|
|
|
public final ActorSystemImpl system;
|
|
|
|
|
|
|
|
|
|
public TestExtension(ActorSystemImpl i) {
|
|
|
|
|
system = i;
|
|
|
|
|
}
|
2011-11-25 10:45:22 +01:00
|
|
|
}
|
2011-11-29 23:00:57 +01:00
|
|
|
|
|
|
|
|
static class OtherExtension implements Extension {
|
|
|
|
|
static final ExtensionKey<OtherExtension> key = new ExtensionKey<OtherExtension>(OtherExtension.class) {};
|
|
|
|
|
|
|
|
|
|
public final ActorSystemImpl system;
|
|
|
|
|
public OtherExtension(ActorSystemImpl i) {
|
|
|
|
|
system = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-25 10:45:22 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
private static ActorSystem system;
|
2011-11-17 23:15:19 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeAll() {
|
|
|
|
|
Config c = ConfigFactory.parseString("akka.extensions = [ \"akka.actor.JavaExtension$Provider\" ]").withFallback(
|
|
|
|
|
AkkaSpec.testConf());
|
|
|
|
|
system = ActorSystem.create("JavaExtension", c);
|
|
|
|
|
}
|
2011-11-17 23:15:19 +01:00
|
|
|
|
2011-11-30 15:16:20 +01:00
|
|
|
@AfterClass
|
|
|
|
|
public static void afterAll() {
|
2011-12-14 01:06:20 +01:00
|
|
|
system.shutdown();
|
2011-11-30 15:16:20 +01:00
|
|
|
system = null;
|
|
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-17 23:15:19 +01:00
|
|
|
@Test
|
|
|
|
|
public void mustBeAccessible() {
|
2011-11-25 10:45:22 +01:00
|
|
|
assertSame(system.extension(defaultInstance).system, system);
|
|
|
|
|
assertSame(defaultInstance.apply(system).system, system);
|
2011-11-17 23:15:19 +01:00
|
|
|
}
|
2011-11-29 23:00:57 +01:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mustBeAdHoc() {
|
|
|
|
|
assertSame(OtherExtension.key.apply(system).system, system);
|
|
|
|
|
}
|
2011-11-22 13:04:10 +01:00
|
|
|
|
2011-11-17 23:15:19 +01:00
|
|
|
}
|