use of org.asynchttpclient.Response in project druid by druid-io.
the class EmitterTest method testSanity.
@Test
public void testSanity() throws Exception {
final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1), new UnitEvent("test", 2));
emitter = sizeBasedEmitter(2);
httpClient.setGoHandler(new GoHandler() {
@Override
protected ListenableFuture<Response> go(Request request) throws JsonProcessingException {
Assert.assertEquals(TARGET_URL, request.getUrl());
Assert.assertEquals("application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE));
Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
return GoHandlers.immediateFuture(okResponse());
}
}.times(1));
for (UnitEvent event : events) {
emitter.emit(event);
}
waitForEmission(emitter, 1);
closeNoFlush(emitter);
Assert.assertTrue(httpClient.succeeded());
}
use of org.asynchttpclient.Response in project druid by druid-io.
the class EmitterTest method testGzipContentEncoding.
@Test
public void testGzipContentEncoding() throws Exception {
final List<UnitEvent> events = Arrays.asList(new UnitEvent("plain-text", 1), new UnitEvent("plain-text", 2));
emitter = sizeBasedEmitterWithContentEncoding(2, ContentEncoding.GZIP);
httpClient.setGoHandler(new GoHandler() {
@Override
protected ListenableFuture<Response> go(Request request) throws IOException {
Assert.assertEquals(TARGET_URL, request.getUrl());
Assert.assertEquals("application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE));
Assert.assertEquals(HttpHeaders.Values.GZIP, request.getHeaders().get(HttpHeaders.Names.CONTENT_ENCODING));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteBuffer data = request.getByteBufferData().slice();
byte[] dataArray = new byte[data.remaining()];
data.get(dataArray);
CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos);
Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), baos.toString(StandardCharsets.UTF_8.name()));
return GoHandlers.immediateFuture(okResponse());
}
}.times(1));
for (UnitEvent event : events) {
emitter.emit(event);
}
waitForEmission(emitter, 1);
closeNoFlush(emitter);
Assert.assertTrue(httpClient.succeeded());
}
use of org.asynchttpclient.Response in project druid by druid-io.
the class ParametrizedUriEmitterTest method testEmitterWithFeedUriExtractor.
@Test
public void testEmitterWithFeedUriExtractor() throws Exception {
Emitter emitter = parametrizedEmmiter("http://example.com/{feed}");
final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1), new UnitEvent("test", 2));
httpClient.setGoHandler(new GoHandler() {
@Override
public ListenableFuture<Response> go(Request request) throws JsonProcessingException {
Assert.assertEquals("http://example.com/test", request.getUrl());
Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
return GoHandlers.immediateFuture(EmitterTest.okResponse());
}
}.times(1));
for (UnitEvent event : events) {
emitter.emit(event);
}
emitter.flush();
Assert.assertTrue(httpClient.succeeded());
}
use of org.asynchttpclient.Response in project druid by druid-io.
the class ParametrizedUriEmitterTest method testEmitterWithParametrizedUriExtractor.
@Test
public void testEmitterWithParametrizedUriExtractor() throws Exception {
Emitter emitter = parametrizedEmmiter("http://example.com/{key1}/{key2}");
final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1, ImmutableMap.of("key1", "val1", "key2", "val2")), new UnitEvent("test", 2, ImmutableMap.of("key1", "val1", "key2", "val2")));
httpClient.setGoHandler(new GoHandler() {
@Override
protected ListenableFuture<Response> go(Request request) throws JsonProcessingException {
Assert.assertEquals("http://example.com/val1/val2", request.getUrl());
Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
return GoHandlers.immediateFuture(EmitterTest.okResponse());
}
}.times(1));
for (UnitEvent event : events) {
emitter.emit(event);
}
emitter.flush();
Assert.assertTrue(httpClient.succeeded());
}
use of org.asynchttpclient.Response in project killbill by killbill.
the class KillBillAuth0Realm method findAuth0UserPermissions.
private Set<String> findAuth0UserPermissions(final String userId, final String token) {
final String path;
try {
path = "/api/v2/users/" + URLEncoder.encode(userId, "UTF-8") + "/permissions";
} catch (final UnsupportedEncodingException e) {
// Should never happen
throw new IllegalStateException(e);
}
final Response auth0RawResponse = doGetRequest(path, token);
try {
final List<Map<String, Object>> auth0Response = mapper.readValue(auth0RawResponse.getResponseBodyAsStream(), new TypeReference<List<Map<String, Object>>>() {
});
final Set<String> permissions = new HashSet<String>();
for (final Map<String, Object> group : auth0Response) {
final Object permission = group.get("permission_name");
if (permission != null) {
permissions.add((String) permission);
}
}
return permissions;
} catch (final IOException e) {
log.warn("Unable to read response from Auth0", e);
throw new AuthorizationException(e);
}
}
Aggregations