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:26:57 UTC
svn commit: r1471082 - in /accumulo/branches/1.5/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:26:57 2013
New Revision: 1471082
URL: http://svn.apache.org/r1471082
Log:
ACCUMULO-482 added some unit test for the proxy and fixed some issues
Modified:
accumulo/branches/1.5/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
Modified: accumulo/branches/1.5/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java?rev=1471082&r1=1471081&r2=1471082&view=diff
==============================================================================
--- accumulo/branches/1.5/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java (original)
+++ accumulo/branches/1.5/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java Tue Apr 23 18:26:57 2013
@@ -1004,12 +1004,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());
}
@@ -1031,10 +1044,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) {
@@ -1055,7 +1065,7 @@ public class ProxyServer implements Accu
return ret;
}
}
-
+
@Override
public void closeScanner(String scanner) throws UnknownScanner, TException {
try {
@@ -1143,10 +1153,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);
@@ -1156,15 +1163,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);
}
@@ -1173,20 +1179,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 {
BatchWriterConfig cfg = new BatchWriterConfig();
Modified: accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java?rev=1471082&r1=1471081&r2=1471082&view=diff
==============================================================================
--- accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java (original)
+++ accumulo/branches/1.5/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java Tue Apr 23 18:26:57 2013
@@ -38,6 +38,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.client.security.tokens.PasswordToken;
@@ -71,9 +72,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.test.MiniAccumuloCluster;
import org.apache.accumulo.test.functional.SlowIterator;
@@ -306,6 +310,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)) {