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 km...@apache.org on 2013/07/17 18:52:35 UTC
svn commit: r1504199 - in /db/derby/code/branches/10.8: ./
java/engine/org/apache/derby/impl/services/monitor/
java/engine/org/apache/derby/loc/
java/shared/org/apache/derby/shared/common/reference/
java/testing/org/apache/derbyTesting/functionTests/te...
Author: kmarsden
Date: Wed Jul 17 16:52:35 2013
New Revision: 1504199
URL: http://svn.apache.org/r1504199
Log:
DERBY-5283 Crash / process termination during SYSCS_DISABLE_LOG_ARCHIVE_MODE can leave service.properties broken
Merge from trunk also includes the fix for DERBY-5816 which was a test failure caused by the original change. The message files had to be manually merged.
revisions merged were:
DERBY-5283 1188109 1188828
DERBY-5816 1350361 1353764
Added:
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java
- copied, changed from r1188109, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java
Modified:
db/derby/code/branches/10.8/ (props changed)
db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml
db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java
db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/SQLState.java
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1188109,1188828,1350361,1353764
Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?rev=1504199&r1=1504198&r2=1504199&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java Wed Jul 17 16:52:35 2013
@@ -39,14 +39,19 @@ import org.apache.derby.io.WritableStora
import org.apache.derby.iapi.reference.Attribute;
import org.apache.derby.iapi.reference.Property;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+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;
+import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.NoSuchElementException;
@@ -63,6 +68,9 @@ import java.security.PrivilegedActionExc
*/
final class StorageFactoryService implements PersistentService
{
+ /** Marker printed as the last line of the service properties file. */
+ private static final String SERVICE_PROPERTIES_EOF_TOKEN =
+ "#--- last line, don't put anything after this line ---";
private String home; // the path of the database home directory. Can be null
private String canonicalHome; // will be null if home is null
@@ -271,6 +279,7 @@ final class StorageFactoryService implem
{
StorageFactory storageFactory = privGetStorageFactoryInstance( true, serviceName, null, null);
StorageFile file = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);
+ resolveServicePropertiesFiles(storageFactory, file);
try {
InputStream is = file.getInputStream();
try {
@@ -318,6 +327,7 @@ final class StorageFactoryService implem
if( ! (sf instanceof WritableStorageFactory))
throw StandardException.newException(SQLState.READ_ONLY_SERVICE);
final WritableStorageFactory storageFactory = (WritableStorageFactory) sf;
+ // Write the service properties to file.
try
{
AccessController.doPrivileged(
@@ -325,63 +335,81 @@ final class StorageFactoryService implem
{
public Object run() throws StandardException
{
- StorageFile backupFile = null;
+ StorageFile backupFile = replace
+ ? storageFactory.newStorageFile(
+ PersistentService.PROPERTIES_NAME.concat("old"))
+ : null;
StorageFile servicePropertiesFile = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);
+ FileOperationHelper foh = new FileOperationHelper();
if (replace)
{
- backupFile = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME.concat("old"));
- try
- {
- if(!servicePropertiesFile.renameTo(backupFile))
- throw StandardException.newException(SQLState.UNABLE_TO_RENAME_FILE,
- servicePropertiesFile, backupFile);
+ foh.renameTo(
+ servicePropertiesFile, backupFile, true);
}
- catch (SecurityException se) { throw Monitor.exceptionStartingModule(se); }
- }
OutputStream os = null;
try
{
os = servicePropertiesFile.getOutputStream();
- properties.store( os, serviceName + MessageService.getTextMessage(MessageId.SERVICE_PROPERTIES_DONT_EDIT));
+ 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,"ISO-8859-1"));
+ bOut.write(SERVICE_PROPERTIES_EOF_TOKEN);
+ bOut.newLine();
storageFactory.sync( os, false);
+ bOut.close();
os.close();
- os = null;
+ os = null;
}
catch (IOException ioe)
{
- if (os != null)
+ if (backupFile != null)
{
- try
+ // Rename the old properties file back again.
+ foh.renameTo(backupFile, servicePropertiesFile,
+ false);
+ }
+ if (replace)
{
- os.close();
+ throw StandardException.newException(
+ SQLState.SERVICE_PROPERTIES_EDIT_FAILED,
+ ioe);
}
- catch (IOException ioe2) {}
- os = null;
+ else
+ {
+ throw Monitor.exceptionStartingModule(ioe);
}
-
- if (backupFile != null)
+ }
+ finally
+ {
+ if (os != null)
{
- // need to re-name the old properties file back again
try
{
- servicePropertiesFile.delete();
- backupFile.renameTo(servicePropertiesFile);
+ os.close();
}
- catch (SecurityException se) {}
+ catch (IOException ioe)
+ {
+ // Ignore exception on close
}
- throw Monitor.exceptionStartingModule(ioe);
+ }
}
if (backupFile != null)
{
- try
+ if (!foh.delete(backupFile, false))
{
- backupFile.delete();
- backupFile = null;
+ Monitor.getStream().printlnWithHeader(
+ MessageService.getTextMessage(
+ MessageId.SERVICE_PROPERTIES_BACKUP_DEL_FAILED,
+ getMostAccuratePath(backupFile)));
+
}
- catch (SecurityException se) {}
}
return null;
}
@@ -474,6 +502,93 @@ final class StorageFactoryService implem
}catch( PrivilegedActionException pae) { throw (StandardException) pae.getException();}
}
+ /**
+ * Resolves situations where a failure condition left the service properties
+ * file, and/or the service properties file backup, in an inconsistent
+ * state.
+ * <p>
+ * Note that this method doesn't resolve the situation where both the
+ * current service properties file and the backup file are missing.
+ *
+ * @param sf the storage factory for the service
+ * @param spf the service properties file
+ * @throws StandardException if a file operation on a service properties
+ * file fails
+ */
+ private void resolveServicePropertiesFiles(StorageFactory sf,
+ StorageFile spf)
+ throws StandardException {
+ StorageFile spfOld = sf.newStorageFile(PROPERTIES_NAME.concat("old"));
+ FileOperationHelper foh = new FileOperationHelper();
+ boolean hasCurrent = foh.exists(spf, true);
+ boolean hasBackup = foh.exists(spfOld, true);
+ // Shortcut the normal case.
+ if (hasCurrent && !hasBackup) {
+ return;
+ }
+
+ // Backup file, but no current file.
+ if (hasBackup && !hasCurrent) {
+ // Writing the new service properties file must have failed during
+ // an update. Rename the backup to be the current file.
+ foh.renameTo(spfOld, spf, true);
+ Monitor.getStream().printlnWithHeader(
+ MessageService.getTextMessage(
+ MessageId.SERVICE_PROPERTIES_RESTORED));
+ // Backup file and current file.
+ } else if (hasBackup && hasCurrent) {
+ // See if the new (current) file is valid. If so delete the backup,
+ // if not, rename the backup to be the current.
+ BufferedReader bin = null;
+ String lastLine = null;
+ try {
+ //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) {
+ lastLine = line;
+ }
+ }
+ } catch (IOException ioe) {
+ throw StandardException.newException(
+ SQLState.UNABLE_TO_OPEN_FILE, ioe,
+ spf.getPath(), ioe.getMessage());
+ } finally {
+ try {
+ if (bin != null) {
+ bin.close();
+ }
+ } catch (IOException ioe) {
+ // Ignore exception during close
+ }
+ }
+ if (lastLine != null &&
+ lastLine.startsWith(SERVICE_PROPERTIES_EOF_TOKEN)) {
+ // Being unable to delete the backup file is fine as long as
+ // the current file appears valid.
+ String msg;
+ if (foh.delete(spfOld, false)) {
+ msg = MessageService.getTextMessage(
+ MessageId.SERVICE_PROPERTIES_BACKUP_DELETED);
+ } else {
+ // Include path so the user can delete file manually.
+ msg = MessageService.getTextMessage(
+ MessageId.SERVICE_PROPERTIES_BACKUP_DEL_FAILED,
+ getMostAccuratePath(spfOld));
+ }
+ Monitor.getStream().printlnWithHeader(msg);
+ } else {
+ foh.delete(spf, false);
+ foh.renameTo(spfOld, spf, true);
+ Monitor.getStream().printlnWithHeader(
+ MessageService.getTextMessage(
+ MessageId.SERVICE_PROPERTIES_RESTORED));
+ }
+ }
+ }
+
/*
**Recreates service root if required depending on which of the following
**attribute is specified on the conection URL:
@@ -717,7 +832,7 @@ final class StorageFactoryService implem
StorageFile seg0 = storageFactory.newStorageFile("seg0");
if (seg0.exists()) {
throw StandardException.newException
- ( SQLState.MISSING_SERVICE_PROPERTIES, serviceName, PersistentService.PROPERTIES_NAME );
+ ( SQLState.SERVICE_PROPERTIES_MISSING, serviceName, PersistentService.PROPERTIES_NAME );
}
}
}
@@ -983,4 +1098,114 @@ final class StorageFactoryService implem
return null;
} // end of run
} // end of class DirectoryList
+
+ /**
+ * Helper method returning the "best-effort-most-accurate" path.
+ *
+ * @param file the file to get the path to
+ * @return The file path, either ala {@code File.getCanonicalPath} or
+ * {@code File.getPath}.
+ */
+ private static String getMostAccuratePath(StorageFile file) {
+ String path = file.getPath();
+ try {
+ path = file.getCanonicalPath();
+ } catch (IOException ioe) {
+ // Ignore this, use path from above.
+ }
+ return path;
}
+
+ /**
+ * Helper class for common file operations on the service properties files.
+ * <p>
+ * Introduced to take care of error reporting for common file operations
+ * carried out in StorageFactoryService.
+ */
+ //@NotThreadSafe
+ private static class FileOperationHelper {
+ /** Name of the most recently performed operation. */
+ private String operation;
+
+ boolean exists(StorageFile file, boolean mustSucceed)
+ throws StandardException {
+ operation = "exists";
+ boolean ret = false;
+ try {
+ ret = file.exists();
+ } catch (SecurityException se) {
+ handleSecPrivException(file, mustSucceed, se);
+ }
+ return ret;
+ }
+
+ boolean delete(StorageFile file, boolean mustSucceed)
+ throws StandardException {
+ operation = "delete";
+ boolean deleted = false;
+ try {
+ deleted = file.delete();
+ } catch (SecurityException se) {
+ handleSecPrivException(file, mustSucceed, se);
+ }
+ if (mustSucceed && !deleted) {
+ throw StandardException.newException(
+ SQLState.UNABLE_TO_DELETE_FILE, file.getPath());
+ }
+ return deleted;
+ }
+
+ boolean renameTo(StorageFile from, StorageFile to, boolean mustSucceed)
+ throws StandardException {
+ operation = "renameTo";
+ // Even if the explicit delete fails, the rename may succeed.
+ delete(to, false);
+ boolean renamed = false;
+ try {
+ renamed = from.renameTo(to);
+ } catch (SecurityException se) {
+ StorageFile file = to;
+ try {
+ // We got a security exception, assume a secman is present.
+ System.getSecurityManager().checkWrite(from.getPath());
+ } catch (SecurityException se1) {
+ file = from;
+ }
+ handleSecPrivException(file, mustSucceed, se);
+ }
+ if (mustSucceed && !renamed) {
+ throw StandardException.newException(
+ SQLState.UNABLE_TO_RENAME_FILE,
+ from.getPath(), to.getPath());
+ }
+ return renamed;
+ }
+
+ /**
+ * Handles security exceptions caused by missing privileges on the
+ * files being accessed.
+ *
+ * @param file the file that was accessed
+ * @param mustSucceed if {@code true} a {@code StandardException} will
+ * be thrown, if {@code false} a warning is written to the log
+ * @param se the security exception raised
+ * @throws StandardException if {@code mustSucceed} is {@code true}
+ * @throws NullPointerException if {@code file} or {@code se} is null
+ */
+ private void handleSecPrivException(StorageFile file,
+ boolean mustSucceed,
+ SecurityException se)
+ throws StandardException {
+ if (mustSucceed) {
+ throw StandardException.newException(
+ SQLState.MISSING_FILE_PRIVILEGE, se, operation,
+ file.getName(), se.getMessage());
+ } else {
+ Monitor.getStream().printlnWithHeader(
+ MessageService.getTextMessage(
+ SQLState.MISSING_FILE_PRIVILEGE, operation,
+ getMostAccuratePath(file), se.getMessage()));
+ }
+ }
+ } // End of static class FileOperationHelper
+}
Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml?rev=1504199&r1=1504198&r2=1504199&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml Wed Jul 17 16:52:35 2013
@@ -3715,6 +3715,20 @@ Guide.
</msg>
<msg>
+ <name>XBM0B.D</name>
+ <text>Failed to edit/write service properties file: {0}</text>
+ <arg>errorMessage</arg>
+ </msg>
+
+ <msg>
+ <name>XBM0C.D</name>
+ <text>Missing privilege for operation '{0}' on file '{1}': {2}</text>
+ <arg>operation</arg>
+ <arg>path</arg>
+ <arg>errorMessage</arg>
+ </msg>
+
+ <msg>
<name>XBM0G.D</name>
<text>Failed to start encryption engine. Please make sure you are running Java 2 and have downloaded an encryption provider such as jce and put it in your class path. </text>
</msg>
@@ -8204,6 +8218,22 @@ Shutting down instance {0} on database d
# ********************************************************************</text>
</msg>
+ <msg>
+ <name>M002</name>
+ <text>Restored missing/corrupted service properties from backup file.</text>
+ </msg>
+
+ <msg>
+ <name>M003</name>
+ <text>Deleted leftover service properties backup file.</text>
+ </msg>
+
+ <msg>
+ <name>M004</name>
+ <text>Failed to delete leftover service properties backup file, delete it manually: {0}</text>
+ <arg>servicePropertiesBackupFile</arg>
+ </msg>
+
</family>
</section>
Modified: db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=1504199&r1=1504198&r2=1504199&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java (original)
+++ db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java Wed Jul 17 16:52:35 2013
@@ -209,7 +209,15 @@ public interface MessageId {
/*
* Monitor
*/
- String SERVICE_PROPERTIES_DONT_EDIT = "M001"; // Tell user not to edit service.properties
+
+ /** Tell user not to edit service.properties. */
+ String SERVICE_PROPERTIES_DONT_EDIT = "M001";
+ /** Informational message, service properties restored. */
+ String SERVICE_PROPERTIES_RESTORED = "M002";
+ /** Informational message, service properties backup deleted. */
+ String SERVICE_PROPERTIES_BACKUP_DELETED = "M003";
+ /** Informational message, service properties backup deletion failed. */
+ String SERVICE_PROPERTIES_BACKUP_DEL_FAILED = "M004";
/*
* Replication
Modified: db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1504199&r1=1504198&r2=1504199&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/SQLState.java (original)
+++ db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/SQLState.java Wed Jul 17 16:52:35 2013
@@ -164,7 +164,9 @@ public interface SQLState {
String SERVICE_MISSING_IMPLEMENTATION = "XBM02.D";
String MISSING_PRODUCT_VERSION = "XBM05.D";
String SERVICE_WRONG_BOOT_PASSWORD = "XBM06.D";
- String MISSING_SERVICE_PROPERTIES = "XBM0A.D";
+ String SERVICE_PROPERTIES_MISSING = "XBM0A.D";
+ String SERVICE_PROPERTIES_EDIT_FAILED = "XBM0B.D";
+ String MISSING_FILE_PRIVILEGE = "XBM0C.D";
String SERVICE_BOOT_PASSWORD_TOO_SHORT = "XBM07.D";
String MISSING_ENCRYPTION_PROVIDER = "XBM0G.D";
String SERVICE_DIRECTORY_CREATE_ERROR = "XBM0H.D";
Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java?rev=1504199&r1=1504198&r2=1504199&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ErrorCodeTest.java Wed Jul 17 16:52:35 2013
@@ -168,6 +168,8 @@ public final class ErrorCodeTest extends
{"XBM07","Startup failed. Boot password must be at least 8 bytes long.","45000"},
{"XBM08","Could not instantiate {0} StorageFactory class {1}.","45000"},
{"XBM0A","The database directory '{0}' exists. However, it does not contain the expected '{1}' file. Perhaps Derby was brought down in the middle of creating this database. You may want to delete this directory and try creating the database again.","45000"},
+ {"XBM0B","Failed to edit/write service properties file: {0}","45000"},
+ {"XBM0C","Missing privilege for operation '{0}' on file '{1}': {2}", "45000"},
{"XBM0G","Failed to start encryption engine. Please make sure you are running Java 2 and have downloaded an encryption provider such as jce and put it in your class path. ","45000"},
{"XBM0H","Directory {0} cannot be created.","45000"},
{"XBM0I","Directory {0} cannot be removed.","45000"},
Copied: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java (from r1188109, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java)
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java?p2=db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java&r1=1188109&r2=1504199&rev=1504199&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/ServicePropertiesFileTest.java Wed Jul 17 16:52:35 2013
@@ -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,10 @@ import org.apache.derbyTesting.junit.Tes
public class ServicePropertiesFileTest
extends BaseJDBCTestCase {
+ //DERBY-5816
+ //Service Properties File is always encoded in ISO-8859-1
+ // 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 +181,7 @@ public class ServicePropertiesFileTest
// Recover and assert
connectThenShutdown(db);
assertNormalPresence();
- assertEOFToken(spf);
+ assertEOFToken(spf,SPF_ENCODING);
}
/**
@@ -196,13 +202,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 +267,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 +278,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 +324,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 +359,7 @@ public class ServicePropertiesFileTest
PrivilegedFileOpsForTests.delete(spf);
}
}
+
/**
* Connects to the specified database, then shuts it down.
Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java?rev=1504199&r1=1504198&r2=1504199&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java Wed Jul 17 16:52:35 2013
@@ -79,7 +79,8 @@ public class _Suite extends BaseTestCase
suite.addTest(AutomaticIndexStatisticsMultiTest.suite());
suite.addTest(BTreeMaxScanTest.suite());
suite.addTest(MadhareTest.suite());
-
+ suite.addTest(ServicePropertiesFileTest.suite());
+
/* Tests that only run in sane builds */
if (SanityManager.DEBUG) {
suite.addTest(HoldCursorExternalSortJDBC30Test.suite());