cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [17/17] git commit: Fix unit tests on java7 Patch by Marcus Eriksson, reviewed by brandonwilliams for CASSANDRA-5315
Date Wed, 06 Mar 2013 22:25:41 GMT
Updated Branches:
  refs/heads/cassandra-1.1 2b87bfe55 -> 54601f192
  refs/heads/cassandra-1.2 62b1ee40b -> c58f596ea
  refs/heads/trunk 66e6f2969 -> ec921a9ff


Fix unit tests on java7
Patch by Marcus Eriksson, reviewed by brandonwilliams for CASSANDRA-5315


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ec921a9f
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ec921a9f
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ec921a9f

Branch: refs/heads/trunk
Commit: ec921a9ff8af1531dcc7ae5cb2bd8d60b265d50f
Parents: a146f4e
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Wed Mar 6 16:25:06 2013 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Wed Mar 6 16:25:06 2013 -0600

----------------------------------------------------------------------
 .../org/apache/cassandra/MethodComparator.java     |  146 +++++++++++++++
 .../apache/cassandra/OrderedJUnit4ClassRunner.java |   34 ++++
 .../cassandra/config/DatabaseDescriptorTest.java   |    4 +
 .../unit/org/apache/cassandra/config/DefsTest.java |    3 +
 .../apache/cassandra/db/ColumnFamilyStoreTest.java |    3 +
 .../cassandra/db/compaction/CompactionsTest.java   |    3 +
 .../compaction/LeveledCompactionStrategyTest.java  |    3 +
 .../org/apache/cassandra/dht/BootStrapperTest.java |    3 +
 .../cassandra/io/sstable/SSTableReaderTest.java    |    3 +
 .../service/StorageServiceServerTest.java          |    3 +
 .../cassandra/streaming/StreamingTransferTest.java |    3 +
 11 files changed, 208 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/MethodComparator.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/MethodComparator.java b/test/unit/org/apache/cassandra/MethodComparator.java
new file mode 100644
index 0000000..690ae57
--- /dev/null
+++ b/test/unit/org/apache/cassandra/MethodComparator.java
@@ -0,0 +1,146 @@
+package org.apache.cassandra;
+
+import org.junit.Ignore;
+import org.junit.runners.model.FrameworkMethod;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.lang.reflect.Method;
+import java.util.Comparator;
+
+public class MethodComparator<T> implements Comparator<T>
+{
+    private static final char[] METHOD_SEPARATORS = {1, 7};
+
+    private MethodComparator()
+    {
+    }
+
+    public static MethodComparator<FrameworkMethod> getFrameworkMethodComparatorForJUnit4()
+    {
+        return new MethodComparator<FrameworkMethod>();
+    }
+
+    @Override
+    public int compare(T o1, T o2)
+    {
+        final MethodPosition methodPosition1 = this.getIndexOfMethodPosition(o1);
+        final MethodPosition methodPosition2 = this.getIndexOfMethodPosition(o2);
+        return methodPosition1.compareTo(methodPosition2);
+    }
+
+    private MethodPosition getIndexOfMethodPosition(final Object method)
+    {
+        if (method instanceof FrameworkMethod)
+        {
+            return this.getIndexOfMethodPosition((FrameworkMethod) method);
+        }
+        else if (method instanceof Method)
+        {
+            return this.getIndexOfMethodPosition((Method) method);
+        }
+        else
+        {
+            return new NullMethodPosition();
+        }
+    }
+
+    private MethodPosition getIndexOfMethodPosition(final FrameworkMethod frameworkMethod)
+    {
+        return getIndexOfMethodPosition(frameworkMethod.getMethod());
+    }
+
+    private MethodPosition getIndexOfMethodPosition(final Method method)
+    {
+        final Class aClass = method.getDeclaringClass();
+        if (method.getAnnotation(Ignore.class) == null)
+        {
+            return getIndexOfMethodPosition(aClass, method.getName());
+        }
+        else
+        {
+            return new NullMethodPosition();
+        }
+    }
+
+    private MethodPosition getIndexOfMethodPosition(final Class aClass, final String methodName)
+    {
+        MethodPosition methodPosition;
+        for (final char methodSeparator : METHOD_SEPARATORS)
+        {
+            methodPosition = getIndexOfMethodPosition(aClass, methodName, methodSeparator);
+            if (!(methodPosition instanceof NullMethodPosition))
+            {
+                return methodPosition;
+            }
+        }
+        return new NullMethodPosition();
+    }
+
+    private MethodPosition getIndexOfMethodPosition(final Class aClass, final String methodName,
final char methodSeparator)
+    {
+        final InputStream inputStream = aClass.getResourceAsStream(aClass.getSimpleName()
+ ".class");
+        final LineNumberReader lineNumberReader = new LineNumberReader(new InputStreamReader(inputStream));
+        final String methodNameWithSeparator = methodName + methodSeparator;
+        try
+        {
+            try
+            {
+                String line;
+                while ((line = lineNumberReader.readLine()) != null)
+                {
+                    if (line.contains(methodNameWithSeparator))
+                    {
+                        return new MethodPosition(lineNumberReader.getLineNumber(), line.indexOf(methodNameWithSeparator));
+                    }
+                }
+            }
+            finally
+            {
+                lineNumberReader.close();
+            }
+        }
+        catch (IOException e)
+        {
+            return new NullMethodPosition();
+        }
+        return new NullMethodPosition();
+    }
+
+    private static class MethodPosition implements Comparable<MethodPosition>
+    {
+        private final Integer lineNumber;
+        private final Integer indexInLine;
+
+        public MethodPosition(int lineNumber, int indexInLine)
+        {
+            this.lineNumber = lineNumber;
+            this.indexInLine = indexInLine;
+        }
+
+        @Override
+        public int compareTo(MethodPosition o)
+        {
+
+            // If line numbers are equal, then compare by indexes in this line.
+            if (this.lineNumber.equals(o.lineNumber))
+            {
+                return this.indexInLine.compareTo(o.indexInLine);
+            }
+            else
+            {
+                return this.lineNumber.compareTo(o.lineNumber);
+            }
+        }
+    }
+
+    private static class NullMethodPosition extends MethodPosition
+    {
+        public NullMethodPosition()
+        {
+            super(-1, -1);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/OrderedJUnit4ClassRunner.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/OrderedJUnit4ClassRunner.java b/test/unit/org/apache/cassandra/OrderedJUnit4ClassRunner.java
new file mode 100644
index 0000000..d84aedb
--- /dev/null
+++ b/test/unit/org/apache/cassandra/OrderedJUnit4ClassRunner.java
@@ -0,0 +1,34 @@
+package org.apache.cassandra;
+
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class OrderedJUnit4ClassRunner extends BlockJUnit4ClassRunner
+{
+
+    public OrderedJUnit4ClassRunner(Class aClass) throws InitializationError
+    {
+        super(aClass);
+    }
+
+    @Override
+    protected List<FrameworkMethod> computeTestMethods()
+    {
+        final List<FrameworkMethod> list = super.computeTestMethods();
+        try
+        {
+            final List<FrameworkMethod> copy = new ArrayList<FrameworkMethod>(list);
+            Collections.sort(copy, MethodComparator.getFrameworkMethodComparatorForJUnit4());
+            return copy;
+        }
+        catch (Throwable throwable)
+        {
+            return list;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java b/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
index 9cca997..513b808 100644
--- a/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
+++ b/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
@@ -18,6 +18,7 @@
 */
 package org.apache.cassandra.config;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.InvalidRequestException;
@@ -26,11 +27,14 @@ import org.apache.cassandra.locator.SimpleStrategy;
 import org.apache.cassandra.service.MigrationManager;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
+
 import static org.junit.Assert.*;
 
 
 import java.io.IOException;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class DatabaseDescriptorTest
 {
     @Test

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/config/DefsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/config/DefsTest.java b/test/unit/org/apache/cassandra/config/DefsTest.java
index ef30668..76cab94 100644
--- a/test/unit/org/apache/cassandra/config/DefsTest.java
+++ b/test/unit/org/apache/cassandra/config/DefsTest.java
@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.db.*;
@@ -42,7 +43,9 @@ import org.apache.cassandra.thrift.IndexType;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class DefsTest extends SchemaLoader
 {
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
index c17a688..12a39ad 100644
--- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
@@ -32,7 +32,9 @@ import com.google.common.collect.Sets;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.config.CFMetaData;
@@ -58,6 +60,7 @@ import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
 import static org.apache.commons.lang.ArrayUtils.EMPTY_BYTE_ARRAY;
 import static org.junit.Assert.assertNull;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class ColumnFamilyStoreTest extends SchemaLoader
 {
     static byte[] bytes1, bytes2;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java
index 94a9573..3a1b804 100644
--- a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java
+++ b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java
@@ -29,7 +29,9 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.SetMultimap;
 import com.google.common.collect.Sets;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.config.DatabaseDescriptor;
@@ -48,6 +50,7 @@ import org.apache.cassandra.utils.Pair;
 
 import static junit.framework.Assert.*;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class CompactionsTest extends SchemaLoader
 {
     public static final String TABLE1 = "Keyspace1";

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
index ebc320f..161e7f8 100644
--- a/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
+++ b/test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java
@@ -23,7 +23,9 @@ import java.util.Collection;
 
 import com.google.common.collect.Iterables;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.db.ColumnFamilyStore;
@@ -41,6 +43,7 @@ import org.apache.cassandra.utils.FBUtilities;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class LeveledCompactionStrategyTest extends SchemaLoader
 {
     /*

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/dht/BootStrapperTest.java b/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
index d2b1aec..2381545 100644
--- a/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
+++ b/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
@@ -31,7 +31,9 @@ import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.Table;
@@ -46,6 +48,7 @@ import org.apache.cassandra.utils.FBUtilities;
 
 import static org.junit.Assert.*;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class BootStrapperTest extends SchemaLoader
 {
     @Test

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
index 6e1e5c2..a8b6d64 100644
--- a/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
@@ -31,7 +31,9 @@ import java.util.concurrent.ExecutionException;
 import java.util.*;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.Util;
 import org.apache.cassandra.config.DatabaseDescriptor;
@@ -55,6 +57,7 @@ import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.CLibrary;
 import org.apache.cassandra.utils.Pair;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class SSTableReaderTest extends SchemaLoader
 {
     static Token t(int i)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
index c4931a6..39fbb4a 100644
--- a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
+++ b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
@@ -25,7 +25,9 @@ import java.util.Collections;
 import java.util.List;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.dht.Token;
@@ -35,6 +37,7 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class StorageServiceServerTest
 {
     @Test

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ec921a9f/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java
index dd2d4f4..5083e6b 100644
--- a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java
+++ b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.streaming;
 */
 
 import static junit.framework.Assert.assertEquals;
+import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.Util;
 import static org.apache.cassandra.Util.column;
 import static org.apache.cassandra.Util.addMutation;
@@ -47,11 +48,13 @@ import org.apache.cassandra.utils.FBUtilities;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.cassandra.utils.ByteBufferUtil;
 
+@RunWith(OrderedJUnit4ClassRunner.class)
 public class StreamingTransferTest extends SchemaLoader
 {
     private static final Logger logger = LoggerFactory.getLogger(StreamingTransferTest.class);


Mime
View raw message