use of com.netflix.titus.common.util.guice.ContainerEventBusModule in project titus-control-plane by Netflix.
the class ActivationProvisionListenerTest method testActivateOnlyOnce.
@Test
public void testActivateOnlyOnce() throws Exception {
LifecycleInjector injector = InjectorBuilder.fromModules(new ContainerEventBusModule(), new AbstractModule() {
@Override
protected void configure() {
bind(TitusRuntime.class).toInstance(TitusRuntimes.internal());
bind(ActivationProvisionListenerTest.class).toInstance(ActivationProvisionListenerTest.this);
bind(ServiceA.class);
}
}).createInjector();
ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class);
ServiceA serviceA = injector.getInstance(ServiceA.class);
ServiceA otherServiceA = injector.getInstance(ServiceA.class);
assertThat(serviceA).isSameAs(otherServiceA);
assertThat(serviceA.state).isEqualTo("NOT_READY");
activationLifecycle.activate();
assertThat(activationLifecycle.isActive(serviceA)).isTrue();
assertThat(serviceA.state).isEqualTo("ACTIVATED");
assertThat(activationTrace).hasSize(1);
activationLifecycle.deactivate();
assertThat(activationLifecycle.isActive(serviceA)).isFalse();
assertThat(serviceA.state).isEqualTo("DEACTIVATED");
assertThat(activationTrace).hasSize(2);
}
use of com.netflix.titus.common.util.guice.ContainerEventBusModule in project titus-control-plane by Netflix.
the class ActivationProvisionListenerTest method testActivationLifecycle.
@Test
public void testActivationLifecycle() throws Exception {
LifecycleInjector injector = InjectorBuilder.fromModules(new ContainerEventBusModule(), new AbstractModule() {
@Override
protected void configure() {
bind(TitusRuntime.class).toInstance(TitusRuntimes.internal());
bind(ActivationProvisionListenerTest.class).toInstance(ActivationProvisionListenerTest.this);
bind(ServiceA.class).asEagerSingleton();
}
}).createInjector();
ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class);
ServiceA serviceA = injector.getInstance(ServiceA.class);
assertThat(serviceA.state).isEqualTo("NOT_READY");
activationLifecycle.activate();
assertThat(activationLifecycle.isActive(serviceA)).isTrue();
assertThat(serviceA.state).isEqualTo("ACTIVATED");
activationLifecycle.deactivate();
assertThat(activationLifecycle.isActive(serviceA)).isFalse();
assertThat(serviceA.state).isEqualTo("DEACTIVATED");
}
use of com.netflix.titus.common.util.guice.ContainerEventBusModule in project titus-control-plane by Netflix.
the class ProxyMethodInterceptorTest method doTest.
private void doTest(AbstractModule serviceModule) {
Injector injector = Guice.createInjector(new ContainerEventBusModule(), new AbstractModule() {
@Override
protected void configure() {
bind(TitusRuntime.class).toInstance(TitusRuntimes.internal());
}
}, serviceModule);
MyServiceImpl service = (MyServiceImpl) injector.getInstance(MyService.class);
// Check that service is guarded
assertThat(service.isActive()).isFalse();
try {
service.echo("hello");
fail("Expected to fail, as service is not activated yet");
} catch (Exception ignore) {
}
injector.getInstance(ActivationLifecycle.class).activate();
assertThat(service.isActive()).isTrue();
String reply = service.echo("hello");
assertThat(reply).isEqualTo("HELLO");
}
Aggregations