Search in sources :

Example 1 with ActivationLifecycle

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"));
}
Also used : ContainerEventBusModule(com.netflix.titus.common.util.guice.ContainerEventBusModule) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 2 with ActivationLifecycle

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"));
}
Also used : ContainerEventBusModule(com.netflix.titus.common.util.guice.ContainerEventBusModule) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 3 with ActivationLifecycle

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);
}
Also used : ContainerEventBusModule(com.netflix.titus.common.util.guice.ContainerEventBusModule) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 4 with ActivationLifecycle

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");
}
Also used : ContainerEventBusModule(com.netflix.titus.common.util.guice.ContainerEventBusModule) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

AbstractModule (com.google.inject.AbstractModule)4 LifecycleInjector (com.netflix.governator.LifecycleInjector)4 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)4 ActivationLifecycle (com.netflix.titus.common.util.guice.ActivationLifecycle)4 ContainerEventBusModule (com.netflix.titus.common.util.guice.ContainerEventBusModule)4 Test (org.junit.Test)4