Search in sources :

Example 11 with UnitEvent

use of org.apache.druid.java.util.emitter.service.UnitEvent 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());
}
Also used : Response(org.asynchttpclient.Response) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) Test(org.junit.Test)

Example 12 with UnitEvent

use of org.apache.druid.java.util.emitter.service.UnitEvent 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());
}
Also used : Response(org.asynchttpclient.Response) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) Test(org.junit.Test)

Aggregations

UnitEvent (org.apache.druid.java.util.emitter.service.UnitEvent)12 Test (org.junit.Test)12 Request (org.asynchttpclient.Request)10 Response (org.asynchttpclient.Response)10 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)7 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DefaultPasswordProvider (org.apache.druid.metadata.DefaultPasswordProvider)1 ListenableFuture (org.asynchttpclient.ListenableFuture)1