@Test
  public void connectRiverAndSendMessages() throws InterruptedException {

    Thread.sleep(1000);

    String field = "content";
    String msg = "sammy";

    logger.debug("Publishing message [channel={}, msg={}]", channel, msg);
    jedis.publish(channel, msg);

    Thread.sleep(1000);
    refreshIndex();

    QuerySourceBuilder builder = new QuerySourceBuilder();
    builder.setQuery(queryString(field + ":" + msg));

    logger.debug(
        "Counting [index={}, type={}, field={}, msg={}]",
        new Object[] {index, channel, field, msg});
    CountResponse resp =
        node.client().count(countRequest(index).types(channel).source(builder)).actionGet();
    assertEquals(1, resp.getCount());

    msg = "coldplay";

    logger.debug(
        "Counting [index={}, type={}, field={}, msg={}]",
        new Object[] {index, channel, field, msg});
    resp = node.client().count(countRequest(index).types(channel).source(builder)).actionGet();
    assertEquals(0, resp.getCount());

    logger.debug("Publishing message [channel={}]", channel);
    jedis.publish(channel, msg);

    Thread.sleep(1000);
    refreshIndex();

    logger.debug(
        "Counting [index={}, type={}, field={}, msg={}]",
        new Object[] {index, channel, field, msg});
    resp = node.client().count(countRequest(index).types(channel).source(builder)).actionGet();
    assertEquals(1, resp.getCount());

    shutdown();
  }
Esempio n. 2
0
 /** The source to execute. */
 public CountRequest source(QuerySourceBuilder sourceBuilder) {
   this.source = sourceBuilder.buildAsBytes(Requests.CONTENT_TYPE);
   this.sourceUnsafe = false;
   return this;
 }
Esempio n. 3
0
 public ExplainRequest source(QuerySourceBuilder sourceBuilder) {
   this.source = sourceBuilder.buildAsBytes(Requests.CONTENT_TYPE);
   return this;
 }