http-client-branch: Make ResponeBodyTest is more tolerant of file size http-client-branch
authorchegar
Mon, 06 Nov 2017 13:06:34 +0000
branchhttp-client-branch
changeset 55766 2136ad3694e4
parent 55765 c56b15998860
child 55768 8674257c75ce
child 55769 4ecfe77d0c24
http-client-branch: Make ResponeBodyTest is more tolerant of file size
test/jdk/java/net/httpclient/RequestBodyTest.java
--- a/test/jdk/java/net/httpclient/RequestBodyTest.java	Mon Nov 06 12:24:15 2017 +0000
+++ b/test/jdk/java/net/httpclient/RequestBodyTest.java	Mon Nov 06 13:06:34 2017 +0000
@@ -176,7 +176,7 @@
     }
 
     static final int DEFAULT_OFFSET = 10;
-    static final int DEFAULT_LENGTH = 1000;
+    static final int DEFAULT_LENGTH_FACTOR = 4/5;
 
     HttpRequest createRequest(URI uri,
                               RequestBody requestBodyType,
@@ -194,7 +194,9 @@
                 rb.POST(fromByteArray(fileAsBytes));
                 break;
             case BYTE_ARRAY_OFFSET:
-                rb.POST(fromByteArray(fileAsBytes, DEFAULT_OFFSET, DEFAULT_LENGTH));
+                rb.POST(fromByteArray(fileAsBytes,
+                                      DEFAULT_OFFSET,
+                                      fileAsBytes.length * DEFAULT_LENGTH_FACTOR));
                 break;
             case BYTE_ARRAYS:
                 Iterable<byte[]> iterable = Arrays.asList(fileAsBytes);
@@ -231,9 +233,8 @@
         byte[] fileAsBytes = getFileBytes(filename);
         if (requestBodyType == RequestBody.BYTE_ARRAY_OFFSET) {
             // Truncate the expected response body, if only a portion was sent
-            fileAsBytes = Arrays.copyOfRange(fileAsBytes,
-                                             DEFAULT_OFFSET,
-                                             DEFAULT_OFFSET + DEFAULT_LENGTH);
+            int length = DEFAULT_OFFSET + (fileAsBytes.length * DEFAULT_LENGTH_FACTOR);
+            fileAsBytes = Arrays.copyOfRange(fileAsBytes, DEFAULT_OFFSET, length);
         }
         String fileAsString = new String(fileAsBytes, UTF_8);
         Path tempFile = Paths.get("RequestBodyTest.tmp");