db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1350411 - in /db/derby/code/branches/10.9: ./ java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java
Date Thu, 14 Jun 2012 22:08:41 GMT
Author: kmarsden
Date: Thu Jun 14 22:08:41 2012
New Revision: 1350411

URL: http://svn.apache.org/viewvc?rev=1350411&view=rev
Log:
DERBY-5816 store.ServicePropertiesFileTest fails on z/OS

Fix code and test to read and write to service.properties with a consistent
encoding



Modified:
    db/derby/code/branches/10.9/   (props changed)
    db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java

Propchange: db/derby/code/branches/10.9/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1350258,1350361

Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?rev=1350411&r1=1350410&r2=1350411&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
(original)
+++ db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
Thu Jun 14 22:08:41 2012
@@ -47,6 +47,7 @@ import java.io.FileReader;
 import java.io.InputStream;
 import java.io.BufferedInputStream;
 import java.io.BufferedWriter;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.IOException;
 import java.io.FileNotFoundException;
@@ -359,8 +360,10 @@ final class StorageFactoryService implem
                             properties.store(os, serviceName +
                                 MessageService.getTextMessage(
                                     MessageId.SERVICE_PROPERTIES_DONT_EDIT));
+                            // The eof token should match the ISO-8859-1 encoding 
+                            // of the rest of the properties file written with store.
                             BufferedWriter bOut = new BufferedWriter(
-                                    new OutputStreamWriter(os));
+                                    new OutputStreamWriter(os,"ISO-8859-1"));
                             bOut.write(SERVICE_PROPERTIES_EOF_TOKEN);
                             bOut.newLine();
                             storageFactory.sync( os, false);
@@ -520,7 +523,9 @@ final class StorageFactoryService implem
             BufferedReader bin = null;
             String lastLine = null;
             try {
-                bin = new BufferedReader(new FileReader(spf.getPath()));
+                //service.properties always in ISO-8859-1 because written with Properties.store()
+                bin = new BufferedReader(new InputStreamReader(
+                        new FileInputStream(spf.getPath()),"ISO-8859-1"));
                 String line;
                 while ((line = bin.readLine()) != null) {
                     if (line.trim().length() != 0) {

Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java?rev=1350411&r1=1350410&r2=1350411&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java
(original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java
Thu Jun 14 22:08:41 2012
@@ -25,6 +25,8 @@ import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 
 import java.sql.Connection;
 import java.sql.SQLException;
@@ -49,6 +51,9 @@ import org.apache.derbyTesting.junit.Tes
 public class ServicePropertiesFileTest
         extends BaseJDBCTestCase {
     
+    //Service Properties File is always encoded in US-ASCII
+    // because it is written with Properties.store
+    private static final String SPF_ENCODING = "ISO-8859-1";
     private static final String LOG_A_MODE =
             "derby.storage.logArchiveMode";
     /**
@@ -175,7 +180,7 @@ public class ServicePropertiesFileTest
         // Recover and assert
         connectThenShutdown(db);
         assertNormalPresence();
-        assertEOFToken(spf);
+        assertEOFToken(spf,SPF_ENCODING);
     }
 
     /**
@@ -196,13 +201,13 @@ public class ServicePropertiesFileTest
         String db = "spfTestSPFCWB";
         copyDbAs(db);
         createSPFBackup(true);
-        removeEOFToken(spf);
+        removeEOFToken(spf, SPF_ENCODING);
         assertPresence(true, true);
 
         // Recover and assert
         connectThenShutdown(db);
         assertNormalPresence();
-        assertEOFToken(spf);
+        assertEOFToken(spf,SPF_ENCODING);
     }
 
     /**
@@ -261,10 +266,10 @@ public class ServicePropertiesFileTest
     /**
      * Asserts that the specified file ends with the end-of-file token.
      */
-    private void assertEOFToken(File file)
+    private void assertEOFToken(File file, String encoding)
             throws IOException {
-        BufferedReader in = new BufferedReader(
-                PrivilegedFileOpsForTests.getFileReader(file));
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+                PrivilegedFileOpsForTests.getFileInputStream(file), encoding));
         String prev = null;
         String cur;
         while ((cur = in.readLine()) != null) {
@@ -272,23 +277,25 @@ public class ServicePropertiesFileTest
         }
         in.close();
         assertNotNull("last line is null - empty file?", prev);
-        assertTrue(prev.startsWith(END_TOKEN));
+        assertTrue("prev:" + prev +": does not equal " + END_TOKEN, 
+                prev.startsWith(END_TOKEN));
     }
 
     /**
      * Removes the end-of-file token from the specified file.
      */
-    private void removeEOFToken(File original)
+    private void removeEOFToken(File original, String encoding)
             throws IOException {
         // Move file, then rewrite by removing last line (the token).
         File renamed = new File(original.getAbsolutePath() + "-renamed");
         PrivilegedFileOpsForTests.copy(original, renamed);
         PrivilegedFileOpsForTests.delete(original);
-        BufferedReader in = new BufferedReader(
-                PrivilegedFileOpsForTests.getFileReader(renamed));
-        // Default charset should be 8859_1.
-        BufferedWriter out = new BufferedWriter(
-                PrivilegedFileOpsForTests.getFileWriter(original));
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+                PrivilegedFileOpsForTests.getFileInputStream(renamed),
+                encoding));
+        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
+                PrivilegedFileOpsForTests.getFileOutputStream(original),
+                encoding));
         String prev = null;
         String line;
         while ((line = in.readLine()) != null) {
@@ -316,8 +323,9 @@ public class ServicePropertiesFileTest
     private int grepForToken(String token, File file)
             throws IOException {
         int matchingLines = 0;
-        BufferedReader in = new BufferedReader(
-                PrivilegedFileOpsForTests.getFileReader(file));    
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+                PrivilegedFileOpsForTests.getFileInputStream(file),
+                SPF_ENCODING));    
         String line;
         while ((line = in.readLine()) != null) {
             if (line.indexOf(token) != -1) {
@@ -350,6 +358,7 @@ public class ServicePropertiesFileTest
             PrivilegedFileOpsForTests.delete(spf);
         }
     }
+    
 
     /**
      * Connects to the specified database, then shuts it down.



Mime
View raw message