use of com.google.inject.Binder 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.Binder in project druid by druid-io.
the class NamespaceLookupExtractorFactoryTest method testSimpleIntrospectionHandler.
@Test
public void testSimpleIntrospectionHandler() throws Exception {
final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {
@Override
public void configure(Binder binder) {
JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
}
}));
final ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
mapper.registerSubtypes(NamespaceLookupExtractorFactory.class);
final String str = "{ \"type\": \"cachedNamespace\", \"extractionNamespace\": { \"type\": \"staticMap\", \"map\": {\"foo\":\"bar\"} }, \"firstCacheTimeout\":10000 }";
final LookupExtractorFactory lookupExtractorFactory = mapper.readValue(str, LookupExtractorFactory.class);
Assert.assertTrue(lookupExtractorFactory.start());
try {
final LookupIntrospectHandler handler = lookupExtractorFactory.getIntrospectHandler();
Assert.assertNotNull(handler);
final Class<? extends LookupIntrospectHandler> clazz = handler.getClass();
Assert.assertNotNull(clazz.getMethod("getVersion").invoke(handler));
Assert.assertEquals(ImmutableSet.of("foo"), ((Response) clazz.getMethod("getKeys").invoke(handler)).getEntity());
Assert.assertEquals(ImmutableSet.of("bar"), ((Response) clazz.getMethod("getValues").invoke(handler)).getEntity());
Assert.assertEquals(ImmutableMap.builder().put("foo", "bar").build(), ((Response) clazz.getMethod("getMap").invoke(handler)).getEntity());
} finally {
Assert.assertTrue(lookupExtractorFactory.close());
}
}
use of com.google.inject.Binder in project druid by druid-io.
the class OffHeapNamespaceExtractionCacheManagerTest method testInjection.
@Test
public void testInjection() {
final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {
@Override
public void configure(Binder binder) {
JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
}
}));
final Properties properties = injector.getInstance(Properties.class);
properties.clear();
properties.put(NamespaceExtractionModule.TYPE_PREFIX, "offHeap");
final NamespaceExtractionCacheManager manager = injector.getInstance(NamespaceExtractionCacheManager.class);
Assert.assertEquals(OffHeapNamespaceExtractionCacheManager.class, manager.getClass());
}
use of com.google.inject.Binder in project druid by druid-io.
the class OnHeapNamespaceExtractionCacheManagerTest method testInjection.
@Test
public void testInjection() {
final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {
@Override
public void configure(Binder binder) {
JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
}
}));
final Properties properties = injector.getInstance(Properties.class);
properties.clear();
properties.put(NamespaceExtractionModule.TYPE_PREFIX, "onHeap");
final NamespaceExtractionCacheManager manager = injector.getInstance(NamespaceExtractionCacheManager.class);
Assert.assertEquals(OnHeapNamespaceExtractionCacheManager.class, manager.getClass());
}
use of com.google.inject.Binder in project druid by druid-io.
the class IngestSegmentFirehoseFactoryTimelineTest method constructorFeeder.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> constructorFeeder() {
final List<TestCase> testCases = ImmutableList.of(TC("2000/2000T02", 3, 7, DS("2000/2000T01", "v1", 0, IR("2000", 1), IR("2000T00:01", 2)), DS("2000T01/2000T02", "v1", 0, IR("2000T01", 4))), /* Adjacent segments */
TC("2000/2000T02", 3, 7, DS("2000/2000T02", "v1", 0, IR("2000", 1), IR("2000T00:01", 2), IR("2000T01", 8)), DS("2000T01/2000T02", "v2", 0, IR("2000T01:01", 4))), /* 1H segment overlaid on top of 2H segment */
TC("2000/2000-01-02", 4, 23, DS("2000/2000-01-02", "v1", 0, IR("2000", 1), IR("2000T00:01", 2), IR("2000T01", 8), IR("2000T02", 16)), DS("2000T01/2000T02", "v2", 0, IR("2000T01:01", 4))), /* 1H segment overlaid on top of 1D segment */
TC("2000/2000T02", 4, 15, DS("2000/2000T02", "v1", 0, IR("2000", 1), IR("2000T00:01", 2), IR("2000T01", 8)), DS("2000/2000T02", "v1", 1, IR("2000T01:01", 4))), /* Segment set with two segments for the same interval */
TC("2000T01/2000T02", 1, 2, DS("2000/2000T03", "v1", 0, IR("2000", 1), IR("2000T01", 2), IR("2000T02", 4))), /* Segment wider than desired interval */
TC("2000T02/2000T04", 2, 12, DS("2000/2000T03", "v1", 0, IR("2000", 1), IR("2000T01", 2), IR("2000T02", 4)), DS("2000T03/2000T04", "v1", 0, IR("2000T03", 8))));
final List<Object[]> constructors = Lists.newArrayList();
for (final TestCase testCase : testCases) {
final TaskActionClient taskActionClient = new TaskActionClient() {
@Override
public <RetType> RetType submit(TaskAction<RetType> taskAction) throws IOException {
if (taskAction instanceof SegmentListUsedAction) {
// Expect the interval we asked for
final SegmentListUsedAction action = (SegmentListUsedAction) taskAction;
if (action.getIntervals().equals(ImmutableList.of(testCase.interval))) {
return (RetType) ImmutableList.copyOf(testCase.segments);
} else {
throw new IllegalArgumentException("WTF");
}
} else {
throw new UnsupportedOperationException();
}
}
};
SegmentHandoffNotifierFactory notifierFactory = EasyMock.createNiceMock(SegmentHandoffNotifierFactory.class);
EasyMock.replay(notifierFactory);
final TaskToolboxFactory taskToolboxFactory = new TaskToolboxFactory(new TaskConfig(testCase.tmpDir.getAbsolutePath(), null, null, 50000, null, false, null, null), new TaskActionClientFactory() {
@Override
public TaskActionClient create(Task task) {
return taskActionClient;
}
}, new NoopServiceEmitter(), // segment pusher
null, // segment killer
null, // segment mover
null, // segment archiver
null, // segment announcer,
null, notifierFactory, // query runner factory conglomerate corporation unionized collective
null, // query executor service
null, // monitor scheduler
null, new SegmentLoaderFactory(new SegmentLoaderLocalCacheManager(null, new SegmentLoaderConfig() {
@Override
public List<StorageLocationConfig> getLocations() {
return Lists.newArrayList();
}
}, MAPPER)), MAPPER, INDEX_MERGER, INDEX_IO, null, null, INDEX_MERGER_V9);
final Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(TaskToolboxFactory.class).toInstance(taskToolboxFactory);
}
});
final IngestSegmentFirehoseFactory factory = new IngestSegmentFirehoseFactory(DATA_SOURCE, testCase.interval, new NoopDimFilter(), Arrays.asList(DIMENSIONS), Arrays.asList(METRICS), injector, INDEX_IO);
constructors.add(new Object[] { testCase.toString(), factory, testCase.tmpDir, testCase.expectedCount, testCase.expectedSum });
}
return constructors;
}
Aggregations