diff --git a/indexing-hadoop/src/test/java/org/apache/druid/indexer/DeterminePartitionsJobSamplerTest.java b/indexing-hadoop/src/test/java/org/apache/druid/indexer/DeterminePartitionsJobSamplerTest.java index 21f6be8114d..16b3894244a 100644 --- a/indexing-hadoop/src/test/java/org/apache/druid/indexer/DeterminePartitionsJobSamplerTest.java +++ b/indexing-hadoop/src/test/java/org/apache/druid/indexer/DeterminePartitionsJobSamplerTest.java @@ -76,7 +76,7 @@ public class DeterminePartitionsJobSamplerTest } double expect = total * 1.0 / samplingFactor; double error = Math.abs(hit - expect) / expect; - Assert.assertTrue(error < 0.01); + Assert.assertTrue(String.valueOf(error), error < 0.02); } @Test @@ -97,6 +97,6 @@ public class DeterminePartitionsJobSamplerTest } double expect = total * 1.0 / samplingFactor; double error = Math.abs(hit - expect) / expect; - Assert.assertTrue(error < 0.01); + Assert.assertTrue(String.valueOf(error), error < 0.02); } } diff --git a/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyBindings.java b/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyBindings.java index 9fc26a73bec..d955ce98484 100644 --- a/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyBindings.java +++ b/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyBindings.java @@ -94,10 +94,15 @@ public class JettyBindings @Override public Map getInitParameters() { - if (timeoutMs >= 0) { - return ImmutableMap.of("maxRequests", String.valueOf(maxRequests), "suspendMs", String.valueOf(timeoutMs)); + if (timeoutMs < 0) { + return ImmutableMap.of("maxRequests", String.valueOf(maxRequests)); } - return ImmutableMap.of("maxRequests", String.valueOf(maxRequests)); + if (timeoutMs > Integer.MAX_VALUE) { + // QoSFilter tries to parse the suspendMs parameter as an int, so we can't set it to more than Integer + // .MAX_VALUE. + return ImmutableMap.of("maxRequests", String.valueOf(maxRequests), "suspendMs", String.valueOf(Integer.MAX_VALUE)); + } + return ImmutableMap.of("maxRequests", String.valueOf(maxRequests), "suspendMs", String.valueOf(timeoutMs)); } @Override diff --git a/server/src/test/java/org/apache/druid/server/initialization/JettyQosTest.java b/server/src/test/java/org/apache/druid/server/initialization/JettyQosTest.java index e9f7fc016ad..b0fea90bc44 100644 --- a/server/src/test/java/org/apache/druid/server/initialization/JettyQosTest.java +++ b/server/src/test/java/org/apache/druid/server/initialization/JettyQosTest.java @@ -22,6 +22,7 @@ package org.apache.druid.server.initialization; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterators; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Binder; import com.google.inject.Injector; @@ -45,12 +46,16 @@ import org.apache.druid.server.initialization.jetty.JettyServerInitializer; import org.apache.druid.server.security.AuthTestUtils; import org.apache.druid.server.security.AuthorizerMapper; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlets.QoSFilter; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.jboss.netty.handler.codec.http.HttpMethod; import org.junit.Assert; import org.junit.Test; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; import java.net.URL; +import java.util.Enumeration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicLong; @@ -193,4 +198,58 @@ public class JettyQosTest extends BaseJettyTest // check that fast requests finished quickly Assert.assertTrue(fastElapsed.get() / fastCount.get() < 500); } + + @Test + public void testQoSFilterMaxTimeout() + { + QoSFilter filter = new QoSFilter(); + JettyBindings.QosFilterHolder qosFilterHolder = new JettyBindings.QosFilterHolder(new String[]{"/slow/*"}, 1, + Long.MAX_VALUE + ); + filter.init(new QoSFilterConfig(qosFilterHolder)); + Assert.assertEquals(Integer.MAX_VALUE, filter.getSuspendMs()); + } + + @Test + public void testQoSFilterNoTimeout() + { + QoSFilter filter = new QoSFilter(); + JettyBindings.QosFilterHolder qosFilterHolder = new JettyBindings.QosFilterHolder(new String[]{"/slow/*"}, 1); + filter.init(new QoSFilterConfig(qosFilterHolder)); + Assert.assertEquals(-1, filter.getSuspendMs()); + } + + private static class QoSFilterConfig implements FilterConfig + { + private JettyBindings.QosFilterHolder qosFilterHolder; + + public QoSFilterConfig(JettyBindings.QosFilterHolder qosFilterHolder) + { + this.qosFilterHolder = qosFilterHolder; + } + + @Override + public String getFilterName() + { + return "dummy"; + } + + @Override + public ServletContext getServletContext() + { + return null; + } + + @Override + public String getInitParameter(String name) + { + return qosFilterHolder.getInitParameters().get(name); + } + + @Override + public Enumeration getInitParameterNames() + { + return Iterators.asEnumeration(qosFilterHolder.getInitParameters().keySet().iterator()); + } + } }