public class OSReadOnlyTest extends BaseJDBCTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
OSReadOnlyTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private void |
assertExpectedInsertBehaviour(javax.sql.DataSource ds,
boolean expectedSuccess,
int insertIntValue,
java.lang.String insertStringValue) |
private void |
assertReadDB(javax.sql.DataSource ds) |
protected static junit.framework.Test |
baseSuite(java.lang.String name) |
static boolean |
changeDirectoryToReadOnly(java.io.File directory)
Change all of the files in a directory and its subdirectories
to read only.
|
void |
changeFilePermissions(java.lang.String dir) |
private java.io.File |
constructDbPath(java.lang.String relDbDirName)
Constructs the path to the database base directory.
|
private void |
createDummyLockFile(java.lang.String dbDir)
Creates a dummy database lock file if one doesn't exist, and sets the
lock file to read-only.
|
private java.lang.String |
getPhysicalDbName() |
private void |
moveDatabaseOnOS(java.lang.String fromwhere,
java.lang.String todir)
Moves the database from one location to another location.
|
private static junit.framework.Test |
newCleanDatabase(BaseTestSuite s) |
private void |
shutdownDB(javax.sql.DataSource ds) |
static junit.framework.Test |
suite() |
private boolean |
supportsSetReadOnly()
Check if
File.setReadOnly() has any effect in this environment. |
void |
testOSReadOnly()
Test that if we make the files comprising the database read-only
on OS level, the database reacts as if it's in 'ReadOnly' mode
|
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, tearDown, 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, setUp, toString
private static junit.framework.Test newCleanDatabase(BaseTestSuite s)
protected static junit.framework.Test baseSuite(java.lang.String name)
public static junit.framework.Test suite()
public void testOSReadOnly() throws java.lang.Exception
java.lang.Exception
private boolean supportsSetReadOnly() throws java.io.IOException
File.setReadOnly()
has any effect in this environment.
For example, if the test runs as a privileged user, it may be able
to modify a file even if it has been made read-only. If so, it doesn't
make any sense to run this test.true
if File.setReadOnly()
prevents file
modifications; otherwise, false
java.io.IOException
- if an unexpected error happensprivate java.lang.String getPhysicalDbName()
private void shutdownDB(javax.sql.DataSource ds) throws java.sql.SQLException
java.sql.SQLException
private void assertReadDB(javax.sql.DataSource ds) throws java.sql.SQLException
java.sql.SQLException
private void assertExpectedInsertBehaviour(javax.sql.DataSource ds, boolean expectedSuccess, int insertIntValue, java.lang.String insertStringValue) throws java.sql.SQLException
java.sql.SQLException
private void moveDatabaseOnOS(java.lang.String fromwhere, java.lang.String todir) throws java.io.IOException
fromwhere
- source directorytodir
- destination directoryjava.io.IOException
- if the copy failsprivate void createDummyLockFile(java.lang.String dbDir)
This method is a work-around for the problem that Java cannot make a file writable before Java 6.
dbDir
- the database directory where the lock file belongspublic void changeFilePermissions(java.lang.String dir)
private java.io.File constructDbPath(java.lang.String relDbDirName)
relDbDirName
- the database name (relative)public static boolean changeDirectoryToReadOnly(java.io.File directory)
directory
- the directory File handle to start recursing from.true
for success, false
otherwiseApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.