protected Module getServiceDiscoveryModule() { return new DiscoveryClientModule(); }
@Override public void configure() { bind(DiscoveryClientConfig.class).toProvider(ConfigProvider.of(DiscoveryClientConfig.class)).in(Scopes.SINGLETON); bind(ServiceURIConverter.class).in(Scopes.SINGLETON); if (readOnly) { bind(ReadOnlyDiscoveryClient.class).to(ReadOnlyDiscoveryClientImpl.class).in(Scopes.SINGLETON); } else { bind(DiscoveryClient.class).to(DiscoveryClientImpl.class).in(Scopes.SINGLETON); bind(ReadOnlyDiscoveryClient.class).to(DiscoveryClient.class).in(Scopes.SINGLETON); bind(ServiceAnnouncer.class).asEagerSingleton(); } HttpClientModule.bindNewObserver(binder()).to(DiscoveryServiceInterceptor.class); }
@Override public Module getTestCaseModule(final Config config) { return Modules.override(new DiscoveryClientModule()).with(new AbstractModule() { @Override protected void configure() { bind (DiscoveryClient.class).toInstance(mockedClient); bind (ReadOnlyDiscoveryClient.class).toInstance(mockedClient); } }); }
@Test public void testSpinup() { final Config config = Config.getEmptyConfig(); final Injector inj = Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new HttpServerModule(config), new JmxModule(), new LifecycleModule(ServiceDiscoveryLifecycle.class), Modules.override(new DiscoveryClientModule()).with(new AbstractModule() { @Override public void configure() { bindConstant().annotatedWith(DiscoveryClientModule.ZOOKEEPER_CONNECT_NAMED).to("1.1.1.1:2345"); bind(new TypeLiteral<Map<Integer, InetSocketAddress>>() {}).annotatedWith(DiscoveryClientModule.ZOOKEEPER_CONNECT_NAMED).toInstance(ImmutableMap.of(1, new InetSocketAddress("1.1.1.1", 2345))); } }), new GalaxyAnnouncementModule("my-service", "my-type")); Assert.assertNotNull(inj); final GalaxyAnnouncer announcer = inj.getInstance(GalaxyAnnouncer.class); Assert.assertNotNull(announcer); } }