public class BTreeMaxScanTest extends BaseJDBCTestCase
Modifier and Type | Class and Description |
---|---|
private static class |
BTreeMaxScanTest.AtomicInt
Poor man's replacement for java.util.concurrent.atomic.AtomicInteger
that runs on platforms where java.util.concurrent isn't available.
|
private static class |
BTreeMaxScanTest.Result
This class represents a result from an asynchronous operation.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
traceFlags
List of SanityManager debug flags to reset on teardown.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
BTreeMaxScanTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private static BTreeMaxScanTest.Result |
asyncGetSingleResult(java.sql.Statement s,
java.lang.String sql)
Execute a statement asynchronously and return an object that can be
used to retrieve the result once the statement is complete.
|
private void |
setTraceFlag(java.lang.String flag)
If running with a debug build and derby.tests.trace is true, enable
tracing for messages with the specified flag.
|
static junit.framework.Test |
suite()
Create a test suite with all the test cases in this class.
|
protected void |
tearDown()
Tear down the test environment.
|
void |
testEmptyRightmostLeaf()
Test that latch conflicts between forward scans and backward (max) scans
are resolved without deadlocking or other errors when the rightmost
leaf page of the B-tree is empty.
|
void |
testOppositeScanDirections()
Test that scanners that work in opposite directions don't deadlock.
|
void |
testRestartScanAfterWaitOnMaxRow()
Test that a max scan which cannot immediately lock the rightmost row
in the index, restarts the scan when it wakes up to see if the row it
waited for is still the maximum row.
|
void |
testSerializable()
Test that B-tree max scans reposition correctly after waiting for a
lock on the last row and detect any new max value inserted while the
scan was waiting for the lock.
|
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, setUp, toString
private java.util.List<java.lang.String> traceFlags
public static junit.framework.Test suite()
protected void tearDown() throws java.lang.Exception
tearDown
in class BaseJDBCTestCase
java.lang.Exception
public void testRestartScanAfterWaitOnMaxRow() throws java.lang.Exception
java.lang.Exception
public void testOppositeScanDirections() throws java.lang.Exception
java.lang.Exception
public void testEmptyRightmostLeaf() throws java.lang.Exception
Test that latch conflicts between forward scans and backward (max) scans are resolved without deadlocking or other errors when the rightmost leaf page of the B-tree is empty. In that case, the backward scan must restart, since it doesn't have any saved position to return to.
The test is performed by running two threads that scan the leaves of the B-tree in the forward direction, while at the same time two threads do a backward max scan on the same B-tree. In parallel with the threads that scan the index, the main thread will repeatedly delete the rows with the highest values in order to create a window where the scans may see an empty page, sleep a little, and then re-insert the deleted rows.
java.lang.Exception
public void testSerializable() throws java.lang.Exception
Test that B-tree max scans reposition correctly after waiting for a lock on the last row and detect any new max value inserted while the scan was waiting for the lock.
Note: Currently, B-tree max scans always take a table lock when running with serializable isolation level, so the scans in this test case will not actually be blocked waiting for a row lock. The test case is added to verify that the scans behave correctly if the lock mode is changed in the future.
java.lang.Exception
private static BTreeMaxScanTest.Result asyncGetSingleResult(java.sql.Statement s, java.lang.String sql)
s
- the statement object to use for executionsql
- the SQL to executeResult
object that allows retrieval of the result
once it's availableprivate void setTraceFlag(java.lang.String flag)
flag
- the debug flag to enableApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.