cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1441030 - in /cxf/trunk/api/src: main/java/org/apache/cxf/io/CachedWriter.java test/java/org/apache/cxf/io/CachedOutputStreamTest.java test/java/org/apache/cxf/io/CachedWriterTest.java
Date Thu, 31 Jan 2013 16:00:25 GMT
Author: ay
Date: Thu Jan 31 16:00:25 2013
New Revision: 1441030

URL: http://svn.apache.org/viewvc?rev=1441030&view=rev
Log:
[CXF-4797] CachedWriter may leave temp files undeleted

Added:
    cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedWriterTest.java
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedWriter.java
    cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedWriter.java?rev=1441030&r1=1441029&r2=1441030&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedWriter.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedWriter.java Thu Jan 31 16:00:25 2013
@@ -481,9 +481,8 @@ public class CachedWriter extends Writer
                         closed = true;
                     }
                 };
-                Reader r = new InputStreamReader(fileInputStream, "UTF-8");
-                streamList.add(r);
-                return r;
+                streamList.add(fileInputStream);
+                return new InputStreamReader(fileInputStream, "UTF-8");
             } catch (FileNotFoundException e) {
                 throw new IOException("Cached file was deleted, " + e.toString());
             }

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java?rev=1441030&r1=1441029&r2=1441030&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java (original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java Thu Jan 31 16:00:25
2013
@@ -62,6 +62,25 @@ public class CachedOutputStreamTest exte
     }
 
     @Test
+    public void testDeleteTmpFile2() throws IOException {
+        CachedOutputStream cos = new CachedOutputStream();        
+        //ensure output data size larger then 64k which will generate tmp file
+        String result = initTestData(65);
+        cos.write(result.getBytes());
+        //assert tmp file is generated
+        File tempFile = cos.getTempFile();
+        assertNotNull(tempFile);
+        assertTrue(tempFile.exists());
+        InputStream in = cos.getInputStream();
+        cos.close();
+        //assert tmp file is not deleted when the input stream is open
+        assertTrue(tempFile.exists());
+        in.close();
+        //assert tmp file is deleted after the input stream is closed
+        assertFalse(tempFile.exists());
+    }
+
+    @Test
     public void testEncryptAndDecryptWithDeleteOnClose() throws IOException {
         CachedOutputStream cos = new CachedOutputStream();
         cos.setThreshold(4);

Added: cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedWriterTest.java?rev=1441030&view=auto
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedWriterTest.java (added)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/io/CachedWriterTest.java Thu Jan 31 16:00:25
2013
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringWriter;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CachedWriterTest extends Assert {    
+    
+    @Test
+    public void testResetOut() throws IOException {
+        CachedWriter cos = new CachedWriter();        
+        String result = initTestData(16);
+        cos.write(result);
+        StringWriter out = new StringWriter();
+        cos.resetOut(out, true);
+        String test = out.toString();
+        assertEquals("The test stream content isn't same ", test , result);
+        cos.close();
+    }
+    
+    @Test
+    public void testDeleteTmpFile() throws IOException {
+        CachedWriter cos = new CachedWriter();        
+        //ensure output data size larger then 64k which will generate tmp file
+        String result = initTestData(65);
+        cos.write(result);
+        //assert tmp file is generated
+        File tempFile = cos.getTempFile();
+        assertNotNull(tempFile);
+        assertTrue(tempFile.exists());
+        cos.close();
+        //assert tmp file is deleted after close the CachedOutputStream
+        assertFalse(tempFile.exists());
+    }
+
+    @Test
+    public void testDeleteTmpFile2() throws IOException {
+        CachedWriter cos = new CachedWriter();
+        //ensure output data size larger then 64k which will generate tmp file
+        String result = initTestData(65);
+        cos.write(result);
+        //assert tmp file is generated
+        File tempFile = cos.getTempFile();
+        assertNotNull(tempFile);
+        assertTrue(tempFile.exists());
+        Reader in = cos.getReader();
+        cos.close();
+        //assert tmp file is not deleted when the reader is open
+        assertTrue(tempFile.exists());
+        in.close();
+        //assert tmp file is deleted after the reader is closed
+        assertFalse(tempFile.exists());
+    }
+
+    String initTestData(int packetSize) {
+        String temp = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+?><[]/0123456789";
+        String result = new String();
+        for (int i = 0; i <  1024 * packetSize / temp.length(); i++) {
+            result = result + temp;
+        }
+        return result;
+    }
+    
+
+}
+    
+   



Mime
View raw message