Search in sources :

Example 1 with EventReceiverFirehoseTestClient

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

the class ITUnionQueryTest method postEvents.

public 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);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_PREFIX + id, jsonMapper, httpClient, smileMapper);
        client.postEventsFromFile(UNION_DATA_FILE);
    } finally {
        eventReceiverSelector.stop();
    }
}
Also used : ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(io.druid.testing.clients.EventReceiverFirehoseTestClient)

Example 2 with EventReceiverFirehoseTestClient

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

the class ITRealtimeIndexTaskTest method postEvents.

public void postEvents() throws Exception {
    DateTimeZone zone = DateTimeZone.forID("UTC");
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_NAME);
    eventReceiverSelector.start();
    BufferedReader reader = null;
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(ITRealtimeIndexTaskTest.class.getResourceAsStream(EVENT_DATA_FILE));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    try {
        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 = new DateTime(zone);
        // 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 = line.replace(TIME_PLACEHOLDER, EVENT_FMT.print(dt));
            LOG.info("sending event: [%s]\n", event);
            Collection<Map<String, Object>> events = new ArrayList<Map<String, Object>>();
            events.add((Map<String, Object>) this.jsonMapper.readValue(event, new TypeReference<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 ex) {
            /* nothing */
            }
            dtLast = dt;
            dt = new DateTime(zone);
            i++;
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        reader.close();
        eventReceiverSelector.stop();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(io.druid.testing.clients.EventReceiverFirehoseTestClient) BufferedReader(java.io.BufferedReader) ISE(io.druid.java.util.common.ISE) Map(java.util.Map)

Aggregations

ServerDiscoverySelector (io.druid.curator.discovery.ServerDiscoverySelector)2 EventReceiverFirehoseTestClient (io.druid.testing.clients.EventReceiverFirehoseTestClient)2 ISE (io.druid.java.util.common.ISE)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1