fix test initialization

This commit is contained in:
Xavier Léauté 2014-08-18 13:37:47 -07:00
parent 1fd30ab588
commit 78054d7f05
1 changed files with 35 additions and 38 deletions

View File

@ -20,11 +20,12 @@
package io.druid.server.initialization; package io.druid.server.initialization;
import com.google.api.client.repackaged.com.google.common.base.Throwables; import com.google.api.client.repackaged.com.google.common.base.Throwables;
import com.google.common.collect.Lists; import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.servlet.GuiceFilter; import com.google.inject.servlet.GuiceFilter;
import com.metamx.common.lifecycle.Lifecycle; import com.metamx.common.lifecycle.Lifecycle;
@ -33,10 +34,14 @@ import com.metamx.http.client.response.InputStreamResponseHandler;
import com.metamx.http.client.response.StatusResponseHandler; import com.metamx.http.client.response.StatusResponseHandler;
import com.metamx.http.client.response.StatusResponseHolder; import com.metamx.http.client.response.StatusResponseHolder;
import io.druid.guice.Jerseys; import io.druid.guice.Jerseys;
import io.druid.guice.JsonConfigProvider;
import io.druid.guice.LazySingleton; import io.druid.guice.LazySingleton;
import io.druid.guice.LifecycleModule;
import io.druid.guice.annotations.Global; import io.druid.guice.annotations.Global;
import io.druid.guice.GuiceInjectors; import io.druid.guice.GuiceInjectors;
import io.druid.guice.annotations.Self;
import io.druid.initialization.Initialization; import io.druid.initialization.Initialization;
import io.druid.server.DruidNode;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
@ -78,10 +83,7 @@ public class JettyTest
public static void setProperties() public static void setProperties()
{ {
System.setProperty("druid.host", "localhost:9999");
System.setProperty("druid.port", "9999");
System.setProperty("druid.server.http.numThreads", "20"); System.setProperty("druid.server.http.numThreads", "20");
System.setProperty("druid.service", "test");
System.setProperty("druid.server.http.maxIdleTime", "PT1S"); System.setProperty("druid.server.http.maxIdleTime", "PT1S");
System.setProperty("druid.global.http.readTimeout", "PT1S"); System.setProperty("druid.global.http.readTimeout", "PT1S");
} }
@ -91,22 +93,24 @@ public class JettyTest
{ {
setProperties(); setProperties();
Injector injector = Initialization.makeInjectorWithModules( Injector injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(), Lists.<Object>newArrayList( GuiceInjectors.makeStartupInjector(), ImmutableList.<Object>of(
new Module() new Module()
{ {
@Override @Override
public void configure(Binder binder) public void configure(Binder binder)
{ {
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", 9999)
);
binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class); binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
Jerseys.addResource(binder, SlowResource.class); Jerseys.addResource(binder, SlowResource.class);
Jerseys.addResource(binder, ExceptionResource.class); Jerseys.addResource(binder, ExceptionResource.class);
LifecycleModule.register(binder, Server.class);
} }
} }
) )
); );
lifecycle = injector.getInstance(Lifecycle.class); lifecycle = injector.getInstance(Lifecycle.class);
// Jetty is Lazy Initialized do a getInstance
injector.getInstance(Server.class);
lifecycle.start(); lifecycle.start();
ClientHolder holder = injector.getInstance(ClientHolder.class); ClientHolder holder = injector.getInstance(ClientHolder.class);
client = holder.getClient(); client = holder.getClient();
@ -136,11 +140,8 @@ public class JettyTest
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
long startTime2 = 0; long startTime2 = 0;
try { try {
ListenableFuture<StatusResponseHolder> go = client.get( ListenableFuture<StatusResponseHolder> go =
new URL( client.get(new URL("http://localhost:9999/slow/hello"))
"http://localhost:9999/slow/hello"
)
)
.go(new StatusResponseHandler(Charset.defaultCharset())); .go(new StatusResponseHandler(Charset.defaultCharset()));
startTime2 = System.currentTimeMillis(); startTime2 = System.currentTimeMillis();
go.get(); go.get();
@ -178,12 +179,8 @@ public class JettyTest
// above bug is not fixed in jetty for gzip encoding, and the chunk is still finalized instead of throwing exception. // above bug is not fixed in jetty for gzip encoding, and the chunk is still finalized instead of throwing exception.
public void testChunkNotFinalized() throws Exception public void testChunkNotFinalized() throws Exception
{ {
ListenableFuture<InputStream> go = client.get( ListenableFuture<InputStream> go =
new URL( client.get(new URL("http://localhost:9999/exception/exception"))
"http://localhost:9999/exception/exception"
)
)
.go(new InputStreamResponseHandler()); .go(new InputStreamResponseHandler());
try { try {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();