use of com.google.inject.Injector in project druid by druid-io.
the class ConditionalMultibindTest method testMultiConditionalBind_cat_dog_non_continuous_syntax.
@Test
public void testMultiConditionalBind_cat_dog_non_continuous_syntax() {
props.setProperty("animal.type", "pets");
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, Animal.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Cat.class);
ConditionalMultibind.create(props, binder, Animal.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Dog.class);
}
});
Set<Animal> animalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>() {
}));
Assert.assertEquals(2, animalSet.size());
Assert.assertEquals(animalSet, ImmutableSet.<Animal>of(new Cat(), new Dog()));
}
use of com.google.inject.Injector in project druid by druid-io.
the class ConditionalMultibindTest method testMultiConditionalBind_cat_dog.
@Test
public void testMultiConditionalBind_cat_dog() {
props.setProperty("animal.type", "pets");
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, Animal.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Cat.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Dog.class);
}
});
Set<Animal> animalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>() {
}));
Assert.assertEquals(2, animalSet.size());
Assert.assertEquals(animalSet, ImmutableSet.<Animal>of(new Cat(), new Dog()));
}
use of com.google.inject.Injector in project druid by druid-io.
the class ConditionalMultibindTest method testMultiConditionalBind_inject.
@Test
public void testMultiConditionalBind_inject() {
props.setProperty("animal.type", "pets");
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, Animal.class).addBinding(Bird.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Cat.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Dog.class);
}
}, new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, Animal.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("not_match"), Tiger.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Fish.class);
}
});
PetShotAvails shop = new PetShotAvails();
injector.injectMembers(shop);
Assert.assertEquals(4, shop.animals.size());
Assert.assertEquals(shop.animals, ImmutableSet.<Animal>of(new Bird(), new Cat(), new Dog(), new Fish()));
}
use of com.google.inject.Injector in project druid by druid-io.
the class AuthenticationKerberosConfigTest method testserde.
@Test
public void testserde() {
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
binder.install(new ConfigModule());
binder.install(new DruidGuiceExtensions());
JsonConfigProvider.bind(binder, "druid.hadoop.security.kerberos", AuthenticationKerberosConfig.class);
}
@Provides
@LazySingleton
public ObjectMapper jsonMapper() {
return new DefaultObjectMapper();
}
});
Properties props = injector.getInstance(Properties.class);
AuthenticationKerberosConfig config = injector.getInstance(AuthenticationKerberosConfig.class);
Assert.assertEquals(props.getProperty("druid.hadoop.security.kerberos.principal"), config.getPrincipal());
Assert.assertEquals(props.getProperty("druid.hadoop.security.kerberos.keytab"), config.getKeytab());
}
use of com.google.inject.Injector in project druid by druid-io.
the class CaffeineCacheProviderWithConfig method testBasicInjection.
@Test
public void testBasicInjection() throws Exception {
final CaffeineCacheConfig config = new CaffeineCacheConfig();
Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/redis");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
binder.bind(CaffeineCacheConfig.class).toInstance(config);
binder.bind(Cache.class).toProvider(CaffeineCacheProviderWithConfig.class).in(ManageLifecycle.class);
}));
final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
lifecycle.start();
try {
Cache cache = injector.getInstance(Cache.class);
Assert.assertEquals(CaffeineCache.class, cache.getClass());
} finally {
lifecycle.stop();
}
}
Aggregations