use of org.apache.ranger.audit.queue.AuditBatchQueue in project ranger by apache.
the class TestAuditQueue method testAuditBatchQueueDestDown.
@Test
public void testAuditBatchQueueDestDown() {
logger.debug("testAuditBatchQueueDestDown()...");
int messageToSend = 10;
String basePropName = "testAuditBatchQueueDestDown_" + MiscUtil.generateUniqueId();
int batchSize = messageToSend / 3;
int queueSize = messageToSend * 2;
// Deliberately big interval
int intervalMS = Integer.MAX_VALUE;
Properties props = new Properties();
props.put(basePropName + "." + BaseAuditHandler.PROP_NAME, "testAuditBatchQueueDestDown");
props.put(basePropName + "." + AuditQueue.PROP_BATCH_SIZE, "" + batchSize);
props.put(basePropName + "." + AuditQueue.PROP_QUEUE_SIZE, "" + queueSize);
props.put(basePropName + "." + AuditQueue.PROP_BATCH_INTERVAL, "" + intervalMS);
// Enable File Spooling
props.put(basePropName + "." + "filespool.enable", "" + true);
props.put(basePropName + "." + "filespool.dir", "target");
TestConsumer testConsumer = new TestConsumer();
testConsumer.isDown = true;
AuditBatchQueue queue = new AuditBatchQueue(testConsumer);
queue.init(props, basePropName);
queue.start();
for (int i = 0; i < messageToSend; i++) {
queue.log(createEvent());
}
// Let's wait for second
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// ignore
}
queue.waitToComplete(5000);
queue.stop();
queue.waitToComplete();
assertEquals("Total count", 0, testConsumer.getCountTotal());
assertEquals("Total sum", 0, testConsumer.getSumTotal());
assertEquals("Total batch", 0, testConsumer.getBatchCount());
assertNull("Event not in sequnce", testConsumer.isInSequence());
}
Aggregations