ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1640384 - 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 Tue, 18 Nov 2014 16:35:02 GMT
Author: marrs
Date: Tue Nov 18 16:35:02 2014
New Revision: 1640384

URL: http://svn.apache.org/r1640384
Log:
ACE-495 Added a test and a fix for this bug.

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=1640384&r1=1640383&r2=1640384&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
Tue Nov 18 16:35:02 2014
@@ -554,6 +554,10 @@ public class LogStoreImpl implements Log
         	// re-fetch within the lock
         	descriptor = getDescriptorInternal(targetID, storeID);
             long high = descriptor.getRangeSet().getHigh();
+            long lowestID = getLowestIDInternal(targetID, storeID);
+            if (high < lowestID) {
+                high = lowestID - 1;
+            }
             Event result = new Event(targetID, storeID, high + 1, System.currentTimeMillis(),
type, props);
             List<Event> list = new ArrayList<>();
             list.add(result);
@@ -577,6 +581,7 @@ public class LogStoreImpl implements Log
 		        	File index = getLogFileIndex(targetID, logID);
 					fw = new FileWriter(index);
 		        	fw.write(Long.toString(lowestID));
+		        	System.out.println("SLID: " + index.getAbsolutePath() + "=" + lowestID);
 		        	m_fileToLowestID.put(index.getAbsolutePath(), lowestID);
 		        }
 		        finally {
@@ -615,11 +620,13 @@ public class LogStoreImpl implements Log
     			br.close();
     			result = Long.parseLong(line);
     			m_fileToLowestID.put(index.getAbsolutePath(), result);
+                System.out.println("GLID: " + index.getAbsolutePath() + "=" + result);
     		}
     		catch (Exception nfe) {
     			// if the file somehow got corrupted, or does not exist,
     			// we simply assume 0 as the default
     			m_fileToLowestID.put(index.getAbsolutePath(), 0L);
+                System.out.println("GLID: " + index.getAbsolutePath() + "=0!!!");
     			return 0L;
     		}
     		finally {

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=1640384&r1=1640383&r2=1640384&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
Tue Nov 18 16:35:02 2014
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -193,11 +194,63 @@ public class ServerLogStoreTester {
         assert stored.size() == 0 : "No events should have been stored";
     }
 
-	private List<Event> getStoredEvents() throws IOException {
+    @SuppressWarnings("serial")
+    @Test(groups = { UNIT })
+    public void testLogIDGenerationWithLowestID() throws IOException {
+        Dictionary<String, String> props = new Hashtable<>();
+        props.put("test", "foo");
+
+        long logID = 0;
+        for (long id = 1; id <= 20; id++) {
+            Event event = m_logStore.put("target", 1, props);
+            System.out.println("Event: " + event.toRepresentation());
+            logID = event.getStoreID();
+        }
+
+        List<Descriptor> descriptors = m_logStore.getDescriptors();
+        assert descriptors.size() == 1 : "Incorrect amount of ranges returned from store";
+        String range = descriptors.get(0).getRangeSet().toRepresentation();
+        assert range.equals("1-20") : "Incorrect range in descriptor: " + range;
+        List<Event> stored = getStoredEvents();
+        assert stored.size() == 20 : "Exactly 20 events should have been stored";
+        
+        m_logStore.setLowestID("target", logID, 10);
+        assert 10 == m_logStore.getLowestID("target", logID) : "Lowest ID should be 10, not:
" + m_logStore.getLowestID("target", logID);
+        
+        stored = getStoredEvents();
+        assert stored.size() == 11 : "Exactly 11 events should have been stored, we found
" + stored.size();
+        descriptors = m_logStore.getDescriptors();
+        assert descriptors.size() == 1 : "Incorrect amount of ranges returned from store";
+        range = descriptors.get(0).getRangeSet().toRepresentation();
+        assert range.equals("10-20") : "Incorrect range in descriptor: " + range;
+
+        m_logStore.setLowestID("target", logID, 21);
+        stored = getStoredEvents();
+        assert stored.size() == 0 : "No events should have been stored, we found " + stored.size();
+        descriptors = m_logStore.getDescriptors();
+        assert descriptors.size() == 1 : "Incorrect amount of ranges returned from store";
+        range = descriptors.get(0).getRangeSet().toRepresentation();
+        assert range.equals("") : "Incorrect range in descriptor: " + range;
+
+        for (long id = 1; id <= 20; id++) {
+            System.out.println("Event: " + m_logStore.put("target", 1, props).toRepresentation());
+        }
+        
+        stored = getStoredEvents();
+        assert stored.size() == 20 : "Exactly 20 events should have been stored, we found
" + stored.size();
+        descriptors = m_logStore.getDescriptors();
+        assert descriptors.size() == 1 : "Incorrect amount of ranges returned from store";
+        range = descriptors.get(0).getRangeSet().toRepresentation();
+        assert range.equals("21-40") : "Incorrect range in descriptor: " + range;
+    }
+    
+    private List<Event> getStoredEvents() throws IOException {
 		List<Event> stored = new ArrayList<Event>();
         for (Descriptor range : m_logStore.getDescriptors()) {
+            System.out.println("TID: " + range.getTargetID());
             for (Descriptor range2 : m_logStore.getDescriptors(range.getTargetID())) {
                 stored.addAll(m_logStore.get(m_logStore.getDescriptor(range2.getTargetID(),
range2.getStoreID())));
+                System.out.println("  Range: " + range2.getRangeSet());
             }
         }
 		return stored;



Mime
View raw message