Search in sources :

Example 1 with EventReceiverFirehoseTestClient

use of org.apache.druid.testing.clients.EventReceiverFirehoseTestClient in project druid by druid-io.

the class ITAppenderatorDriverRealtimeIndexTaskTest method postEvents.

@Override
void postEvents() throws Exception {
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_NAME);
    eventReceiverSelector.start();
    InputStreamReader isr;
    try {
        isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE), StandardCharsets.UTF_8);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    try (BufferedReader reader = new BufferedReader(isr)) {
        ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
        // Use the host from the config file and the port announced in zookeeper
        String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
        LOG.info("Event Receiver Found at host [%s]", host);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_NAME, jsonMapper, httpClient, smileMapper);
        // there are 22 lines in the file
        int i = 1;
        // timestamp used for sending each event
        DateTime dt = DateTimes.nowUtc();
        dtFirst = dt;
        dtLast = dt;
        String line;
        while ((line = reader.readLine()) != null) {
            if (i == 15) {
                // for the 15th line, use a time before the window
                dt = dt.minusMinutes(10);
                // oldest timestamp
                dtFirst = dt;
            } else if (i == 16) {
                // remember this time to use in the expected response from the groupBy query
                dtGroupBy = dt;
            } else if (i == 18) {
                // use a time 6 seconds ago so it will be out of order
                dt = dt.minusSeconds(6);
            }
            String event = StringUtils.replace(line, TIME_PLACEHOLDER, EVENT_FMT.print(dt));
            LOG.info("sending event: [%s]\n", event);
            Collection<Map<String, Object>> events = new ArrayList<>();
            events.add(this.jsonMapper.readValue(event, JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT));
            int eventsPosted = client.postEvents(events, this.jsonMapper, MediaType.APPLICATION_JSON);
            if (eventsPosted != events.size()) {
                throw new ISE("Event not posted");
            }
            try {
                Thread.sleep(DELAY_BETWEEN_EVENTS_SECS * 1000);
            } catch (InterruptedException ignored) {
            /* nothing */
            }
            // latest timestamp
            dtLast = dt;
            dt = DateTimes.nowUtc();
            i++;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        eventReceiverSelector.stop();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) ServerDiscoverySelector(org.apache.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(org.apache.druid.testing.clients.EventReceiverFirehoseTestClient) BufferedReader(java.io.BufferedReader) ISE(org.apache.druid.java.util.common.ISE) Map(java.util.Map)

Example 2 with EventReceiverFirehoseTestClient

use of org.apache.druid.testing.clients.EventReceiverFirehoseTestClient in project druid by druid-io.

the class ITUnionQueryTest method postEvents.

private void postEvents(int id) throws Exception {
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_PREFIX + id);
    eventReceiverSelector.start();
    try {
        ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
        // Access the docker VM mapped host and port instead of service announced in zookeeper
        String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
        LOG.info("Event Receiver Found at host [%s]", host);
        LOG.info("Checking worker /status/health for [%s]", host);
        ITRetryUtil.retryUntilTrue(() -> {
            try {
                StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://%s/status/health", host))), StatusResponseHandler.getInstance()).get();
                return response.getStatus().equals(HttpResponseStatus.OK);
            } catch (Throwable e) {
                LOG.error(e, "");
                return false;
            }
        }, StringUtils.format("Checking /status/health for worker [%s]", host));
        LOG.info("Finished checking worker /status/health for [%s], success", host);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_PREFIX + id, jsonMapper, httpClient, smileMapper);
        client.postEventsFromFile(UNION_DATA_FILE);
    } finally {
        eventReceiverSelector.stop();
    }
}
Also used : ServerDiscoverySelector(org.apache.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(org.apache.druid.testing.clients.EventReceiverFirehoseTestClient) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL)

Example 3 with EventReceiverFirehoseTestClient

use of org.apache.druid.testing.clients.EventReceiverFirehoseTestClient in project druid by druid-io.

the class ITRealtimeIndexTaskTest method postEvents.

@Override
void postEvents() throws Exception {
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_NAME);
    eventReceiverSelector.start();
    InputStreamReader isr;
    try {
        isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE), StandardCharsets.UTF_8);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    try (BufferedReader reader = new BufferedReader(isr)) {
        ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
        // Use the host from the config file and the port announced in zookeeper
        String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
        LOG.info("Event Receiver Found at host [%s]", host);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_NAME, jsonMapper, httpClient, smileMapper);
        // there are 22 lines in the file
        int i = 1;
        // timestamp used for sending each event
        DateTime dt = DateTimes.nowUtc();
        // timestamp of 1st event
        dtFirst = dt;
        // timestamp of last event
        dtLast = dt;
        String line;
        while ((line = reader.readLine()) != null) {
            if (i == 15) {
                // for the 15th line, use a time before the window
                dt = dt.minusMinutes(10);
            } else if (i == 16) {
                // remember this time to use in the expected response from the groupBy query
                dtGroupBy = dt;
            } else if (i == 18) {
                // use a time 6 seconds ago so it will be out of order
                dt = dt.minusSeconds(6);
            }
            String event = StringUtils.replace(line, TIME_PLACEHOLDER, EVENT_FMT.print(dt));
            LOG.info("sending event: [%s]\n", event);
            Collection<Map<String, Object>> events = new ArrayList<>();
            events.add(this.jsonMapper.readValue(event, JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT));
            int eventsPosted = client.postEvents(events, this.jsonMapper, MediaType.APPLICATION_JSON);
            if (eventsPosted != events.size()) {
                throw new ISE("Event not posted");
            }
            try {
                Thread.sleep(DELAY_BETWEEN_EVENTS_SECS * 1000);
            } catch (InterruptedException ignored) {
            /* nothing */
            }
            dtLast = dt;
            dt = DateTimes.nowUtc();
            i++;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        eventReceiverSelector.stop();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) ServerDiscoverySelector(org.apache.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(org.apache.druid.testing.clients.EventReceiverFirehoseTestClient) BufferedReader(java.io.BufferedReader) ISE(org.apache.druid.java.util.common.ISE) Map(java.util.Map)

Aggregations

ServerDiscoverySelector (org.apache.druid.curator.discovery.ServerDiscoverySelector)3 EventReceiverFirehoseTestClient (org.apache.druid.testing.clients.EventReceiverFirehoseTestClient)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ISE (org.apache.druid.java.util.common.ISE)2 DateTime (org.joda.time.DateTime)2 URL (java.net.URL)1 Request (org.apache.druid.java.util.http.client.Request)1 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)1