chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1785948 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src: main/java/org/apache/chemistry/opencmis/server/shared/ test/java/org/apache/chemistry/opencmis/server/impl/
Date Wed, 08 Mar 2017 11:35:29 GMT
Author: fmui
Date: Wed Mar  8 11:35:29 2017
New Revision: 1785948

URL: http://svn.apache.org/viewvc?rev=1785948&view=rev
Log:
added more unit tests for ThresholdOutputStream

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java?rev=1785948&r1=1785947&r2=1785948&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
Wed Mar  8 11:35:29 2017
@@ -120,7 +120,8 @@ public class ThresholdOutputStream exten
      * @param encrypt
      *            indicates if temporary files must be encrypted
      */
-    public ThresholdOutputStream(int initSize, File tempDir, int memoryThreshold, long maxContentSize,
boolean encrypt) {
+    public ThresholdOutputStream(int initSize, File tempDir, int memoryThreshold, long maxContentSize,
+            boolean encrypt) {
         if (initSize < 0) {
             throw new IllegalArgumentException("Negative initial size: " + initSize);
         }
@@ -160,8 +161,8 @@ public class ThresholdOutputStream exten
             return;
         }
 
-        int newSize = ((bufSize + nextBufferSize) * 2 < MAX_GROW ? (bufSize + nextBufferSize)
* 2 : buf.length
-                + nextBufferSize + MAX_GROW);
+        int newSize = ((bufSize + nextBufferSize) * 2 < MAX_GROW ? (bufSize + nextBufferSize)
* 2
+                : buf.length + nextBufferSize + MAX_GROW);
         byte[] newbuf = new byte[newSize];
         System.arraycopy(buf, 0, newbuf, 0, bufSize);
         buf = newbuf;
@@ -362,7 +363,7 @@ public class ThresholdOutputStream exten
             tmpStream = null;
         }
 
-        if (tempFile != null) {
+        if (tempFile != null && tempFile.exists()) {
             boolean isDeleted = tempFile.delete();
             if (!isDeleted) {
                 if (LOG.isErrorEnabled()) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java?rev=1785948&r1=1785947&r2=1785948&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
Wed Mar  8 11:35:29 2017
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.lang.reflect.Field;
 
 import org.apache.chemistry.opencmis.commons.server.TempStoreOutputStream;
 import org.apache.chemistry.opencmis.server.shared.TempStoreOutputStreamFactory;
@@ -209,7 +210,7 @@ public class ThresholdOutputStreamTest {
     }
 
     @Test
-    public void testDestroy() throws Exception {
+    public void testClose() throws Exception {
         TempStoreOutputStreamFactory streamFactory = TempStoreOutputStreamFactory.newInstance(null,
0, 1024, false);
 
         TempStoreOutputStream tempStream = streamFactory.newOutputStream();
@@ -230,7 +231,33 @@ public class ThresholdOutputStreamTest {
         File tempFile = tis.getTemporaryFile();
         assertTrue(tempFile.exists());
 
-        // destroy
+        // close stream -> delete temp file
+        tis.close();
+
+        // check temp file
+        assertFalse(tempFile.exists());
+    }
+
+    @Test
+    public void testDestroy() throws Exception {
+        TempStoreOutputStreamFactory streamFactory = TempStoreOutputStreamFactory.newInstance(null,
0, 1024, false);
+
+        TempStoreOutputStream tempStream = streamFactory.newOutputStream();
+        tempStream.setMimeType(MIME_TYPE_2);
+        tempStream.setFileName(FILE_NAME_2);
+        assertTrue(tempStream instanceof ThresholdOutputStream);
+
+        // set content
+        ThresholdOutputStream tos = (ThresholdOutputStream) tempStream;
+        tos.write(CONTENT);
+        tos.close();
+
+        // get temp file
+        Field tempFileField = ThresholdOutputStream.class.getDeclaredField("tempFile");
+        tempFileField.setAccessible(true);
+        File tempFile = (File) tempFileField.get(tos);
+
+        // destroy -> delete temp file
         tempStream.destroy(new Exception("ohoh"));
 
         // check temp file



Mime
View raw message