use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class ITWikipediaQueryTest method testQueryLaningLaneIsLimited.
@Test
public void testQueryLaningLaneIsLimited() throws Exception {
ITRetryUtil.retryUntil(() -> {
// the broker is configured with a manually defined query lane, 'one' with limit 1
// -Ddruid.query.scheduler.laning.type=manual
// -Ddruid.query.scheduler.laning.lanes.one=1
// by issuing 50 queries, at least 1 of them will succeed on 'one', and at least 1 of them will overlap enough to
// get limited.
// It's possible but unlikely that these queries execute in a way that none of them overlap, so we
// retry this test a few times to compensate for this.
final int numQueries = 50;
List<Future<StatusResponseHolder>> futures = new ArrayList<>(numQueries);
for (int i = 0; i < numQueries; i++) {
futures.add(queryClient.queryAsync(queryHelper.getQueryURL(config.getBrokerUrl()), getQueryBuilder().build()));
}
int success = 0;
int limited = 0;
for (Future<StatusResponseHolder> future : futures) {
StatusResponseHolder status = future.get();
if (status.getStatus().getCode() == QueryCapacityExceededException.STATUS_CODE) {
limited++;
Assert.assertTrue(status.getContent().contains(QueryCapacityExceededException.makeLaneErrorMessage("one", 1)));
} else if (status.getStatus().getCode() == HttpResponseStatus.OK.getCode()) {
success++;
}
}
try {
Assert.assertTrue(success > 0);
Assert.assertTrue(limited > 0);
return true;
} catch (AssertionError ae) {
LOG.error(ae, "Got assertion error in testQueryLaningLaneIsLimited");
return false;
}
}, true, 5000, 3, "testQueryLaningLaneIsLimited");
// test another to make sure we can still issue one query at a time
StatusResponseHolder followUp = queryClient.queryAsync(queryHelper.getQueryURL(config.getBrokerUrl()), getQueryBuilder().build()).get();
Assert.assertEquals(followUp.getStatus().getCode(), HttpResponseStatus.OK.getCode());
StatusResponseHolder andAnother = queryClient.queryAsync(queryHelper.getQueryURL(config.getBrokerUrl()), getQueryBuilder().build()).get();
Assert.assertEquals(andAnother.getStatus().getCode(), HttpResponseStatus.OK.getCode());
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class ITWikipediaQueryTest method testQueryLaningWithNoLane.
@Test
public void testQueryLaningWithNoLane() throws Exception {
// the broker is configured with a manually defined query lane, 'one' with limit 1
// -Ddruid.query.scheduler.laning.type=manual
// -Ddruid.query.scheduler.laning.lanes.one=1
// these queries will not belong to the lane so none of them should be limited
final int numQueries = 50;
List<Future<StatusResponseHolder>> futures = new ArrayList<>(numQueries);
for (int i = 0; i < numQueries; i++) {
futures.add(queryClient.queryAsync(queryHelper.getQueryURL(config.getBrokerUrl()), getQueryBuilder().context(ImmutableMap.of("queryId", UUID.randomUUID().toString())).build()));
}
int success = 0;
int limited = 0;
for (Future<StatusResponseHolder> future : futures) {
StatusResponseHolder status = future.get();
if (status.getStatus().getCode() == QueryCapacityExceededException.STATUS_CODE) {
limited++;
} else if (status.getStatus().getCode() == HttpResponseStatus.OK.getCode()) {
success++;
}
}
Assert.assertTrue(success > 0);
Assert.assertEquals(limited, 0);
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class ITHighAvailabilityTest method testSelfDiscovery.
private int testSelfDiscovery(Collection<DiscoveryDruidNode> nodes) throws MalformedURLException, ExecutionException, InterruptedException {
int count = 0;
for (DiscoveryDruidNode node : nodes) {
final String location = StringUtils.format("http://%s:%s/status/selfDiscovered", config.isDocker() ? config.getDockerHost() : node.getDruidNode().getHost(), node.getDruidNode().getPlaintextPort());
LOG.info("testing self discovery %s", location);
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(location)), StatusResponseHandler.getInstance()).get();
LOG.info("%s responded with %s", location, response.getStatus().getCode());
Assert.assertEquals(response.getStatus(), HttpResponseStatus.OK);
count++;
}
return count;
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class FriendlyServersTest method testFriendlyProxyHttpServer.
@Test
public void testFriendlyProxyHttpServer() throws Exception {
final AtomicReference<String> requestContent = new AtomicReference<>();
final ExecutorService exec = Executors.newSingleThreadExecutor();
final ServerSocket serverSocket = new ServerSocket(0);
exec.submit(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try (Socket clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8));
OutputStream out = clientSocket.getOutputStream()) {
StringBuilder request = new StringBuilder();
String line;
while (!"".equals((line = in.readLine()))) {
request.append(line).append("\r\n");
}
requestContent.set(request.toString());
out.write("HTTP/1.1 200 OK\r\n\r\n".getBytes(StandardCharsets.UTF_8));
while (!in.readLine().equals("")) {
// skip lines
}
out.write("HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\nhello!".getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
Assert.fail(e.toString());
}
}
}
});
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().withHttpProxyConfig(new HttpClientProxyConfig("localhost", serverSocket.getLocalPort(), "bob", "sally")).build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final StatusResponseHolder response = client.go(new Request(HttpMethod.GET, new URL("http://anotherHost:8080/")), StatusResponseHandler.getInstance()).get();
Assert.assertEquals(200, response.getStatus().getCode());
Assert.assertEquals("hello!", response.getContent());
Assert.assertEquals("CONNECT anotherHost:8080 HTTP/1.1\r\nProxy-Authorization: Basic Ym9iOnNhbGx5\r\n", requestContent.get());
} finally {
exec.shutdownNow();
serverSocket.close();
lifecycle.stop();
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class FriendlyServersTest method testFriendlyHttpServer.
@Test
public void testFriendlyHttpServer() throws Exception {
final ExecutorService exec = Executors.newSingleThreadExecutor();
final ServerSocket serverSocket = new ServerSocket(0);
exec.submit(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try (Socket clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8));
OutputStream out = clientSocket.getOutputStream()) {
while (!in.readLine().equals("")) {
// skip lines
}
out.write("HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\nhello!".getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
// Suppress
}
}
}
});
final Lifecycle lifecycle = new Lifecycle();
try {
final HttpClientConfig config = HttpClientConfig.builder().build();
final HttpClient client = HttpClientInit.createClient(config, lifecycle);
final StatusResponseHolder response = client.go(new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort()))), StatusResponseHandler.getInstance()).get();
Assert.assertEquals(200, response.getStatus().getCode());
Assert.assertEquals("hello!", response.getContent());
} finally {
exec.shutdownNow();
serverSocket.close();
lifecycle.stop();
}
}
Aggregations