Search in sources :

Example 6 with AuditBatchQueue

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());
}
Also used : AuditBatchQueue(org.apache.ranger.audit.queue.AuditBatchQueue) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

AuditBatchQueue (org.apache.ranger.audit.queue.AuditBatchQueue)6 Properties (java.util.Properties)5 Test (org.junit.Test)5 DBAuditDestination (org.apache.ranger.audit.destination.DBAuditDestination)1 FileAuditDestination (org.apache.ranger.audit.destination.FileAuditDestination)1 HDFSAuditDestination (org.apache.ranger.audit.destination.HDFSAuditDestination)1 Log4JAuditDestination (org.apache.ranger.audit.destination.Log4JAuditDestination)1 SolrAuditDestination (org.apache.ranger.audit.destination.SolrAuditDestination)1 KafkaAuditProvider (org.apache.ranger.audit.provider.kafka.KafkaAuditProvider)1 AuditAsyncQueue (org.apache.ranger.audit.queue.AuditAsyncQueue)1 AuditQueue (org.apache.ranger.audit.queue.AuditQueue)1