cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1199909 - in /cassandra/branches/cassandra-1.0: src/java/org/apache/cassandra/io/sstable/Descriptor.java test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java
Date Wed, 09 Nov 2011 18:29:31 GMT
Author: jbellis
Date: Wed Nov  9 18:29:30 2011
New Revision: 1199909

URL: http://svn.apache.org/viewvc?rev=1199909&view=rev
Log:
update Descriptor to use a regexp for validation
patch by ymorishita; reviewed by jbellis for CASSANDRA-3470

Modified:
    cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/sstable/Descriptor.java
    cassandra/branches/cassandra-1.0/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java

Modified: cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/sstable/Descriptor.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/sstable/Descriptor.java?rev=1199909&r1=1199908&r2=1199909&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/sstable/Descriptor.java
(original)
+++ cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/sstable/Descriptor.java
Wed Nov  9 18:29:30 2011
@@ -51,6 +51,7 @@ public class Descriptor
     public static final String CURRENT_VERSION = "h";
 
     public final File directory;
+    /** version has the following format: <code>[a-z]+</code> */
     public final String version;
     public final String ksname;
     public final String cfname;
@@ -242,16 +243,12 @@ public class Descriptor
 
     /**
      * @param ver SSTable version
-     * @return True if the given version string is not empty, and
-     * contains all lowercase letters, as defined by java.lang.Character.
+     * @return True if the given version string matches the format.
+     * @see #version
      */
     static boolean versionValidate(String ver)
     {
-        if (ver.length() < 1) return false;
-        for (char ch : ver.toCharArray())
-            if (!Character.isLetter(ch) || !Character.isLowerCase(ch))
-                return false;
-        return true;
+        return ver != null && ver.matches("[a-z]+");
     }
 
     public boolean isFromTheFuture()

Modified: cassandra/branches/cassandra-1.0/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java?rev=1199909&r1=1199908&r2=1199909&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java
(original)
+++ cassandra/branches/cassandra-1.0/test/unit/org/apache/cassandra/io/sstable/DescriptorTest.java
Wed Nov  9 18:29:30 2011
@@ -49,6 +49,25 @@ public class DescriptorTest
         assertKeyspace("Keyspace11", dirPath);
     }
 
+    @Test
+    public void testVersion()
+    {
+        // letter only
+        Descriptor desc = Descriptor.fromFilename(new File("Keyspace1"), "Standard1-h-1-Data.db").left;
+        assert "h".equals(desc.version);
+        assert desc.tracksMaxTimestamp;
+
+        // multiple letters
+        desc = Descriptor.fromFilename(new File("Keyspace1"), "Standard1-ha-1-Data.db").left;
+        assert "ha".equals(desc.version);
+        assert desc.tracksMaxTimestamp;
+
+        // hypothetical two-letter g version
+        desc = Descriptor.fromFilename(new File("Keyspace1"), "Standard1-gz-1-Data.db").left;
+        assert "gz".equals(desc.version);
+        assert !desc.tracksMaxTimestamp;
+    }
+
     private void assertKeyspace(String expectedKsName, String dirPath) {
         File dir = new File(dirPath);
         dir.deleteOnExit();



Mime
View raw message