Author: jbellis
Date: Wed Aug 17 13:22:24 2011
New Revision: 1158693

URL: http://svn.apache.org/viewvc?rev=1158693&view=rev
Log:
fix SSTIT on Windows
patch by Vladimir Loncar; reviewed by jbellis for CASSANDRA-3043

Modified:
    
cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/tools/SSTableImportTest.java

Modified: 
cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/tools/SSTableImportTest.java?rev=1158693&r1=1158692&r2=1158693&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
 (original)
+++ 
cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
 Wed Aug 17 13:22:24 2011
@@ -20,6 +20,8 @@ package org.apache.cassandra.tools;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.config.DatabaseDescriptor;
@@ -44,17 +46,16 @@ import static org.junit.Assert.assertEqu
 
 import org.apache.cassandra.Util;
 
-import org.apache.cassandra.utils.FBUtilities;
 import org.json.simple.parser.ParseException;
 import org.junit.Test;
 
 public class SSTableImportTest extends SchemaLoader
 {   
     @Test
-    public void testImportSimpleCf() throws IOException
+    public void testImportSimpleCf() throws IOException, URISyntaxException
     {
         // Import JSON to temp SSTable file
-        String jsonUrl = 
getClass().getClassLoader().getResource("SimpleCF.json").getPath();
+        String jsonUrl = resourcePath("SimpleCF.json");
         File tempSS = tempSSTableFile("Keyspace1", "Standard1");
         SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", 
tempSS.getPath());
 
@@ -72,11 +73,18 @@ public class SSTableImportTest extends S
         assert ((ExpiringColumn)expCol).getTimeToLive() == 42 && 
expCol.getLocalDeletionTime() == 2000000000;
     }
 
+    private String resourcePath(String name) throws URISyntaxException
+    {
+        // Naive resource.getPath fails on Windows in many cases, for example 
if there are spaces in the path
+        // which get encoded as %20 which Windows doesn't like. The trick is 
to create a URI first, which satisfies all platforms.
+        return new 
URI(getClass().getClassLoader().getResource(name).toString()).getPath();
+    }
+
     @Test
-    public void testImportSimpleCfOldFormat() throws IOException
+    public void testImportSimpleCfOldFormat() throws IOException, 
URISyntaxException
     {
         // Import JSON to temp SSTable file
-        String jsonUrl = 
getClass().getClassLoader().getResource("SimpleCF.oldformat.json").getPath();
+        String jsonUrl = resourcePath("SimpleCF.oldformat.json");
         File tempSS = tempSSTableFile("Keyspace1", "Standard1");
         SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", 
tempSS.getPath());
 
@@ -95,9 +103,9 @@ public class SSTableImportTest extends S
     }
 
     @Test
-    public void testImportSuperCf() throws IOException, ParseException
+    public void testImportSuperCf() throws IOException, ParseException, 
URISyntaxException
     {
-        String jsonUrl = 
getClass().getClassLoader().getResource("SuperCF.json").getPath();
+        String jsonUrl = resourcePath("SuperCF.json");
         File tempSS = tempSSTableFile("Keyspace1", "Super4");
         SSTableImport.importJson(jsonUrl, "Keyspace1", "Super4", 
tempSS.getPath());
         
@@ -113,9 +121,9 @@ public class SSTableImportTest extends S
     }
 
     @Test
-    public void testImportUnsortedMode() throws IOException
+    public void testImportUnsortedMode() throws IOException, URISyntaxException
     {
-        String jsonUrl = 
getClass().getClassLoader().getResource("UnsortedSuperCF.json").getPath();
+        String jsonUrl = resourcePath("UnsortedSuperCF.json");
         File tempSS = tempSSTableFile("Keyspace1", "Super4");
 
         ColumnFamily columnFamily = ColumnFamily.create("Keyspace1", "Super4");
@@ -127,10 +135,10 @@ public class SSTableImportTest extends S
     }
 
     @Test
-    public void testImportCounterCf() throws IOException
+    public void testImportCounterCf() throws IOException, URISyntaxException
     {
         // Import JSON to temp SSTable file
-        String jsonUrl = 
getClass().getClassLoader().getResource("CounterCF.json").getPath();
+        String jsonUrl = resourcePath("CounterCF.json");
         File tempSS = tempSSTableFile("Keyspace1", "Counter1");
         SSTableImport.importJson(jsonUrl, "Keyspace1", "Counter1", 
tempSS.getPath());
 


Reply via email to