Search in sources :

Example 1 with Match

use of org.elasticsearch.action.percolate.PercolateResponse.Match in project apex-malhar by apache.

the class ElasticSearchPercolateTest method checkPercolateResponse.

/**
 */
private void checkPercolateResponse() {
    ElasticSearchPercolatorOperator oper = new ElasticSearchPercolatorOperator();
    oper.hostName = HOST_NAME;
    oper.port = PORT;
    oper.indexName = INDEX_NAME;
    oper.documentType = DOCUMENT_TYPE;
    oper.setup(null);
    String[] messages = { "{content:'This will match only with malhar'}", "{content:'This will match only with github'}", "{content:'This will match with both github and malhar'}", "{content:'This will not match with any of them'}" };
    String[][] matches = { { MALHAR_TOPIC }, { GITHUB_TOPIC }, { GITHUB_TOPIC, MALHAR_TOPIC }, {} };
    CollectorTestSink<PercolateResponse> sink = new CollectorTestSink<PercolateResponse>();
    oper.outputPort.setSink((CollectorTestSink) sink);
    for (String message : messages) {
        oper.inputPort.process(message);
    }
    int i = 0;
    for (PercolateResponse response : sink.collectedTuples) {
        List<String> matchIds = new ArrayList<String>();
        for (Match match : response.getMatches()) {
            matchIds.add(match.getId().toString());
        }
        Collections.sort(matchIds);
        Assert.assertArrayEquals(matchIds.toArray(), matches[i]);
        i++;
    }
}
Also used : ArrayList(java.util.ArrayList) PercolateResponse(org.elasticsearch.action.percolate.PercolateResponse) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Match(org.elasticsearch.action.percolate.PercolateResponse.Match)

Aggregations

ArrayList (java.util.ArrayList)1 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 PercolateResponse (org.elasticsearch.action.percolate.PercolateResponse)1 Match (org.elasticsearch.action.percolate.PercolateResponse.Match)1