use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class JettyTest method testNumConnectionsMetricHttp.
@Test
public void testNumConnectionsMetricHttp() throws Exception {
String text = "hello";
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(out)) {
gzipOutputStream.write(text.getBytes(Charset.defaultCharset()));
}
Request request = new Request(HttpMethod.GET, new URL("http://localhost:" + port + "/latched/hello"));
request.setHeader("Content-Encoding", "gzip");
request.setContent(MediaType.TEXT_PLAIN, out.toByteArray());
JettyServerModule jsm = injector.getInstance(JettyServerModule.class);
latchedRequestState.reset();
waitForJettyServerModuleActiveConnectionsZero(jsm);
Assert.assertEquals(0, jsm.getActiveConnections());
ListenableFuture<InputStream> go = client.go(request, new InputStreamResponseHandler());
latchedRequestState.clientWaitForServerToStartRequest();
Assert.assertEquals(1, jsm.getActiveConnections());
latchedRequestState.clientReadyToFinishRequest();
go.get();
waitForJettyServerModuleActiveConnectionsZero(jsm);
Assert.assertEquals(0, jsm.getActiveConnections());
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class JettyTest method testTimeouts.
@Test
// this test will deadlock if it hits an issue, so ignored by default
@Ignore
public void testTimeouts() throws Exception {
// test for request timeouts properly not locking up all threads
final ExecutorService executor = Executors.newFixedThreadPool(100);
final AtomicLong count = new AtomicLong(0);
final CountDownLatch latch = new CountDownLatch(1000);
for (int i = 0; i < 10000; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
executor.execute(new Runnable() {
@Override
public void run() {
long startTime = System.currentTimeMillis();
long startTime2 = 0;
try {
ListenableFuture<StatusResponseHolder> go = client.go(new Request(HttpMethod.GET, new URL("http://localhost:" + port + "/slow/hello")), StatusResponseHandler.getInstance());
startTime2 = System.currentTimeMillis();
go.get();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.printf(Locale.ENGLISH, "Response time client%dtime taken for getting future%dCounter %d%n", System.currentTimeMillis() - startTime, System.currentTimeMillis() - startTime2, count.incrementAndGet());
latch.countDown();
}
}
});
}
});
}
latch.await();
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class DruidLeaderClient method withUrl.
private Request withUrl(Request old, URL url) {
Request req = new Request(old.getMethod(), url);
req.addHeaderValues(old.getHeaders());
if (old.hasContent()) {
req.setContent(old.getContent());
}
return req;
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class LookupReferencesManagerTest method testCoordinatorLookupSync.
@Test
public void testCoordinatorLookupSync() throws Exception {
LookupExtractorFactoryContainer container1 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key1", "value1"), true));
LookupExtractorFactoryContainer container2 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key2", "value2"), true));
LookupExtractorFactoryContainer container3 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key3", "value3"), true));
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testLookup1", container1);
lookupMap.put("testLookup2", container2);
lookupMap.put("testLookup3", container3);
String strResult = mapper.writeValueAsString(lookupMap);
Request request = new Request(HttpMethod.GET, new URL("http://localhost:1234/xx"));
EasyMock.expect(config.getLookupTier()).andReturn(LOOKUP_TIER).anyTimes();
EasyMock.replay(config);
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/coordinator/v1/lookups/config/lookupTier?detailed=true")).andReturn(request);
StringFullResponseHolder responseHolder = new StringFullResponseHolder(newEmptyResponse(HttpResponseStatus.OK), StandardCharsets.UTF_8).addChunk(strResult);
EasyMock.expect(druidLeaderClient.go(request)).andReturn(responseHolder);
EasyMock.replay(druidLeaderClient);
lookupReferencesManager.start();
Assert.assertEquals(Optional.of(container1), lookupReferencesManager.get("testLookup1"));
Assert.assertEquals(Optional.of(container2), lookupReferencesManager.get("testLookup2"));
Assert.assertEquals(Optional.of(container3), lookupReferencesManager.get("testLookup3"));
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class LookupReferencesManagerTest method testGetAllLookupNames.
@Test
public void testGetAllLookupNames() throws Exception {
LookupExtractorFactoryContainer container1 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key1", "value1"), true));
LookupExtractorFactoryContainer container2 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key2", "value2"), true));
Map<String, Object> lookupMap = new HashMap<>();
String strResult = mapper.writeValueAsString(lookupMap);
Request request = new Request(HttpMethod.GET, new URL("http://localhost:1234/xx"));
EasyMock.expect(config.getLookupTier()).andReturn(LOOKUP_TIER).anyTimes();
EasyMock.replay(config);
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/coordinator/v1/lookups/config/lookupTier?detailed=true")).andReturn(request);
StringFullResponseHolder responseHolder = new StringFullResponseHolder(newEmptyResponse(HttpResponseStatus.OK), StandardCharsets.UTF_8).addChunk(strResult);
EasyMock.expect(druidLeaderClient.go(request)).andReturn(responseHolder);
EasyMock.replay(druidLeaderClient);
lookupReferencesManager.start();
lookupReferencesManager.add("one", container1);
lookupReferencesManager.add("two", container2);
lookupReferencesManager.handlePendingNotices();
Assert.assertEquals(ImmutableSet.of("one", "two"), lookupReferencesManager.getAllLookupNames());
Assert.assertEquals(ImmutableSet.of("one", "two"), ((LookupExtractorFactoryContainerProvider) lookupReferencesManager).getAllLookupNames());
}
Aggregations