You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by se...@apache.org on 2009/08/26 15:15:51 UTC
svn commit: r807997 - in
/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs:
TestIdentityDecoder.java TestLengthDelimitedDecoder.java
TestLengthDelimitedEncoder.java
Author: sebb
Date: Wed Aug 26 13:15:51 2009
New Revision: 807997
URL: http://svn.apache.org/viewvc?rev=807997&view=rev
Log:
Close files so they can be deleted
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java?rev=807997&r1=807996&r2=807997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java Wed Aug 26 13:15:51 2009
@@ -209,7 +209,7 @@
}
private void deleteWithCheck(File handle){
- if (!handle.delete()){
+ if (!handle.delete() && handle.exists()){
System.err.println("Failed to delete: "+handle.getPath());
}
}
@@ -311,7 +311,8 @@
decoder.transfer(fchannel, 5, 10);
fail("expected IOException");
} catch(IOException iox) {}
-
+
+ testfile.close();
deleteWithCheck(fileHandle);
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java?rev=807997&r1=807996&r2=807997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java Wed Aug 26 13:15:51 2009
@@ -317,7 +317,7 @@
}
private void deleteWithCheck(File handle){
- if (!handle.delete()){
+ if (!handle.delete() && handle.exists()){
System.err.println("Failed to delete: "+handle.getPath());
}
}
@@ -419,6 +419,7 @@
fail("expected IOException");
} catch(IOException iox) {}
+ testfile.close();
deleteWithCheck(fileHandle);
}
@@ -453,6 +454,7 @@
assertTrue(decoder.isCompleted());
assertEquals(16, metrics.getBytesTransferred());
+ testfile.close();
deleteWithCheck(fileHandle);
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java?rev=807997&r1=807996&r2=807997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedEncoder.java Wed Aug 26 13:15:51 2009
@@ -171,7 +171,7 @@
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
channel, outbuf, metrics, 16);
- File tmpFile = File.createTempFile("testFile", "txt");
+ File tmpFile = File.createTempFile("testFile", ".txt");
FileOutputStream fout = new FileOutputStream(tmpFile);
OutputStreamWriter wrtout = new OutputStreamWriter(fout);
@@ -190,11 +190,13 @@
assertTrue(encoder.isCompleted());
assertEquals("stuff;more stuff", s);
+ fchannel.close();
+
deleteWithCheck(tmpFile);
}
private void deleteWithCheck(File handle){
- if (!handle.delete()){
+ if (!handle.delete() && handle.exists()){
System.err.println("Failed to delete: "+handle.getPath());
}
}
@@ -211,7 +213,7 @@
encoder.write(wrap("stuff;"));
//Create an empty file
- File tmpFile = File.createTempFile("testFile", "txt");
+ File tmpFile = File.createTempFile("testFile", ".txt");
FileOutputStream fout = new FileOutputStream(tmpFile);
OutputStreamWriter wrtout = new OutputStreamWriter(fout);
@@ -229,6 +231,7 @@
assertTrue(encoder.isCompleted());
assertEquals("stuff;more stuff", s);
+ fchannel.close();
deleteWithCheck(tmpFile);
}
@@ -243,7 +246,7 @@
channel, outbuf, metrics, 5);
encoder.write(wrap("stuff"));
- File tmpFile = File.createTempFile("testFile", "txt");
+ File tmpFile = File.createTempFile("testFile", ".txt");
FileOutputStream fout = new FileOutputStream(tmpFile);
OutputStreamWriter wrtout = new OutputStreamWriter(fout);
@@ -252,13 +255,14 @@
wrtout.flush();
wrtout.close();
+ FileChannel fchannel = new FileInputStream(tmpFile).getChannel();
try {
- FileChannel fchannel = new FileInputStream(tmpFile).getChannel();
encoder.transfer(fchannel, 0, 10);
fail("IllegalStateException should have been thrown");
} catch (IllegalStateException ex) {
// ignore
} finally {
+ fchannel.close();
deleteWithCheck(tmpFile);
}
}
@@ -273,7 +277,7 @@
LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
channel, outbuf, metrics, 16);
- File tmpFile = File.createTempFile("testFile", "txt");
+ File tmpFile = File.createTempFile("testFile", ".txt");
FileOutputStream fout = new FileOutputStream(tmpFile);
OutputStreamWriter wrtout = new OutputStreamWriter(fout);
@@ -292,6 +296,7 @@
assertTrue(encoder.isCompleted());
assertEquals("stuff;more stuff", s);
+ fchannel.close();
deleteWithCheck(tmpFile);
}