ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1416687 - in /ace/trunk/org.apache.ace.client.repository.impl: src/org/apache/ace/client/repository/stateful/impl/ test/org/apache/ace/client/repository/impl/
Date Mon, 03 Dec 2012 21:46:09 GMT
Author: marrs
Date: Mon Dec  3 21:46:08 2012
New Revision: 1416687

URL: http://svn.apache.org/viewvc?rev=1416687&view=rev
Log:
ACE-308 Fixed the comparator. Added a test to ensure this bug does not resurface.

Added:
    ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/LogEventComparator.java
    ace/trunk/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/ACE308Test.java
Modified:
    ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java

Added: ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/LogEventComparator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/LogEventComparator.java?rev=1416687&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/LogEventComparator.java
(added)
+++ ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/LogEventComparator.java
Mon Dec  3 21:46:08 2012
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.client.repository.stateful.impl;
+
+import java.util.Comparator;
+
+import org.apache.ace.log.LogEvent;
+
+public final class LogEventComparator implements Comparator<LogEvent> {
+	public int compare(LogEvent left, LogEvent right) {
+        if (left.getLogID() == right.getLogID()) {
+            return sgn(left.getTime() - right.getTime());
+        }
+        else {
+            return sgn(left.getLogID() - right.getLogID());
+        }
+    }
+
+	public int sgn(long number) {
+    	if (number < 0) {
+    		return -1;
+    	}
+    	else if (number > 0) {
+    		return 1;
+    	}
+    	return 0;
+    }
+}
\ No newline at end of file

Modified: ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java?rev=1416687&r1=1416686&r2=1416687&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java
Mon Dec  3 21:46:08 2012
@@ -236,16 +236,7 @@ public class StatefulTargetRepositoryImp
         return false;
     }
 
-    private Comparator<LogEvent> m_auditEventComparator = new Comparator<LogEvent>()
{
-        public int compare(LogEvent left, LogEvent right) {
-            if (left.getLogID() == right.getLogID()) {
-                return (int) (left.getTime() - right.getTime());
-            }
-            else {
-                return (int) (left.getLogID() - right.getLogID());
-            }
-        }
-    };
+    private Comparator<LogEvent> m_auditEventComparator = new LogEventComparator();
 
     /**
      * Gets all auditlog events which are related to a given target ID.

Added: ace/trunk/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/ACE308Test.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/ACE308Test.java?rev=1416687&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/ACE308Test.java
(added)
+++ ace/trunk/org.apache.ace.client.repository.impl/test/org/apache/ace/client/repository/impl/ACE308Test.java
Mon Dec  3 21:46:08 2012
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.client.repository.impl;
+
+import org.apache.ace.client.repository.stateful.impl.LogEventComparator;
+import org.apache.ace.log.LogEvent;
+import org.apache.ace.test.utils.TestUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Before fixing ACE-308 the comparator could "overflow" when casting a long to an
+ * int, changing the sign of the result. For this specific case, it would fail. After
+ * the fix, it no longer fails.
+ */
+public class ACE308Test {
+    @Test( groups = { TestUtils.UNIT } )
+    public void testLogEvents() {
+    	LogEventComparator c = new LogEventComparator();
+    	LogEvent left = new LogEvent("t", 1, 1, -1000000000000000000L, 0, null);
+    	LogEvent right = new LogEvent("t", 1, 1, 1, 0, null);
+    	Assert.assertTrue((left.getTime() - right.getTime()) < 0L);
+    	Assert.assertTrue(c.compare(left, right) < 0L);
+    }
+}



Mime
View raw message