cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r1062951 - /cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/CompactSerializerTest.java
Date Mon, 24 Jan 2011 20:03:48 GMT
Author: gdusbabek
Date: Mon Jan 24 20:03:44 2011
New Revision: 1062951

URL: http://svn.apache.org/viewvc?rev=1062951&view=rev
Log:
ICompactSerializerTest assures serialization assumptions. patch by gdusbabek, reviewed by
jbellis. CASSANDRA-1923

Added:
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/CompactSerializerTest.java

Added: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/CompactSerializerTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/CompactSerializerTest.java?rev=1062951&view=auto
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/CompactSerializerTest.java
(added)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/CompactSerializerTest.java
Mon Jan 24 20:03:44 2011
@@ -0,0 +1,128 @@
+package org.apache.cassandra.io;
+
+import org.apache.cassandra.CleanupHelper;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class CompactSerializerTest extends CleanupHelper
+{
+    private static Set<String> expectedClassNames;
+    private static List<String> discoveredClassNames;
+    
+    @BeforeClass
+    public static void scanClasspath()
+    {
+        expectedClassNames = new HashSet<String>();
+        expectedClassNames.add("RangeSliceCommandSerializer");
+        expectedClassNames.add("ReadCommandSerializer");
+        expectedClassNames.add("ReadResponseSerializer");
+        expectedClassNames.add("RowSerializer");
+        expectedClassNames.add("RowMutationSerializer");
+        expectedClassNames.add("SliceByNamesReadCommandSerializer");
+        expectedClassNames.add("SliceFromReadCommandSerializer");
+        expectedClassNames.add("TruncateResponseSerializer");
+        expectedClassNames.add("TruncationSerializer");
+        expectedClassNames.add("WriteResponseSerializer");
+        expectedClassNames.add("EndpointStateSerializer");
+        expectedClassNames.add("GossipDigestSerializer");
+        expectedClassNames.add("GossipDigestAck2MessageSerializer");
+        expectedClassNames.add("GossipDigestAckMessageSerializer");
+        expectedClassNames.add("GossipDigestSynMessageSerializer");
+        expectedClassNames.add("HeartBeatStateSerializer");
+        expectedClassNames.add("VersionedValueSerializer");
+        expectedClassNames.add("HeaderSerializer");
+        expectedClassNames.add("MessageSerializer");
+        expectedClassNames.add("TreeRequestVerbHandler");
+        expectedClassNames.add("TreeResponseVerbHandler");
+        expectedClassNames.add("PendingFileSerializer");
+        expectedClassNames.add("StreamHeaderSerializer");
+        expectedClassNames.add("FileStatusSerializer");
+        expectedClassNames.add("StreamRequestMessageSerializer");
+        expectedClassNames.add("BloomFilterSerializer");
+        expectedClassNames.add("EstimatedHistogramSerializer");
+        expectedClassNames.add("LegacyBloomFilterSerializer");
+        
+        discoveredClassNames = new ArrayList<String>();
+        String cp = System.getProperty("java.class.path");
+        assert cp != null;
+        String[] parts = cp.split(File.pathSeparator, -1);
+        class DirScanner 
+        {
+            void scan(File f, String ctx) 
+            {
+                String newCtx = ctx == null ? f.getName().equals("org") ? f.getName() : null
: ctx + "." + f.getName();
+                if (f.isDirectory())
+                {
+                    for (File child : f.listFiles())
+                    {
+                        scan(child, newCtx);
+                    }
+                }
+                else if (f.getName().endsWith(".class"))
+                {
+                    String fName = f.getName();
+                    String className = ctx + "." + fName.substring(0, fName.lastIndexOf('.'));
+                    try
+                    {
+                        Class cls = Class.forName(className);
+                        String simpleName = cls.getSimpleName();
+                        classTraversal: while (cls != null)
+                        {
+                            Type[] interfaces = cls.getGenericInterfaces();
+                            for (Type t : interfaces)
+                            {
+                                if(t instanceof ParameterizedType)
+                                {
+                                    ParameterizedType pt = (ParameterizedType)t;
+                                    if (((Class)pt.getRawType()).getSimpleName().equals("ICompactSerializer"))
+                                    {
+                                        discoveredClassNames.add(simpleName);
+                                        break classTraversal;
+                                    }
+                                }
+                            }
+                            cls = cls.getSuperclass();
+                        }
+                    }
+                    catch (ClassNotFoundException ex) 
+                    {
+                        throw new RuntimeException(ex);
+                    }
+                }
+            }
+        }
+        
+        DirScanner dirScanner = new DirScanner();
+        for (String cpItem : parts)
+        {
+            File f = new File(cpItem);
+            if (f.exists() && f.isDirectory())
+                dirScanner.scan(f, null);
+        }
+    }
+    
+    /** look for classes I expect to find. */
+    @Test
+    public void verifyAllSimpleNamesTest()
+    {
+        for (String clsName : expectedClassNames)
+            assert discoveredClassNames.contains(clsName) : clsName + " was not discovered";
+    }
+    
+    /** look for classes I do not expect to find. */
+    @Test
+    public void noOthersTest()
+    {
+        for (String clsName : discoveredClassNames)
+            assert expectedClassNames.contains(clsName) : clsName + " was discovered";
+        assert true;
+    }
+}



Mime
View raw message