ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1535328 - in /ace/trunk/org.apache.ace.deployment: src/org/apache/ace/deployment/servlet/ test/org/apache/ace/deployment/servlet/
Date Thu, 24 Oct 2013 09:47:42 GMT
Author: jawi
Date: Thu Oct 24 09:47:41 2013
New Revision: 1535328

URL: http://svn.apache.org/r1535328
Log:
ACE-330 - limit DP-versions for a target:

- added some additional unit tests for the various situations;
- some small updates for the ContentRangeResponseWrapper.


Modified:
    ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/ContentRangeResponseWrapper.java
    ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DefaultDeploymentProcessor.java
    ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/servlet/DeploymentServletTest.java

Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/ContentRangeResponseWrapper.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/ContentRangeResponseWrapper.java?rev=1535328&r1=1535327&r2=1535328&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/ContentRangeResponseWrapper.java
(original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/ContentRangeResponseWrapper.java
Thu Oct 24 09:47:41 2013
@@ -18,13 +18,13 @@
  */
 package org.apache.ace.deployment.servlet;
 
-import java.io.BufferedInputStream;
 import java.io.Closeable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -44,6 +44,7 @@ public class ContentRangeResponseWrapper
      * Internal helper that Wraps a ServletOutputStream to add byte range support.
      */
     private static class ContentRangeOutputStreamWrapper extends ServletOutputStream {
+        private static final int BUFFER_SIZE = 32 * 1024; // kB
 
         private final HttpServletResponse m_response;
         private final long m_requestFirstBytePos;
@@ -52,7 +53,7 @@ public class ContentRangeResponseWrapper
         private final FileOutputStream m_os;
         private final File m_file;
 
-        private long m_instanceLen = 0l;
+        private final AtomicLong m_instanceLen = new AtomicLong(0);
 
         public ContentRangeOutputStreamWrapper(HttpServletResponse response, long firstBytePos,
long lastBytePos) throws IOException {
 
@@ -72,45 +73,42 @@ public class ContentRangeResponseWrapper
 
         @Override
         public void write(int b) throws IOException {
-
             // We only need to buffer the relevant bytes since we keep track of the instance
length in the counter.
-            if (m_instanceLen >= m_requestFirstBytePos
-                && m_instanceLen <= m_requestLastBytePos) {
+            long value = m_instanceLen.getAndIncrement();
+            if (value >= m_requestFirstBytePos && value <= m_requestLastBytePos)
{
                 m_os.write(b);
             }
-            m_instanceLen++;
         }
 
         @Override
         public void close() throws IOException {
             closeQuietly(m_os);
 
-            long instanceLastBytePos = m_instanceLen - 1;
+            long instanceLength = m_instanceLen.get();
+            long instanceLastBytePos = instanceLength - 1L;
             InputStream is = null;
             ServletOutputStream os = null;
 
             try {
                 if (instanceLastBytePos < m_requestFirstBytePos) {
-
                     m_response.setStatus(SC_REQUESTED_RANGE_NOT_SATISFIABLE);
-                    m_response.setHeader("Content-Range", String.format("bytes */%d", m_instanceLen));
+                    m_response.setHeader("Content-Range", String.format("bytes */%d", instanceLength));
                 }
                 else {
-
                     long firstBytePos = m_requestFirstBytePos;
                     long lastBytePos = instanceLastBytePos < m_requestLastBytePos ? instanceLastBytePos
: m_requestLastBytePos;
                     long contentLength = lastBytePos - firstBytePos + 1;
 
                     m_response.setStatus(SC_PARTIAL_CONTENT);
                     m_response.setHeader("Content-Length", String.valueOf(contentLength));
-                    m_response.setHeader("Content-Range", String.format("bytes %d-%d/%d",
firstBytePos, lastBytePos, m_instanceLen));
+                    m_response.setHeader("Content-Range", String.format("bytes %d-%d/%d",
firstBytePos, lastBytePos, instanceLength));
 
-                    is = new BufferedInputStream(new FileInputStream(m_file));
+                    byte[] buffer = new byte[BUFFER_SIZE];
+                    is = new FileInputStream(m_file);
                     os = m_response.getOutputStream();
 
-                    int b;
-                    while ((b = is.read()) != -1) {
-                        os.write(b);
+                    for (int bytesRead = is.read(buffer); bytesRead != -1; bytesRead = is.read(buffer))
{
+                        os.write(buffer, 0, bytesRead);
                     }
                 }
             }
@@ -173,7 +171,8 @@ public class ContentRangeResponseWrapper
      * Extracts and validates the Range header from a request. If the header is found but
is syntactically invalid it
      * will be ignored as required by specification.
      * 
-     * @param request the request to use
+     * @param request
+     *            the request to use
      * @return a long array with two elements (firstBytePos and lastBytePos), or <code>null</code>
if no valid Range
      *         header was found.
      */

Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DefaultDeploymentProcessor.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DefaultDeploymentProcessor.java?rev=1535328&r1=1535327&r2=1535328&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DefaultDeploymentProcessor.java
(original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DefaultDeploymentProcessor.java
Thu Oct 24 09:47:41 2013
@@ -33,13 +33,14 @@ import org.apache.ace.deployment.process
  * client.
  */
 public class DefaultDeploymentProcessor implements DeploymentProcessor {
+    private static final int BUFFER_SIZE = 32 * 1024; // kB
 
     @Override
     public void process(InputStream inputStream, HttpServletRequest request, HttpServletResponse
response) throws IOException {
-        OutputStream output = response.getOutputStream();
+        byte[] buffer = new byte[BUFFER_SIZE];
 
+        OutputStream output = response.getOutputStream();
         try {
-            byte[] buffer = new byte[1024 * 32];
             for (int bytesRead = inputStream.read(buffer); bytesRead != -1; bytesRead = inputStream.read(buffer))
{
                 output.write(buffer, 0, bytesRead);
             }

Modified: ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/servlet/DeploymentServletTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/servlet/DeploymentServletTest.java?rev=1535328&r1=1535327&r2=1535328&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/servlet/DeploymentServletTest.java
(original)
+++ ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/servlet/DeploymentServletTest.java
Thu Oct 24 09:47:41 2013
@@ -109,30 +109,13 @@ public class DeploymentServletTest {
     }
 
     @Test(groups = { UNIT })
-    public void getFixPackageForExistingTargetWithNonExistingFromVersion() throws Exception
{
+    public void getDowngradeFixPackageWithNonExistingToVersion() throws Exception {
         // try to request a version range with a non-existing from-version, should cause
a complete (non-fix) package to
         // be returned...
-        m_requestPathInfo = "/existing/versions/2.0.0";
-        m_requestCurrentParameter = "1.0.0";
-        m_servlet.doGet(m_request, m_response);
-        assertResponseCode(HttpServletResponse.SC_OK);
-        assertResponseOutputSize(100);
-        assertGeneratorTargetId("existing");
-        assertGeneratorToVersion("2.0.0");
-        assertGeneratorFromVersion(null);
-    }
-
-    @Test(groups = { UNIT })
-    public void getFixPackageForExistingTargetWithExistingFromVersion() throws Exception
{
-        // try to request a version range with an existing from-version, should cause a fix
package to be returned...
-        m_requestPathInfo = "/existing/versions/2.0.0";
+        m_requestPathInfo = "/existing/versions/1.0.0";
         m_requestCurrentParameter = "2.0.0";
         m_servlet.doGet(m_request, m_response);
-        assertResponseCode(HttpServletResponse.SC_OK);
-        assertResponseOutputSize(100);
-        assertGeneratorTargetId("existing");
-        assertGeneratorToVersion("2.0.0");
-        assertGeneratorFromVersion("2.0.0");
+        assertResponseCode(HttpServletResponse.SC_NOT_FOUND);
     }
 
     @Test
@@ -238,22 +221,22 @@ public class DeploymentServletTest {
     }
 
     @Test
-    public void getSizeForFixPackageExistingTargetWithKnownSize() throws Exception {
-        m_artifactSize = 10;
-        m_requestCurrentParameter = "2.0.0";
+    public void getSizeForExistingTargetWithUnknownSize() throws Exception {
+        m_artifactSize = -1;
         m_requestPathInfo = "/existing/versions/2.0.0";
         m_servlet.doHead(m_request, m_response);
         assertResponseCode(HttpServletResponse.SC_OK);
-        assertResponseHeaderValue("X-ACE-DPSize", "22"); // 20 + 10%
+        assertResponseHeaderNotPresent("X-ACE-DPSize");
     }
 
     @Test
-    public void getSizeForExistingTargetWithUnknownSize() throws Exception {
-        m_artifactSize = -1;
+    public void getSizeForFixPackageExistingTargetWithKnownSize() throws Exception {
+        m_artifactSize = 10;
+        m_requestCurrentParameter = "2.0.0";
         m_requestPathInfo = "/existing/versions/2.0.0";
         m_servlet.doHead(m_request, m_response);
         assertResponseCode(HttpServletResponse.SC_OK);
-        assertResponseHeaderNotPresent("X-ACE-DPSize");
+        assertResponseHeaderValue("X-ACE-DPSize", "22"); // 20 + 10%
     }
 
     @Test
@@ -266,6 +249,67 @@ public class DeploymentServletTest {
         assertResponseHeaderNotPresent("X-ACE-DPSize");
     }
 
+    @Test(groups = { UNIT })
+    public void getUpgradeFixPackageWithExistingFromVersion() throws Exception {
+        // try to request a version range with an existing from-version, should cause a fix
package to be returned...
+        m_requestPathInfo = "/existing/versions/2.0.0";
+        m_requestCurrentParameter = "2.0.0";
+        m_servlet.doGet(m_request, m_response);
+        assertResponseCode(HttpServletResponse.SC_OK);
+        assertResponseOutputSize(100);
+        assertGeneratorTargetId("existing");
+        assertGeneratorToVersion("2.0.0");
+        assertGeneratorFromVersion("2.0.0");
+    }
+
+    @Test(groups = { UNIT })
+    public void getUpgradeFixPackageWithNonExistingFromVersion() throws Exception {
+        // try to request a version range with a non-existing from-version, should cause
a complete (non-fix) package to
+        // be returned...
+        m_requestPathInfo = "/existing/versions/2.0.0";
+        m_requestCurrentParameter = "1.0.0";
+        m_servlet.doGet(m_request, m_response);
+        assertResponseCode(HttpServletResponse.SC_OK);
+        assertResponseOutputSize(100);
+        assertGeneratorTargetId("existing");
+        assertGeneratorToVersion("2.0.0");
+        assertGeneratorFromVersion(null);
+    }
+
+    @Test(groups = { UNIT })
+    public void getUpgradeFixPackageWithNonExistingToVersion() throws Exception {
+        // try to request a version range with a non-existing from-version, should cause
a complete (non-fix) package to
+        // be returned...
+        m_requestPathInfo = "/existing/versions/3.0.0";
+        m_requestCurrentParameter = "2.0.0";
+        m_servlet.doGet(m_request, m_response);
+        assertResponseCode(HttpServletResponse.SC_NOT_FOUND);
+    }
+
+    @Test(groups = { UNIT })
+    public void getUpgradeWithExistingToVersion() throws Exception {
+        // try to request a version range with a non-existing from-version, should cause
a complete (non-fix) package to
+        // be returned...
+        m_requestPathInfo = "/existing/versions/2.0.0";
+        m_requestCurrentParameter = null;
+        m_servlet.doGet(m_request, m_response);
+        assertResponseCode(HttpServletResponse.SC_OK);
+        assertResponseOutputSize(100);
+        assertGeneratorTargetId("existing");
+        assertGeneratorToVersion("2.0.0");
+        assertGeneratorFromVersion(null);
+    }
+
+    @Test(groups = { UNIT })
+    public void getUpgradeWithNonExistingToVersion() throws Exception {
+        // try to request a version range with a non-existing from-version, should cause
a complete (non-fix) package to
+        // be returned...
+        m_requestPathInfo = "/existing/versions/3.0.0";
+        m_requestCurrentParameter = null;
+        m_servlet.doGet(m_request, m_response);
+        assertResponseCode(HttpServletResponse.SC_NOT_FOUND);
+    }
+
     @Test
     public void getVersionsExistingTarget() throws Exception {
         m_requestPathInfo = "/existing/versions";
@@ -422,6 +466,7 @@ public class DeploymentServletTest {
 
         m_responseStatus = HttpServletResponse.SC_OK;
         m_responseHeaders = new HashMap<String, String>();
+        m_requestRangeHeader = null;
         m_responseOutputStream = new ByteArrayOutputStream();
     }
 



Mime
View raw message