public void bindHttpSelector(String type) { requireNonNull(type, "type is null"); bindHttpSelector(serviceType(type)); }
public void bindHttpSelector(String type) { Preconditions.checkNotNull(type, "type is null"); bindHttpSelector(serviceType(type)); }
public void bindHttpSelector(String type) { Preconditions.checkNotNull(type, "type is null"); bindHttpSelector(serviceType(type)); }
@Override public void configure(Binder binder) { // for backwards compatibility binder.install(new EventModule()); binder.bind(JsonEventWriter.class).in(Scopes.SINGLETON); binder.bind(HttpEventClient.class).in(Scopes.SINGLETON); newSetBinder(binder, EventClient.class).addBinding().to(Key.get(HttpEventClient.class)).in(Scopes.SINGLETON); newExporter(binder).export(EventClient.class).withGeneratedName(); discoveryBinder(binder).bindHttpSelector("collector"); // bind the http client httpClientBinder(binder).bindHttpClient("event", ForEventClient.class); // Kick off the binding of Set<EventTypeMetadata> in case no events are bound newSetBinder(binder, new TypeLiteral<EventTypeMetadata<?>>() {}); } }
@Override public void configure(Binder binder) { // for backwards compatibility binder.install(new EventModule()); binder.bind(JsonEventWriter.class).in(Scopes.SINGLETON); binder.bind(HttpEventClient.class).in(Scopes.SINGLETON); newSetBinder(binder, EventClient.class).addBinding().to(Key.get(HttpEventClient.class)).in(Scopes.SINGLETON); newExporter(binder).export(EventClient.class).withGeneratedName(); discoveryBinder(binder).bindHttpSelector("collector"); // bind the http client httpClientBinder(binder).bindHttpClient("event", ForEventClient.class); // Kick off the binding of Set<EventTypeMetadata> in case no events are bound newSetBinder(binder, new TypeLiteral<EventTypeMetadata<?>>() {}); } }
@Override public void configure(Binder binder) { discoveryBinder(binder).bindHttpSelector("apple"); } }
@Override public void configure(Binder binder) { discoveryBinder(binder).bindHttpSelector("apple"); } }
@Override public void configure(Binder binder) { discoveryBinder(binder).bindHttpSelector("apple"); } }
@Override public void configure(Binder binder) { discoveryBinder(binder).bindHttpSelector("apple"); } }
@Override public void configure(Binder binder) { discoveryBinder(binder).bindHttpSelector("apple"); } }
@Override public void configure(Binder binder) { discoveryBinder(binder).bindHttpSelector(serviceType("apple")); } }
@Test public void testHttpsSelector() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("https", "fake://server-https").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-https")); }
@Test public void testHttpSelectorString() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http")); }
@Test public void testHttpsSelector() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("https", "fake://server-https").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-https")); }
@Test public void testHttpSelectorString() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http")); }
@Test public void testFavorHttpsOverHttpSelector() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build(), serviceAnnouncement("apple").addProperty("https", "fake://server-https").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(selector.selectHttpService(), ImmutableList.of(URI.create("fake://server-https"), URI.create("fake://server-http"))); }
@Test public void testNoHttpServices() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("foo", "fake://server-https").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(selector.selectHttpService(), ImmutableList.of()); }
@Test public void testNoHttpServices() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("foo", "fake://server-https").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(selector.selectHttpService(), ImmutableList.of()); }
@Test public void testHttpSelectorAnnotation() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector(serviceType("apple"))); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http")); ServiceSelectorManager manager = injector.getInstance(ServiceSelectorManager.class); assertEquals(manager.getServiceSelectors().size(), 1); manager.attemptRefresh(); manager.forceRefresh(); }
@Test public void testInvalidUris() { Injector injector = Guice.createInjector( new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new TestingNodeModule(), new TestingDiscoveryModule(), binder -> discoveryBinder(binder).bindHttpSelector("apple")); InMemoryDiscoveryClient discoveryClient = injector.getInstance(InMemoryDiscoveryClient.class); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", ":::INVALID:::").build())); discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("https", ":::INVALID:::").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); assertEquals(selector.selectHttpService(), ImmutableList.of()); } }