ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1638949 - in /ace/trunk/org.apache.ace.log: src/org/apache/ace/log/server/store/impl/LogStoreImpl.java test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java
Date Wed, 12 Nov 2014 18:57:33 GMT
Author: marrs
Date: Wed Nov 12 18:57:29 2014
New Revision: 1638949

URL: http://svn.apache.org/r1638949
Log:
ACE-493 Fixed the issue and added some tests for it.

Modified:
    ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
    ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java

Modified: ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java?rev=1638949&r1=1638948&r2=1638949&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
(original)
+++ ace/trunk/org.apache.ace.log/src/org/apache/ace/log/server/store/impl/LogStoreImpl.java
Wed Nov 12 18:57:29 2014
@@ -271,8 +271,10 @@ public class LogStoreImpl implements Log
                 // and sort
                 Collections.sort(list);
                 // and remove if necessary
-                while (list.size() > m_maxEvents) {
-                	list.remove(0);
+                if (m_maxEvents > 0) {
+	                while (list.size() > m_maxEvents) {
+	                	list.remove(0);
+	                }
                 }
                 out = new PrintWriter(new FileWriter(new File(dir, logID.toString())));
             }

Modified: ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java?rev=1638949&r1=1638948&r2=1638949&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java
(original)
+++ ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/store/impl/ServerLogStoreTester.java
Wed Nov 12 18:57:29 2014
@@ -95,6 +95,58 @@ public class ServerLogStoreTester {
         assert in.equals(out) : "Stored events differ from the added.";
     }
 
+    @SuppressWarnings("serial")
+    @Test(groups = { UNIT })
+    public void testLogOutOfOrder() throws IOException {
+        Map<String, String> props = new HashMap<String, String>();
+        props.put("test", "bar");
+
+        List<Descriptor> ranges = m_logStore.getDescriptors();
+        assert ranges.isEmpty() : "New store should have no ranges.";
+
+        List<Event> events = new ArrayList<Event>();
+        events.add(new Event("t1", 1, 2, 2, AuditEvent.FRAMEWORK_STARTED, props));
+        events.add(new Event("t1", 1, 3, 3, AuditEvent.FRAMEWORK_STARTED, props));
+        events.add(new Event("t1", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED, props));
+        m_logStore.put(events);
+        assert m_logStore.getDescriptors().size() == 1 : "Incorrect amount of ranges returned
from store";
+        List<Event> stored = getStoredEvents();
+
+        Set<String> out = new HashSet<String>();
+        for (Event event : stored) {
+            out.add(event.toRepresentation());
+        }
+        assert out.size() == 3 : "Stored events differ from the added.";
+    }
+
+    @SuppressWarnings("serial")
+    @Test(groups = { UNIT })
+    public void testLogOutOfOrderOneByOne() throws IOException {
+        Map<String, String> props = new HashMap<String, String>();
+        props.put("test", "bar");
+
+        List<Descriptor> ranges = m_logStore.getDescriptors();
+        assert ranges.isEmpty() : "New store should have no ranges.";
+
+        List<Event> events = new ArrayList<Event>();
+        events.add(new Event("t1", 1, 2, 2, AuditEvent.FRAMEWORK_STARTED, props));
+        m_logStore.put(events);
+        events.clear();
+        events.add(new Event("t1", 1, 3, 3, AuditEvent.FRAMEWORK_STARTED, props));
+        m_logStore.put(events);
+        events.clear();
+        events.add(new Event("t1", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED, props));
+        m_logStore.put(events);
+        assert m_logStore.getDescriptors().size() == 1 : "Incorrect amount of ranges returned
from store";
+        List<Event> stored = getStoredEvents();
+
+        Set<String> out = new HashSet<String>();
+        for (Event event : stored) {
+            out.add(event.toRepresentation());
+        }
+        assert out.size() == 3 : "Stored events differ from the added: " + out.size();
+    }
+
     
     @SuppressWarnings("serial")
     @Test(groups = { UNIT })



Mime
View raw message