/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.security.auditlog;

import static org.testng.AssertJUnit.assertEquals;

import org.testng.annotations.Test;

/**
 * 
 */
@Test
public class DuplicateFilteringAuditLoggerTest {

  public void testDuplicateFiltering() throws InterruptedException {
    InMemoryAuditLogger memoryLogger = new InMemoryAuditLogger();  
    DuplicateFilteringAuditLogger filteringLogger = new DuplicateFilteringAuditLogger(memoryLogger, 1000, 1);
    
    log5Messages(filteringLogger);
    assertEquals(5, memoryLogger.getMessages().size());
    
    log5Messages(filteringLogger);
    assertEquals(5, memoryLogger.getMessages().size());
    
    Thread.sleep(1500);
    
    log5Messages(filteringLogger);
    assertEquals(10, memoryLogger.getMessages().size());
    
    log5Messages(filteringLogger);
    assertEquals(10, memoryLogger.getMessages().size());
  }

  private void log5Messages(DuplicateFilteringAuditLogger filteringLogger) {
    filteringLogger.log("alice", "obj1", "op1", true);
    filteringLogger.log("lisa", "obj1", "op1", true);
    filteringLogger.log("alice", "obj2", "op1", true);
    filteringLogger.log("alice", "obj1", "op2", true);
    filteringLogger.log("alice", "obj1", "op1", false);
  }

}

@@ -279,17 +279,38 @@
 */%0A@Test
+(invocationCount = 4)
 %0A
-
 public c
@@ -488,16 +488,132 @@
 er();  %0A
+    %0A    int seconds = 3; //Big enough to make sure writes complete, short enough that we can wait for timeout%0A    %0A
     Dupl
@@ -710,17 +710,23 @@
 , 1000, 
-1
+seconds
 );%0A    %0A
@@ -938,14 +938,63 @@
 eep(
-1500);
+seconds * 2 * 1000); //Long enough to expire everything
 %0A   

Increase the periods in this test to avoid intermittent failures