jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1209513 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/client/ main/java/org/apache/jackrabbit/mk/server/ test/java/org/apache/jackrabbit/mk/ test/java/org/apache/jackrabbit...
Date Fri, 02 Dec 2011 14:37:04 GMT
Author: dpfister
Date: Fri Dec  2 14:37:04 2011
New Revision: 1209513

URL: http://svn.apache.org/viewvc?rev=1209513&view=rev
Log:
add remoting layer to stack of test urls
- avoid unnecessary synthetic accessor methods
- make remote client thread-safe
- finish unread bytes in client response stream

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/HttpExecutor.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Request.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
Fri Dec  2 14:37:04 2011
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.client.Client;
 import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.mem.MemoryKernelImpl;
+import org.apache.jackrabbit.mk.server.Server;
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.wrapper.IndexWrapper;
 import org.apache.jackrabbit.mk.wrapper.LogWrapper;
@@ -81,6 +82,21 @@ public class MicroKernelFactory {
             } catch (URISyntaxException e) {
                 throw new IllegalArgumentException(e.getMessage());
             }
+        } else if (url.startsWith("remote:")) {
+            try {
+                MicroKernel mk = getInstance(url.substring("remote:".length()));
+                final Server server = new Server(mk);
+                server.setPort(0);
+                server.start();
+                return new Client(server.getAddress()) {
+                    public void dispose() {
+                        super.dispose();
+                        server.stop();
+                    }
+                };
+            } catch (IOException e) {
+                throw new IllegalArgumentException(e.getMessage());
+            }
         } else {
             throw new IllegalArgumentException(url);
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
Fri Dec  2 14:37:04 2011
@@ -50,7 +50,7 @@ public class Client implements MicroKern
 
     //-------------------------------------------------- implements MicroKernel
     
-    public void dispose() {
+    public synchronized void dispose() {
         if (disposed) {
             return;
         }
@@ -61,7 +61,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String getHeadRevision() throws MicroKernelException {
+    public synchronized String getHeadRevision() throws MicroKernelException {
         Request request = null;
         
         try {
@@ -74,7 +74,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String getRevisions(long since, int maxEntries)
+    public synchronized String getRevisions(long since, int maxEntries)
             throws MicroKernelException {
 
         Request request = null;
@@ -91,7 +91,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String waitForCommit(String oldHeadRevision, long maxWaitMillis)
+    public synchronized String waitForCommit(String oldHeadRevision, long maxWaitMillis)
             throws MicroKernelException, InterruptedException {
 
         Request request = null;
@@ -108,7 +108,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String getJournal(String fromRevisionId, String toRevisionId)
+    public synchronized String getJournal(String fromRevisionId, String toRevisionId)
             throws MicroKernelException {
         
         Request request = null;
@@ -125,7 +125,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String diff(String fromRevisionId, String toRevisionId,
+    public synchronized String diff(String fromRevisionId, String toRevisionId,
                        String path)
             throws MicroKernelException {
         Request request = null;
@@ -143,7 +143,7 @@ public class Client implements MicroKern
         }
     }
 
-    public boolean nodeExists(String path, String revisionId)
+    public synchronized boolean nodeExists(String path, String revisionId)
             throws MicroKernelException {
 
         Request request = null;
@@ -160,13 +160,13 @@ public class Client implements MicroKern
         }
     }
 
-    public String getNodes(String path, String revisionId)
+    public synchronized String getNodes(String path, String revisionId)
             throws MicroKernelException {
 
         return getNodes(path, revisionId, 1, 0, -1);
     }
 
-    public String getNodes(String path, String revisionId, int depth,
+    public synchronized String getNodes(String path, String revisionId, int depth,
             long offset, int count) throws MicroKernelException {
         
         Request request = null;
@@ -186,7 +186,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String commit(String path, String jsonDiff, String revisionId, String message)
+    public synchronized String commit(String path, String jsonDiff, String revisionId, String
message)
             throws MicroKernelException {
         
         Request request = null;
@@ -205,7 +205,7 @@ public class Client implements MicroKern
         }
     }
 
-    public long getLength(String blobId) throws MicroKernelException {
+    public synchronized long getLength(String blobId) throws MicroKernelException {
         Request request = null;
 
         try {
@@ -219,7 +219,7 @@ public class Client implements MicroKern
         }
     }
 
-    public int read(String blobId, long pos, byte[] buff, int off, int length)
+    public synchronized int read(String blobId, long pos, byte[] buff, int off, int length)
             throws MicroKernelException {
 
         Request request = null;
@@ -237,7 +237,7 @@ public class Client implements MicroKern
         }
     }
 
-    public String write(InputStream in) throws MicroKernelException {
+    public synchronized String write(InputStream in) throws MicroKernelException {
         Request request = null;
 
         try {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/HttpExecutor.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/HttpExecutor.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/HttpExecutor.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/HttpExecutor.java
Fri Dec  2 14:37:04 2011
@@ -170,7 +170,11 @@ class HttpExecutor implements Closeable 
         case 200:
             return reqIn;
         case 500:
-            throw new IOException(readLine(reqIn));
+            try {
+                throw new IOException(readLine(reqIn));
+            } finally {
+                IOUtils.closeQuietly(reqIn);
+            }
         default:
             String msg = String.format("HTTP request failed with status code: %d", statusCode);
             throw new IOException(msg);
@@ -180,7 +184,7 @@ class HttpExecutor implements Closeable 
     public boolean isAlive() {
         return !connectionClosed && !socket.isClosed();
     }
-
+    
     public void close() {
         IOUtils.closeQuietly(socketOut);
         IOUtils.closeQuietly(socketIn);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Request.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Request.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Request.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Request.java
Fri Dec  2 14:37:04 2011
@@ -181,6 +181,8 @@ class Request implements Closeable {
     }
     
     public void close() {
+        IOUtils.closeQuietly(resultIn);
+        
         executor = null;
     }
     

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Fri Dec  2 14:37:04 2011
@@ -236,7 +236,7 @@ class MicroKernelServlet {
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
 
-            String blobId = request.getParameter("blob_id");
+            String blobId = request.getParameter("blob_id", "");
             long length = mk.getLength(blobId);
 
             response.setContentType("text/plain");
@@ -249,7 +249,7 @@ class MicroKernelServlet {
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
 
-            String blobId = request.getParameter("blob_id");
+            String blobId = request.getParameter("blob_id", "");
             long pos = request.getParameter("pos", 0L);
             int length = request.getParameter("length", -1); 
             

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
Fri Dec  2 14:37:04 2011
@@ -163,7 +163,7 @@ class Response implements Closeable {
      * @param len length
      * @throws IOException if an I/O error occurs
      */
-    private void writeBody(byte[] b, int off, int len) throws IOException {
+    void writeBody(byte[] b, int off, int len) throws IOException {
         if (out == null) {
             return;
         }
@@ -208,7 +208,7 @@ class Response implements Closeable {
     /**
      * Internal <code>OutputStream</code> passed to servlet handlers.
      */
-    private class BodyOutputStream extends OutputStream {
+    class BodyOutputStream extends OutputStream {
         
         /**
          * Buffer size chosen intentionally to not exceed maximum chunk

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
Fri Dec  2 14:37:04 2011
@@ -83,22 +83,26 @@ public class Server {
         
         new Thread(new Runnable() {
             public void run() {
-                try {
-                    while (!stopped.get()) {
-                        final Socket socket = ss.accept();
-                        es.execute(new Runnable() {
-                            public void run() {
-                                handle(socket);
-                            }
-                        });
-                    }
-                } catch (IOException e) {
-                    /* ignore */
-                }
+                accept();
             }
         }, "Acceptor").start();
     }
     
+    void accept() {
+        try {
+            while (!stopped.get()) {
+                final Socket socket = ss.accept();
+                es.execute(new Runnable() {
+                    public void run() {
+                        handle(socket);
+                    }
+                });
+            }
+        } catch (IOException e) {
+            /* ignore */
+        }
+    }
+    
     private ServerSocket createServerSocket() throws IOException {
         return new ServerSocket(port);
     }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MultiMkTestBase.java
Fri Dec  2 14:37:04 2011
@@ -37,13 +37,18 @@ public class MultiMkTestBase {
             return Arrays.asList(new Object[][]{
                     {"fs:{homeDir}/target"},
                     {"mem:"},
-                    {"mem:fs:target/temp"}
+                    {"mem:fs:target/temp"},
+                    {"remote:fs:{homeDir}/target"}
                     });
     }
 
     @Before
     public void setUp() throws Exception {
         mk = MicroKernelFactory.getInstance(url + ";clean");
+        if (url.startsWith("remote:")) {
+            /* remove prefix so tests know when to run */
+            url = url.substring("remote:".length());
+        }
     }
 
     @After

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java?rev=1209513&r1=1209512&r2=1209513&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java
Fri Dec  2 14:37:04 2011
@@ -107,7 +107,7 @@ public class DataStoreTest extends Multi
                 }
                 buff.write(x);
             } else if (op == 1) {
-                byte[] x = new byte[minLen + r.nextInt(100)];
+                byte[] x = new byte[minLen + r.nextInt(5000)];
                 int l = in.read(x);
                 if (l < 0) {
                     break;
@@ -115,7 +115,7 @@ public class DataStoreTest extends Multi
                 buff.write(x, 0, l);
             } else {
                 int offset = r.nextInt(10);
-                int len = minLen + r.nextInt(20);
+                int len = minLen + r.nextInt(1000);
                 byte[] x = new byte[offset + len];
                 int l = in.read(x, offset, len);
                 if (l < 0) {



Mime
View raw message