You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2013/04/23 20:28:14 UTC

svn commit: r1471083 - in /accumulo/branches/1.4/src/proxy/src: main/java/org/apache/accumulo/proxy/ProxyServer.java test/java/org/apache/accumulo/proxy/SimpleTest.java

Author: kturner
Date: Tue Apr 23 18:28:14 2013
New Revision: 1471083

URL: http://svn.apache.org/r1471083
Log:
ACCUMULO-1200 added some unit test for the proxy and fixed some issues

Modified:
    accumulo/branches/1.4/src/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
    accumulo/branches/1.4/src/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java

Modified: accumulo/branches/1.4/src/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java?rev=1471083&r1=1471082&r2=1471083&view=diff
==============================================================================
--- accumulo/branches/1.4/src/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java (original)
+++ accumulo/branches/1.4/src/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java Tue Apr 23 18:28:14 2013
@@ -970,12 +970,25 @@ public class ProxyServer implements Accu
     }
   }
   
-  @Override
-  public boolean hasNext(String scanner) throws UnknownScanner, TException {
-    ScannerPlusIterator spi = scannerCache.getIfPresent(UUID.fromString(scanner));
+  private ScannerPlusIterator getScanner(String scanner) throws UnknownScanner {
+    
+    UUID uuid = null;
+    try {
+      uuid = UUID.fromString(scanner);
+    } catch (IllegalArgumentException e) {
+      throw new UnknownScanner(e.getMessage());
+    }
+    
+    ScannerPlusIterator spi = scannerCache.getIfPresent(uuid);
     if (spi == null) {
       throw new UnknownScanner("Scanner never existed or no longer exists");
     }
+    return spi;
+  }
+  
+  @Override
+  public boolean hasNext(String scanner) throws UnknownScanner, TException {
+    ScannerPlusIterator spi = getScanner(scanner);
     
     return (spi.iterator.hasNext());
   }
@@ -997,10 +1010,7 @@ public class ProxyServer implements Accu
       TException {
     
     // fetch the scanner
-    ScannerPlusIterator spi = scannerCache.getIfPresent(UUID.fromString(scanner));
-    if (spi == null) {
-      throw new UnknownScanner("Scanner never existed or no longer exists");
-    }
+    ScannerPlusIterator spi = getScanner(scanner);
     Iterator<Map.Entry<Key,Value>> batchScanner = spi.iterator;
     // synchronized to prevent race conditions
     synchronized (batchScanner) {
@@ -1021,7 +1031,7 @@ public class ProxyServer implements Accu
       return ret;
     }
   }
-  
+
   @Override
   public void closeScanner(String scanner) throws UnknownScanner, TException {
     try {
@@ -1109,10 +1119,7 @@ public class ProxyServer implements Accu
   @Override
   public void update(String writer, Map<ByteBuffer,List<ColumnUpdate>> cells) throws TException {
     try {
-      BatchWriterPlusException bwpe = writerCache.getIfPresent(UUID.fromString(writer));
-      if (bwpe == null) {
-        throw new UnknownWriter("Writer never existed or no longer exists");
-      }
+      BatchWriterPlusException bwpe = getWriter(writer);
       addCellsToWriter(cells, bwpe);
     } catch (Exception e) {
       throw new TException(e);
@@ -1122,15 +1129,14 @@ public class ProxyServer implements Accu
   @Override
   public void flush(String writer) throws UnknownWriter, org.apache.accumulo.proxy.thrift.MutationsRejectedException, TException {
     try {
-      BatchWriterPlusException bwpe = writerCache.getIfPresent(UUID.fromString(writer));
-      if (bwpe == null) {
-        throw new UnknownWriter("Writer never existed or no longer exists");
-      }
+      BatchWriterPlusException bwpe = getWriter(writer);
       if (bwpe.exception != null)
         throw bwpe.exception;
       bwpe.writer.flush();
     } catch (MutationsRejectedException e) {
       throw new org.apache.accumulo.proxy.thrift.MutationsRejectedException(e.toString());
+    } catch (UnknownWriter uw) {
+      throw uw;
     } catch (Exception e) {
       throw new TException(e);
     }
@@ -1139,20 +1145,34 @@ public class ProxyServer implements Accu
   @Override
   public void closeWriter(String writer) throws UnknownWriter, org.apache.accumulo.proxy.thrift.MutationsRejectedException, TException {
     try {
-      BatchWriterPlusException bwpe = writerCache.getIfPresent(UUID.fromString(writer));
-      if (bwpe == null) {
-        throw new UnknownWriter("Writer never existed or no longer exists");
-      }
+      BatchWriterPlusException bwpe = getWriter(writer);
       if (bwpe.exception != null)
         throw bwpe.exception;
       bwpe.writer.close();
       writerCache.invalidate(UUID.fromString(writer));
+    } catch (UnknownWriter uw) {
+      throw uw;
     } catch (MutationsRejectedException e) {
       throw new org.apache.accumulo.proxy.thrift.MutationsRejectedException(e.toString());
     } catch (Exception e) {
       throw new TException(e);
     }
   }
+
+  private BatchWriterPlusException getWriter(String writer) throws UnknownWriter {
+    UUID uuid = null;
+    try {
+      uuid = UUID.fromString(writer);
+    } catch (IllegalArgumentException iae) {
+      throw new UnknownWriter(iae.getMessage());
+    }
+    
+    BatchWriterPlusException bwpe = writerCache.getIfPresent(uuid);
+    if (bwpe == null) {
+      throw new UnknownWriter("Writer never existed or no longer exists");
+    }
+    return bwpe;
+  }
   
   private BatchWriterPlusException getWriter(ByteBuffer login, String tableName, WriterOptions opts) throws Exception {
     if (opts == null)

Modified: accumulo/branches/1.4/src/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java?rev=1471083&r1=1471082&r2=1471083&view=diff
==============================================================================
--- accumulo/branches/1.4/src/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java (original)
+++ accumulo/branches/1.4/src/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java Tue Apr 23 18:28:14 2013
@@ -36,6 +36,7 @@ import java.util.Properties;
 import java.util.Random;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.UUID;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.conf.DefaultConfiguration;
@@ -66,9 +67,12 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.accumulo.proxy.thrift.ScanState;
 import org.apache.accumulo.proxy.thrift.ScanType;
 import org.apache.accumulo.proxy.thrift.SystemPermission;
+import org.apache.accumulo.proxy.thrift.TableExistsException;
 import org.apache.accumulo.proxy.thrift.TableNotFoundException;
 import org.apache.accumulo.proxy.thrift.TablePermission;
 import org.apache.accumulo.proxy.thrift.TimeType;
+import org.apache.accumulo.proxy.thrift.UnknownScanner;
+import org.apache.accumulo.proxy.thrift.UnknownWriter;
 import org.apache.accumulo.proxy.thrift.WriterOptions;
 import org.apache.accumulo.server.test.functional.SlowIterator;
 import org.apache.accumulo.test.MiniAccumuloCluster;
@@ -289,6 +293,60 @@ public class SimpleTest {
   }
   
   @Test(timeout = 10000)
+  public void testExists() throws Exception {
+    client.createTable(creds, "ett1", false, TimeType.MILLIS);
+    client.createTable(creds, "ett2", false, TimeType.MILLIS);
+    try {
+      client.createTable(creds, "ett1", false, TimeType.MILLIS);
+      fail("exception not thrown");
+    } catch (TableExistsException tee) {}
+    try {
+      client.renameTable(creds, "ett1", "ett2");
+      fail("exception not thrown");
+    } catch (TableExistsException tee) {}
+    try {
+      client.cloneTable(creds, "ett1", "ett2", false, new HashMap<String,String>(), new HashSet<String>());
+      fail("exception not thrown");
+    } catch (TableExistsException tee) {}
+  }
+  
+  @Test(timeout = 10000)
+  public void testUnknownScanner() throws Exception {
+    try {
+      client.nextEntry("99999999");
+      fail("exception not thrown");
+    } catch (UnknownScanner us) {}
+    try {
+      client.nextK("99999999", 6);
+      fail("exception not thrown");
+    } catch (UnknownScanner us) {}
+    try {
+      client.hasNext("99999999");
+      fail("exception not thrown");
+    } catch (UnknownScanner us) {}
+    try {
+      client.hasNext(UUID.randomUUID().toString());
+      fail("exception not thrown");
+    } catch (UnknownScanner us) {}
+  }
+  
+  @Test(timeout = 10000)
+  public void testUnknownWriter() throws Exception {
+    try {
+      client.flush("99999");
+      fail("exception not thrown");
+    } catch (UnknownWriter uw) {}
+    try {
+      client.flush(UUID.randomUUID().toString());
+      fail("exception not thrown");
+    } catch (UnknownWriter uw) {}
+    try {
+      client.closeWriter("99999");
+      fail("exception not thrown");
+    } catch (UnknownWriter uw) {}
+  }
+  
+  @Test(timeout = 10000)
   public void testInstanceOperations() throws Exception {
     int tservers = 0;
     for (String tserver : client.getTabletServers(creds)) {