use of com.google.inject.Module in project druid by druid-io.
the class MetadataStorageTablesConfigTest method testSerdeMetadataStorageTablesConfig.
@Test
public void testSerdeMetadataStorageTablesConfig() throws Exception {
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.metadata.storage.tables", MetadataStorageTablesConfig.class);
}
@Provides
@LazySingleton
public ObjectMapper jsonMapper() {
return new DefaultObjectMapper();
}
});
Properties props = injector.getInstance(Properties.class);
MetadataStorageTablesConfig config = injector.getInstance(MetadataStorageTablesConfig.class);
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.base"), config.getBase());
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.segments"), config.getSegmentsTable());
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.rules"), config.getRulesTable());
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.config"), config.getConfigTable());
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.tasks"), config.getEntryTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLog"), config.getLogTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLock"), config.getLockTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.dataSource"), config.getDataSourceTable());
Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.supervisors"), config.getSupervisorTable());
}
use of com.google.inject.Module in project che by eclipse.
the class CheBootstrap method getModules.
@Override
protected List<Module> getModules() {
// based on logic that getServletModule() is called BEFORE getModules() in the EverrestGuiceContextListener
modules.add(new InitModule(PostConstruct.class));
modules.add(new DestroyModule(PreDestroy.class, LOG_HANDLER));
modules.add(new URIConverter());
modules.add(new URLConverter());
modules.add(new FileConverter());
modules.add(new PathConverter());
modules.add(new StringArrayConverter());
modules.add(new PairConverter());
modules.add(new PairArrayConverter());
modules.addAll(ModuleScanner.findModules());
Map<String, Set<String>> aliases = readConfigurationAliases();
Module firstConfigurationPermutation = Modules.override(new WebInfConfiguration(aliases)).with(new ExtConfiguration(aliases));
Module secondConfigurationPermutation = Modules.override(firstConfigurationPermutation).with(new CheSystemPropertiesConfigurationModule(aliases));
Module lastConfigurationPermutation = Modules.override(secondConfigurationPermutation).with(new CheEnvironmentVariablesConfigurationModule(aliases));
modules.add(lastConfigurationPermutation);
return modules;
}
use of com.google.inject.Module in project druid by druid-io.
the class PolyBindTest method testSanity.
@Test
public void testSanity() throws Exception {
setUp(new Module() {
@Override
public void configure(Binder binder) {
final MapBinder<String, Gogo> gogoBinder = PolyBind.optionBinder(binder, Key.get(Gogo.class));
gogoBinder.addBinding("a").to(GoA.class);
gogoBinder.addBinding("b").to(GoB.class);
final MapBinder<String, GogoSally> gogoSallyBinder = PolyBind.optionBinder(binder, Key.get(GogoSally.class));
gogoSallyBinder.addBinding("a").to(GoA.class);
gogoSallyBinder.addBinding("b").to(GoB.class);
PolyBind.createChoice(binder, "billy", Key.get(Gogo.class, Names.named("reverse")), Key.get(GoB.class));
final MapBinder<String, Gogo> annotatedGogoBinder = PolyBind.optionBinder(binder, Key.get(Gogo.class, Names.named("reverse")));
annotatedGogoBinder.addBinding("a").to(GoB.class);
annotatedGogoBinder.addBinding("b").to(GoA.class);
}
});
Assert.assertEquals("A", injector.getInstance(Gogo.class).go());
Assert.assertEquals("B", injector.getInstance(Key.get(Gogo.class, Names.named("reverse"))).go());
props.setProperty("billy", "b");
Assert.assertEquals("B", injector.getInstance(Gogo.class).go());
Assert.assertEquals("A", injector.getInstance(Key.get(Gogo.class, Names.named("reverse"))).go());
props.setProperty("billy", "a");
Assert.assertEquals("A", injector.getInstance(Gogo.class).go());
Assert.assertEquals("B", injector.getInstance(Key.get(Gogo.class, Names.named("reverse"))).go());
props.setProperty("billy", "b");
Assert.assertEquals("B", injector.getInstance(Gogo.class).go());
Assert.assertEquals("A", injector.getInstance(Key.get(Gogo.class, Names.named("reverse"))).go());
props.setProperty("billy", "c");
Assert.assertEquals("A", injector.getInstance(Gogo.class).go());
Assert.assertEquals("B", injector.getInstance(Key.get(Gogo.class, Names.named("reverse"))).go());
// test default property value
Assert.assertEquals("B", injector.getInstance(GogoSally.class).go());
props.setProperty("sally", "a");
Assert.assertEquals("A", injector.getInstance(GogoSally.class).go());
props.setProperty("sally", "b");
Assert.assertEquals("B", injector.getInstance(GogoSally.class).go());
props.setProperty("sally", "c");
try {
injector.getInstance(GogoSally.class).go();
// should never be reached
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof ProvisionException);
Assert.assertTrue(e.getMessage().contains("Unknown provider[c] of Key[type=io.druid.guice.PolyBindTest$GogoSally"));
}
}
use of com.google.inject.Module in project druid by druid-io.
the class PolyBindTest method setUp.
public void setUp(Module... modules) throws Exception {
props = new Properties();
injector = Guice.createInjector(Iterables.concat(Arrays.asList(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(Properties.class).toInstance(props);
PolyBind.createChoice(binder, "billy", Key.get(Gogo.class), Key.get(GoA.class));
PolyBind.createChoiceWithDefault(binder, "sally", Key.get(GogoSally.class), null, "b");
}
}), Arrays.asList(modules)));
}
use of com.google.inject.Module 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()));
}
Aggregations