IndexInfoBuilder indexInfo = mock(IndexInfoBuilder.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Message m = (Message) invocation.getArguments()[0];
if (m.getRoutingKey().startsWith("parsing_failed")) {
return null;
} else {
return new IndexInfo() {
@Override
public String getIndex() {
return m.getRoutingKey();
}
@Override
public String getType() {
return "type";
}
@Override
public byte[] getSource() {
return m.getPayload();
}
@Override
public String getId() {
return null;
}
@Override
public long getTimestamp() {
return ts;
}
};
}
}
}).when(indexInfo).create(any(Message.class));
Client client = mock(Client.class);
ActionFuture<BulkResponse> responseActionFuture = mock(ActionFuture.class);
BulkResponse response = getBulkItemResponses();
doReturn(response).when(responseActionFuture).actionGet();
doReturn(responseActionFuture).when(client).bulk(any(BulkRequest.class));
ActionFuture<IndexResponse> indexResponseActionFuture = mock(ActionFuture.class);
doReturn(mock(IndexResponse.class)).when(indexResponseActionFuture).actionGet();
doReturn(indexResponseActionFuture).when(client).index(any(IndexRequest.class));
ElasticSearchSink sink = new ElasticSearchSink(
null, // by default it will be memory queue
1000,
5000,
"cluster",
false,
null,
null,
null,
indexInfo,
0,0,0,0,false,null,
null,
jsonMapper,
client);
sink.open();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
sink.writeTo(new DefaultMessageContainer(new Message("parsing_failed_topic" + i, getAnyMessage()), jsonMapper));
}
for (int j = 0; j < 3; ++j) {
sink.writeTo(new DefaultMessageContainer(new Message("indexed" + i, getAnyMessage()), jsonMapper));
}
for (int j = 0; j < 3; ++j) {
sink.writeTo(new DefaultMessageContainer(new Message("rejected" + i, getAnyMessage()), jsonMapper));
}
}
sink.close();
String stat = sink.getStat();