use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.
the class JankyServersTest method testHttpSilentServerWithRequestTimeout.
@Test
public void testHttpSilentServerWithRequestTimeout() throws Throwable {
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().withReadTimeout(new Duration(86400L * 365)).build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final ListenableFuture<StatusResponseHolder> future = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", silentServerSocket.getLocalPort()))), StatusResponseHandler.getInstance(), new Duration(100L));
Throwable e = null;
try {
future.get();
} catch (ExecutionException e1) {
e = e1.getCause();
}
Assert.assertTrue("ReadTimeoutException thrown by 'get'", e instanceof ReadTimeoutException);
} finally {
lifecycle.stop();
}
}
use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.
the class JankyServersTest method testHttpEchoServer.
@Test
public void testHttpEchoServer() throws Throwable {
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final ListenableFuture<StatusResponseHolder> response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", echoServerSocket.getLocalPort()))), StatusResponseHandler.getInstance());
expectedException.expect(ExecutionException.class);
expectedException.expectMessage("java.lang.IllegalArgumentException: invalid version format: GET");
response.get();
} finally {
lifecycle.stop();
}
}
use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.
the class CustomEmitterFactoryTest method testCustomEmitter.
@Test
public void testCustomEmitter() {
final Properties props = new Properties();
props.put("org.apache.druid.java.util.emitter.stringProperty", "http://example.com/");
props.put("org.apache.druid.java.util.emitter.intProperty", "1");
props.put("org.apache.druid.java.util.emitter.type", "test");
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerSubtypes(TestEmitterConfig.class);
final Lifecycle lifecycle = new Lifecycle();
final Emitter emitter = Emitters.create(props, null, objectMapper, lifecycle);
Assert.assertTrue("created emitter should be of class StubEmitter", emitter instanceof StubEmitter);
StubEmitter stubEmitter = (StubEmitter) emitter;
Assert.assertEquals("http://example.com/", stubEmitter.getStringProperty());
Assert.assertEquals(1, stubEmitter.getIntProperty());
}
use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.
the class RedisCacheProviderWithConfig method testBasicInjection.
@Test
public void testBasicInjection() throws Exception {
String json = "{ \"host\": \"localhost\", \"port\": 6379, \"expiration\": 3600}";
final RedisCacheConfig config = new ObjectMapper().readValue(json, RedisCacheConfig.class);
Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/redis");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
binder.bindConstant().annotatedWith(Names.named("host")).to("localhost");
binder.bindConstant().annotatedWith(Names.named("port")).to(6379);
binder.bind(RedisCacheConfig.class).toInstance(config);
binder.bind(Cache.class).toProvider(RedisCacheProviderWithConfig.class).in(ManageLifecycle.class);
}));
Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
lifecycle.start();
try {
Cache cache = injector.getInstance(Cache.class);
Assert.assertEquals(RedisStandaloneCache.class, cache.getClass());
} finally {
lifecycle.stop();
}
}
use of org.apache.druid.java.util.common.lifecycle.Lifecycle in project druid by druid-io.
the class LifecycleModule method getLifecycle.
@Provides
@LazySingleton
public Lifecycle getLifecycle(final Injector injector) {
final Key<Set<KeyHolder>> keyHolderKey = Key.get(new TypeLiteral<Set<KeyHolder>>() {
}, Names.named("lifecycle"));
final Set<KeyHolder> eagerClasses = injector.getInstance(keyHolderKey);
Lifecycle lifecycle = new Lifecycle("module") {
@Override
public void start() throws Exception {
for (KeyHolder<?> holder : eagerClasses) {
// Pull the key so as to "eagerly" load up the class.
injector.getInstance(holder.getKey());
}
super.start();
}
};
initScope.setLifecycle(lifecycle);
normalScope.setLifecycle(lifecycle);
serverScope.setLifecycle(lifecycle);
annoucementsScope.setLifecycle(lifecycle);
return lifecycle;
}
Aggregations