public class ServicePropertiesFileTest extends BaseJDBCTestCase
The basic pattern of the tests is to start with a pristine database, modify 'service.properties' and/or 'service.propertiesold', and then finally boot the database and assert what happened with the two aforementioned files.
Modifier and Type | Field and Description |
---|---|
private static java.io.File |
databasesDir
Where the databases are living.
|
private static java.lang.String |
DB_NAME
Logical name of the pristine database.
|
private static boolean |
dbInitialized
Whether the pristine database has been initialized or not.
|
private java.io.File |
dbToDelete
Database that will be deleted during
shutDown . |
private static java.lang.String |
END_TOKEN
End-of-file token used by Derby in 'service.properties'.
|
private static java.lang.String |
LOG_A_MODE |
private static java.io.File |
pristineDb
Path to the pristine database.
|
private java.io.File |
spf
Path to 'service.properties' of the current database.
|
private static java.lang.String |
SPF_ENCODING |
private java.io.File |
spfOld
Path to 'service.propertiesold' of the current database.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
ServicePropertiesFileTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private void |
assertEOFToken(java.io.File file,
java.lang.String encoding)
Asserts that the specified file ends with the end-of-file token.
|
private void |
assertNormalPresence()
Asserts that the presence of the service properties file and the backup
is normal, that is that the former is present and the latter isn't.
|
private void |
assertPresence(boolean spfPresence,
boolean spfOldPresence)
Asserts the specified presence of the original and the backup service
properties files.
|
private void |
connectThenShutdown(java.lang.String db)
Connects to the specified database, then shuts it down.
|
private void |
copyDbAs(java.lang.String name)
Copies the master/pristine database to a new database.
|
private void |
createSPFBackup(boolean keepOriginal)
Dependent on state set by copyDbAs(java.lang.String).
|
private int |
grepForToken(java.lang.String token,
java.io.File file)
Looks for the specified token in the given file.
|
private void |
removeEOFToken(java.io.File original,
java.lang.String encoding)
Removes the end-of-file token from the specified file.
|
void |
setUp()
Initializes the pristine database if required.
|
static junit.framework.Test |
suite() |
void |
tearDown()
Deletes the last database copy (if one exists).
|
void |
testBackupWithBackupExisting()
Ensures that Derby can handle the case where the backup file already
exists when editing the service properties.
|
void |
testMissingServicePropertiesFileNoBackup()
Tests what happens when the service properties file is missing and there
is no backup available.
|
void |
testMissingServicePropertiesFileWithBackup()
Tests handling of the situation where the service properties file is
missing, but a backup is available.
|
void |
testSevicePropertiesFileCorruptedWithBackup()
Tests the situation where both the service properties file and a backup
are available, but the service properties file is corrupted (see note
below).
|
void |
testSevicePropertiesFileWithBackup()
Tests handling of the situation where both the service properties file
and the backup are available.
|
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepare, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodStatement, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, usingDB2Client, usingDerbyNetClient, usingEmbedded
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, toString
private static final java.lang.String SPF_ENCODING
private static final java.lang.String LOG_A_MODE
private static final java.lang.String END_TOKEN
private static final java.lang.String DB_NAME
private static java.io.File databasesDir
private static java.io.File pristineDb
private static boolean dbInitialized
private java.io.File dbToDelete
shutDown
.private java.io.File spf
copyDbAs(java.lang.String)
private java.io.File spfOld
copyDbAs(java.lang.String)
public ServicePropertiesFileTest(java.lang.String name)
public void setUp() throws java.sql.SQLException
setUp
in class junit.framework.TestCase
java.sql.SQLException
public void tearDown() throws java.lang.Exception
tearDown
in class BaseJDBCTestCase
java.lang.Exception
public void testMissingServicePropertiesFileNoBackup() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testMissingServicePropertiesFileWithBackup() throws java.io.IOException, java.sql.SQLException
The expected behavior is to restore (by renaming) the service properties file from the backup.
java.io.IOException
java.sql.SQLException
public void testSevicePropertiesFileWithBackup() throws java.io.IOException, java.sql.SQLException
Expected behavior here is to delete the backup (given that the original service properties file contains the end-of-file token).
java.io.IOException
java.sql.SQLException
public void testSevicePropertiesFileCorruptedWithBackup() throws java.io.IOException, java.sql.SQLException
The expected behavior is to delete the original service properties file and then restore it from the backup (i.e. by renaming).
In this regard, a corrupt service properties file is one where the end-of-file token is missing. No other error conditions are detected, i.e. if properties are removed manually or the values are modified.
java.io.IOException
java.sql.SQLException
public void testBackupWithBackupExisting() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void assertNormalPresence()
private void assertPresence(boolean spfPresence, boolean spfOldPresence)
spfPresence
- presence of the original filespfOldPresence
- presence of the backup fileprivate void assertEOFToken(java.io.File file, java.lang.String encoding) throws java.io.IOException
java.io.IOException
private void removeEOFToken(java.io.File original, java.lang.String encoding) throws java.io.IOException
java.io.IOException
private int grepForToken(java.lang.String token, java.io.File file) throws java.io.IOException
token
- the search tokenfile
- the file to searchjava.io.IOException
- if accessing the specified file failsprivate void copyDbAs(java.lang.String name) throws java.io.IOException
name
- name of the database to copy tojava.io.IOException
private void createSPFBackup(boolean keepOriginal) throws java.io.IOException
java.io.IOException
private void connectThenShutdown(java.lang.String db) throws java.sql.SQLException
This method is used to trigger the recovery logic for the service properties file.
db
- database to connect to (expected to live in 'system/singleUse')java.sql.SQLException
public static junit.framework.Test suite()
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.