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();
}
}
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();
}
}
Aggregations