use of com.netflix.titus.common.util.guice.ActivationLifecycle in project titus-control-plane by Netflix.
the class ActivationProvisionListenerTest method testDeactivationOrderIsReverseOfActivation.
@Test
public void testDeactivationOrderIsReverseOfActivation() 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(ServiceB.class).asEagerSingleton();
bind(ServiceA.class).asEagerSingleton();
}
}).createInjector();
ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class);
activationLifecycle.activate();
activationLifecycle.deactivate();
assertThat(activationTrace).hasSize(4);
String firstActivated = activationTrace.get(0).getLeft();
String secondActivated = activationTrace.get(1).getLeft();
assertThat(activationTrace.subList(2, 4)).containsExactly(Pair.of(secondActivated, "DEACTIVATED"), Pair.of(firstActivated, "DEACTIVATED"));
}
use of com.netflix.titus.common.util.guice.ActivationLifecycle in project titus-control-plane by Netflix.
the class ActivationProvisionListenerTest method testServiceReordering.
@Test
public void testServiceReordering() 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(ServiceB.class).asEagerSingleton();
bind(ServiceA.class).asEagerSingleton();
}
}).createInjector();
ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class);
activationLifecycle.activate();
assertThat(activationTrace).containsExactlyInAnyOrder(Pair.of("serviceA", "ACTIVATED"), Pair.of("serviceB", "ACTIVATED"));
}
use of com.netflix.titus.common.util.guice.ActivationLifecycle 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.ActivationLifecycle 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");
}
Aggregations