Search in sources :

Example 6 with ContainerEventBusModule

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);
}
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 7 with ContainerEventBusModule

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");
}
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 8 with ContainerEventBusModule

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");
}
Also used : ContainerEventBusModule(com.netflix.titus.common.util.guice.ContainerEventBusModule) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) Injector(com.google.inject.Injector) AbstractModule(com.google.inject.AbstractModule)

Aggregations

ContainerEventBusModule (com.netflix.titus.common.util.guice.ContainerEventBusModule)8 AbstractModule (com.google.inject.AbstractModule)5 ActivationLifecycle (com.netflix.titus.common.util.guice.ActivationLifecycle)5 LifecycleInjector (com.netflix.governator.LifecycleInjector)4 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)4 SystemAbortListener (com.netflix.titus.common.runtime.SystemAbortListener)3 SystemLogService (com.netflix.titus.common.runtime.SystemLogService)3 LoggingSystemAbortListener (com.netflix.titus.common.runtime.internal.LoggingSystemAbortListener)3 LoggingSystemLogService (com.netflix.titus.common.runtime.internal.LoggingSystemLogService)3 Test (org.junit.Test)3 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 Registry (com.netflix.spectator.api.Registry)2 Archaius2ConfigurationLogger (com.netflix.titus.common.util.archaius2.Archaius2ConfigurationLogger)2 TitusEntitySanitizerModule (com.netflix.titus.runtime.TitusEntitySanitizerModule)2 Injector (com.google.inject.Injector)1 GovernatorJerseySupportModule (com.netflix.governator.guice.jersey.GovernatorJerseySupportModule)1 JHiccupModule (com.netflix.titus.common.jhiccup.JHiccupModule)1 FederationEndpointModule (com.netflix.titus.federation.endpoint.FederationEndpointModule)1 CellConnector (com.netflix.titus.federation.service.CellConnector)1 CellInfoResolver (com.netflix.titus.federation.service.CellInfoResolver)1