You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2008/02/14 14:18:06 UTC
svn commit: r627734 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
Author: kristwaa
Date: Thu Feb 14 05:18:05 2008
New Revision: 627734
URL: http://svn.apache.org/viewvc?rev=627734&view=rev
Log:
DERBY-3415: 'DataSourceSerializationTestjunit.framework.AssertionFailedError' on Windows.
Added closing of the FileInputStream to the test. Without it, the test failed on Windows platforms during tear down, and it is of course good practice to always clean up :)
Patch file: derby-3415-1a.diff
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java?rev=627734&r1=627733&r2=627734&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceSerializationTest.java Thu Feb 14 05:18:05 2008
@@ -23,6 +23,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.security.AccessController;
@@ -194,25 +195,47 @@
throw (FileNotFoundException)e.getException();
}
- ObjectInputStream ois = new ObjectInputStream(is);
- String buildVersion = ois.readUTF();
- String buildNumber = ois.readUTF();
- println("Data source " + className + ", version " +
- buildVersion + ", build " + buildNumber);
- Object dsObj = ois.readObject();
- assertNotNull("De-serialized data source is null", dsObj);
- assertTrue("Unexpected class instantiated: " +
- dsObj.getClass().getName(),
- dsObj.getClass().getName().indexOf(className) > 0);
- DataSource ds = (DataSource)dsObj;
- // Just see if the object is usable.
- int newTimeout = ds.getLoginTimeout() +9;
- assertFalse(ds.getLoginTimeout() == newTimeout);
- ds.setLoginTimeout(newTimeout);
- assertEquals(newTimeout, ds.getLoginTimeout());
+ assertNotNull("FileInputStream is null", is);
+ Object dsObj = null;
+ DataSource ds = null;
+ Reference dsRef = null;
+ // Used to preserve original error information in case of exception when
+ // closing the input stream.
+ boolean testSequencePassed = false;
+ try {
+ ObjectInputStream ois = new ObjectInputStream(is);
+ String buildVersion = ois.readUTF();
+ String buildNumber = ois.readUTF();
+ println("Data source " + className + ", version " +
+ buildVersion + ", build " + buildNumber);
+ dsObj = ois.readObject();
+ assertNotNull("De-serialized data source is null", dsObj);
+ assertTrue("Unexpected class instantiated: " +
+ dsObj.getClass().getName(),
+ dsObj.getClass().getName().indexOf(className) > 0);
+ ds = (DataSource)dsObj;
+ // Just see if the object is usable.
+ int newTimeout = ds.getLoginTimeout() +9;
+ assertFalse(ds.getLoginTimeout() == newTimeout);
+ ds.setLoginTimeout(newTimeout);
+ assertEquals(newTimeout, ds.getLoginTimeout());
+
+ // Recreate the data source using reference.
+ dsRef = (Reference)ois.readObject();
+ ois.close();
+ testSequencePassed = true;
+ } finally {
+ if (testSequencePassed) {
+ is.close();
+ } else {
+ try {
+ is.close();
+ } catch (IOException ioe) {
+ // Ignore this to preserve the original exception.
+ }
+ }
+ }
- // Recreate the data source using reference.
- Reference dsRef = (Reference)ois.readObject();
String factoryClassName = dsRef.getFactoryClassName();
ObjectFactory factory =
(ObjectFactory)Class.forName(factoryClassName).newInstance();