use of org.apache.metron.common.writer.BulkMessageWriter in project metron by apache.
the class BulkMessageWriterBoltTest method testFlushOnBatchSize.
@Test
public void testFlushOnBatchSize() throws Exception {
Map stormConf = new HashMap();
bulkMessageWriterBolt.setCuratorFramework(client);
bulkMessageWriterBolt.setZKCache(cache);
bulkMessageWriterBolt.getConfigurations().updateSensorIndexingConfig(BaseEnrichmentBoltTest.sensorType, new FileInputStream("../" + BaseEnrichmentBoltTest.sampleSensorIndexingConfigPath));
{
doThrow(new Exception()).when(bulkMessageWriter).init(eq(stormConf), any(WriterConfiguration.class));
assertThrows(RuntimeException.class, () -> bulkMessageWriterBolt.prepare(stormConf, topologyContext, outputCollector));
reset(bulkMessageWriter);
}
{
when(bulkMessageWriter.getName()).thenReturn("hdfs");
bulkMessageWriterBolt.prepare(stormConf, topologyContext, outputCollector);
verify(bulkMessageWriter, times(1)).init(eq(stormConf), any(WriterConfiguration.class));
}
{
for (int i = 0; i < 4; i++) {
bulkMessageWriterBolt.execute(tupleList.get(i));
verify(bulkMessageWriter, times(0)).write(eq(BaseEnrichmentBoltTest.sensorType), any(WriterConfiguration.class), anyList());
}
BulkWriterResponse response = new BulkWriterResponse();
response.addAllSuccesses(messageIdList);
when(bulkMessageWriter.write(eq(BaseEnrichmentBoltTest.sensorType), any(WriterConfiguration.class), eq(messageList))).thenReturn(response);
bulkMessageWriterBolt.execute(tupleList.get(4));
verify(bulkMessageWriter, times(1)).write(eq(BaseEnrichmentBoltTest.sensorType), any(WriterConfiguration.class), eq(messageList));
tupleList.forEach(tuple -> verify(outputCollector, times(1)).ack(tuple));
reset(outputCollector);
}
{
doThrow(new Exception()).when(bulkMessageWriter).write(eq(BaseEnrichmentBoltTest.sensorType), any(WriterConfiguration.class), anyList());
UnitTestHelper.setLog4jLevel(BulkWriterComponent.class, Level.FATAL);
for (int i = 0; i < 5; i++) {
bulkMessageWriterBolt.execute(tupleList.get(i));
}
UnitTestHelper.setLog4jLevel(BulkWriterComponent.class, Level.ERROR);
tupleList.forEach(tuple -> verify(outputCollector, times(1)).ack(tuple));
verify(outputCollector, times(5)).emit(eq(Constants.ERROR_STREAM), any(Values.class));
verify(outputCollector, times(1)).reportError(any(Throwable.class));
}
Mockito.verifyNoMoreInteractions(outputCollector);
}
Aggregations