accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1440939 - in /accumulo/trunk: core/src/main/java/org/apache/accumulo/core/util/ proxy/ proxy/src/main/java/org/apache/accumulo/proxy/ proxy/src/test/java/org/apache/accumulo/proxy/
Date Thu, 31 Jan 2013 12:53:24 GMT
Author: kturner
Date: Thu Jan 31 12:53:23 2013
New Revision: 1440939

URL: http://svn.apache.org/viewvc?rev=1440939&view=rev
Log:
ACCUMULO-991 Removed ability to configure transport in proxy.  Also made unit test use different
protocols and found/fixed some bugs as a result.

Modified:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
    accumulo/trunk/proxy/proxy.properties
    accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
    accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
    accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
    accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java Thu
Jan 31 12:53:23 2013
@@ -28,7 +28,7 @@ public class ByteBufferUtil {
   public static byte[] toBytes(ByteBuffer buffer) {
     if (buffer == null)
       return null;
-    return Arrays.copyOfRange(buffer.array(), buffer.position(), buffer.remaining());
+    return Arrays.copyOfRange(buffer.array(), buffer.position(), buffer.limit());
   }
   
   public static List<ByteBuffer> toByteBuffers(Collection<byte[]> bytesList)
{

Modified: accumulo/trunk/proxy/proxy.properties
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/proxy.properties?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/proxy.properties (original)
+++ accumulo/trunk/proxy/proxy.properties Thu Jan 31 12:53:23 2013
@@ -3,7 +3,6 @@ accumulo.proxy.apis=org.apache.accumulo.
 org.apache.accumulo.proxy.ProxyServer.useMockInstance=false
 org.apache.accumulo.proxy.thrift.AccumuloProxy.implementor=org.apache.accumulo.proxy.ProxyServer
 org.apache.accumulo.proxy.thrift.AccumuloProxy.protocolFactory=org.apache.thrift.protocol.TCompactProtocol$Factory
-org.apache.accumulo.proxy.thrift.AccumuloProxy.transportFactory=org.apache.thrift.transport.TFramedTransport$Factory
 org.apache.accumulo.proxy.thrift.AccumuloProxy.port=42424
 
 org.apache.accumulo.proxy.ProxyServer.instancename=test

Modified: accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java (original)
+++ accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java Thu Jan 31 12:53:23
2013
@@ -27,8 +27,8 @@ import org.apache.thrift.TProcessor;
 import org.apache.thrift.protocol.TProtocolFactory;
 import org.apache.thrift.server.THsHaServer;
 import org.apache.thrift.server.TServer;
+import org.apache.thrift.transport.TFramedTransport;
 import org.apache.thrift.transport.TNonblockingServerSocket;
-import org.apache.thrift.transport.TTransportFactory;
 
 import com.beust.jcommander.IStringConverter;
 import com.beust.jcommander.Parameter;
@@ -84,17 +84,15 @@ public class Proxy {
       Class<?> implementor = Class.forName(opts.prop.getProperty(api + ".implementor"));
       
       Class<? extends TProtocolFactory> protoFactoryClass = Class.forName(opts.prop.getProperty(api
+ ".protocolFactory")).asSubclass(TProtocolFactory.class);
-      Class<? extends TTransportFactory> transportFactoryClass = Class.forName(opts.prop.getProperty(api
+ ".transportFactory")).asSubclass(
-          TTransportFactory.class);
 
       int port = Integer.parseInt(opts.prop.getProperty(api + ".port"));
-      TServer server = createProxyServer(apiclass, implementor, port, protoFactoryClass,
transportFactoryClass, opts.prop);
+      TServer server = createProxyServer(apiclass, implementor, port, protoFactoryClass,
opts.prop);
       server.serve();
     }
   }
   
   public static TServer createProxyServer(Class<?> api, Class<?> implementor,
final int port, Class<? extends TProtocolFactory> protoClass,
-      Class<? extends TTransportFactory> transportFactoryClass, Properties properties)
throws Exception {
+      Properties properties) throws Exception {
     final TNonblockingServerSocket socket = new TNonblockingServerSocket(port);
 
     // create the implementor
@@ -109,7 +107,7 @@ public class Proxy {
     
     THsHaServer.Args args = new THsHaServer.Args(socket);
     args.processor(processor);
-    args.transportFactory(transportFactoryClass.newInstance());
+    args.transportFactory(new TFramedTransport.Factory());
     args.protocolFactory(protoClass.newInstance());
     return new THsHaServer(args);
   }

Modified: accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java (original)
+++ accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java Thu Jan
31 12:53:23 2013
@@ -603,7 +603,7 @@ public class ProxyServer implements Accu
   @Override
   public boolean authenticateUser(ByteBuffer login, String user, ByteBuffer password) throws
TException {
     try {
-      return getConnector(login).securityOperations().authenticateUser(new UserPassToken(user,
password.array()));
+      return getConnector(login).securityOperations().authenticateUser(new UserPassToken(user,
ByteBufferUtil.toBytes(password)));
     } catch (Exception e) {
       throw translateException(e);
     }
@@ -625,7 +625,7 @@ public class ProxyServer implements Accu
   @Override
   public void changeUserPassword(ByteBuffer login, String user, ByteBuffer password) throws
TException {
     try {
-      getConnector(login).securityOperations().changeUserPassword(new UserPassToken(user,
password.array()));
+      getConnector(login).securityOperations().changeUserPassword(new UserPassToken(user,
ByteBufferUtil.toBytes(password)));
     } catch (Exception e) {
       throw translateException(e);
     }

Modified: accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java (original)
+++ accumulo/trunk/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java Thu
Jan 31 12:53:23 2013
@@ -33,6 +33,7 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.accumulo.proxy.thrift.UserPass;
 import org.apache.thrift.protocol.TCompactProtocol;
 import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TProtocolFactory;
 import org.apache.thrift.transport.TFramedTransport;
 import org.apache.thrift.transport.TSocket;
 import org.apache.thrift.transport.TTransport;
@@ -44,10 +45,14 @@ public class TestProxyClient {
   protected TTransport transport;
   
   public TestProxyClient(String host, int port) throws TTransportException {
+    this(host, port, new TCompactProtocol.Factory());
+  }
+  
+  public TestProxyClient(String host, int port, TProtocolFactory protoFactory) throws TTransportException
{
     final TSocket socket = new TSocket(host, port);
     socket.setTimeout(600000);
     transport = new TFramedTransport(socket);
-    final TProtocol protocol = new TCompactProtocol(transport);
+    final TProtocol protocol = protoFactory.getProtocol(transport);
     proxy = new AccumuloProxy.Client(protocol);
     transport.open();
   }

Modified: accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java (original)
+++ accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java Thu Jan 31
12:53:23 2013
@@ -26,6 +26,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStreamReader;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.EnumSet;
@@ -67,8 +68,8 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.accumulo.proxy.thrift.TablePermission;
 import org.apache.accumulo.proxy.thrift.TimeType;
 import org.apache.accumulo.proxy.thrift.UserPass;
-import org.apache.accumulo.test.functional.SlowIterator;
 import org.apache.accumulo.test.MiniAccumuloCluster;
+import org.apache.accumulo.test.functional.SlowIterator;
 import org.apache.commons.io.FileUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
@@ -76,9 +77,8 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.Text;
 import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TCompactProtocol;
+import org.apache.thrift.protocol.TProtocolFactory;
 import org.apache.thrift.server.TServer;
-import org.apache.thrift.transport.TFramedTransport;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -101,6 +101,19 @@ public class SimpleTest {
   private static UserPass userpass = new UserPass("root", ByteBuffer.wrap(secret.getBytes()));
   private static ByteBuffer creds = null;
 
+  private static Class<? extends TProtocolFactory> protocolClass;
+
+  static Class<? extends TProtocolFactory> getRandomProtocol() {
+    List<Class<? extends TProtocolFactory>> protocolFactories = new ArrayList<Class<?
extends TProtocolFactory>>();
+    protocolFactories.add(org.apache.thrift.protocol.TJSONProtocol.Factory.class);
+    protocolFactories.add(org.apache.thrift.protocol.TBinaryProtocol.Factory.class);
+    protocolFactories.add(org.apache.thrift.protocol.TTupleProtocol.Factory.class);
+    protocolFactories.add(org.apache.thrift.protocol.TCompactProtocol.Factory.class);
+    
+    Random rand = new Random();
+    return protocolFactories.get(rand.nextInt(protocolFactories.size()));
+  }
+
   @BeforeClass
   public static void setupMiniCluster() throws Exception {
     folder.create();
@@ -111,9 +124,12 @@ public class SimpleTest {
     props.put("org.apache.accumulo.proxy.ProxyServer.instancename", accumulo.getInstanceName());
     props.put("org.apache.accumulo.proxy.ProxyServer.zookeepers", accumulo.getZookeepers());
     
+    protocolClass = getRandomProtocol();
+    System.out.println(protocolClass.getName());
+
     proxyPort = 40000 + random.nextInt(20000);
     proxyServer = Proxy.createProxyServer(org.apache.accumulo.proxy.thrift.AccumuloProxy.class,
org.apache.accumulo.proxy.ProxyServer.class, proxyPort,
-        TCompactProtocol.Factory.class, TFramedTransport.Factory.class, props);
+        protocolClass, props);
     thread = new Thread() {
       @Override
       public void run() {
@@ -123,7 +139,7 @@ public class SimpleTest {
     thread.start();
     while (!proxyServer.isServing())
       UtilWaitThread.sleep(100);
-    client = new TestProxyClient("localhost", proxyPort).proxy();
+    client = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance()).proxy();
     creds = client.login(userpass);
   }
 
@@ -171,11 +187,11 @@ public class SimpleTest {
       public void run() {
         String scanner;
         try {
-          Client client2 = new TestProxyClient("localhost", proxyPort).proxy();
+          Client client2 = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance()).proxy();
           scanner = client2.createScanner(creds, "slow", null);
           client2.nextK(scanner, 10);
           client2.closeScanner(scanner);
-        } catch (TException e) {
+        } catch (Exception e) {
           throw new RuntimeException(e);
         }
       }
@@ -209,9 +225,9 @@ public class SimpleTest {
       @Override
       public void run() {
         try {
-          Client client2 = new TestProxyClient("localhost", proxyPort).proxy();
+          Client client2 = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance()).proxy();
           client2.compactTable(creds, "slow", null, null, null, true, true);
-        } catch (TException e) {
+        } catch (Exception e) {
           throw new RuntimeException(e);
         }
       }
@@ -495,7 +511,7 @@ public class SimpleTest {
   @AfterClass
   public static void tearDownMiniCluster() throws Exception {
     accumulo.stop();
-    folder.delete();
+    // folder.delete();
   }
   
 }

Modified: accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
(original)
+++ accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
Thu Jan 31 12:53:23 2013
@@ -27,7 +27,6 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TCompactProtocol;
 import org.apache.thrift.server.TServer;
-import org.apache.thrift.transport.TFramedTransport;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -45,7 +44,7 @@ public class TestProxyInstanceOperations
     prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance", "true");
     
     proxy = Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
Class.forName("org.apache.accumulo.proxy.ProxyServer"),
-        port, TCompactProtocol.Factory.class, TFramedTransport.Factory.class, prop);
+        port, TCompactProtocol.Factory.class, prop);
     thread = new Thread() {
       @Override
       public void run() {

Modified: accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java (original)
+++ accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java Thu
Jan 31 12:53:23 2013
@@ -40,7 +40,6 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.accumulo.proxy.thrift.UserPass;
 import org.apache.thrift.protocol.TCompactProtocol;
 import org.apache.thrift.server.TServer;
-import org.apache.thrift.transport.TFramedTransport;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -61,7 +60,7 @@ public class TestProxyReadWrite {
     prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance", "true");
     
     proxy = Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
Class.forName("org.apache.accumulo.proxy.ProxyServer"),
-        port, TCompactProtocol.Factory.class, TFramedTransport.Factory.class, prop);
+        port, TCompactProtocol.Factory.class, prop);
     thread = new Thread() {
       @Override
       public void run() {

Modified: accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
(original)
+++ accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
Thu Jan 31 12:53:23 2013
@@ -32,7 +32,6 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TCompactProtocol;
 import org.apache.thrift.server.TServer;
-import org.apache.thrift.transport.TFramedTransport;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -55,7 +54,7 @@ public class TestProxySecurityOperations
     prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance", "true");
     
     proxy = Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
Class.forName("org.apache.accumulo.proxy.ProxyServer"),
-        port, TCompactProtocol.Factory.class, TFramedTransport.Factory.class, prop);
+        port, TCompactProtocol.Factory.class, prop);
     thread = new Thread() {
       @Override
       public void run() {

Modified: accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java?rev=1440939&r1=1440938&r2=1440939&view=diff
==============================================================================
--- accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
(original)
+++ accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
Thu Jan 31 12:53:23 2013
@@ -36,7 +36,6 @@ import org.apache.accumulo.proxy.thrift.
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TCompactProtocol;
 import org.apache.thrift.server.TServer;
-import org.apache.thrift.transport.TFramedTransport;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -58,7 +57,7 @@ public class TestProxyTableOperations {
     prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance", "true");
     
     proxy = Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
Class.forName("org.apache.accumulo.proxy.ProxyServer"),
-        port, TCompactProtocol.Factory.class, TFramedTransport.Factory.class, prop);
+        port, TCompactProtocol.Factory.class, prop);
     thread = new Thread() {
       @Override
       public void run() {



Mime
View raw message