public class AutomaticIndexStatisticsTest extends BaseJDBCTestCase
Some of the tests ensure that the daemon is able to recover after encountering various kinds of "expected errors", for instance if the table is dropped while being scanned by the daemon.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
BIG_TABLE |
private static boolean |
dbCreated |
private static long |
DEFAULT_TIMEOUT |
protected static java.lang.String |
MASTERDB |
private static IndexStatsUtil |
stats |
private static java.lang.String[] |
TYPES |
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
AutomaticIndexStatisticsTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
private java.io.File |
constructDbPath(java.lang.String relDbDirName)
Constructs the path to the database base directory.
|
private void |
copyDb(java.lang.String newDbName)
Creates a copy of the master db.
|
private void |
createAndInsertSimple(java.sql.Connection con,
java.lang.String table,
int rows)
Default method to create and populate a simple test table.
|
private void |
createAndInsertSimple(java.lang.String table,
int rows)
Default method to create and populate a simple test table.
|
private void |
createMasterDb()
Creates the default/master db with a larger number of rows.
|
private static void |
dropIfExists(java.sql.Connection con,
java.lang.String entity)
Drops the specified entity if it exists.
|
private void |
forceRowCountEstimateUpdate(java.lang.String table)
Forces Derby to update the row count estimate by doing a full table
scan and then invoking a checkpoint.
|
private IndexStatsUtil.IdxStats[] |
getFilteredTableStats(java.lang.String table,
int expectedCount,
IndexStatsUtil.IdxStats[] oldStats)
Obtains the statistics for all indexes associated with the given table in
the default database.
|
private void |
insertSimple(java.sql.Connection con,
java.lang.String table,
int rows,
int start)
Inserts the specified number of rows into the table, using an increasing
integer as the value.
|
private void |
insertSimple(java.lang.String table,
int rows,
int start)
Inserts the specified number of rows into the table, using an increasing
integer as the value.
|
void |
setUp()
Initialize the default statistics helper object.
|
static junit.framework.Test |
suite() |
void |
tearDown()
Release the default statistics helper object.
|
void |
testCompressWhileScanning()
Tests that compressing the table while scanned makes the daemon fail
gracefully, and that the daemon can do other work afterwards.
|
void |
testDropWhileScanningThenDelete()
Drops table while the daemon is scanning it, then triggers update of
statistics of a different table, and finally shuts down and deletes the
database.
|
void |
testNoUpdateTriggeredBySingleColumnUniqueIndex()
Verifies that queries on a table with single-column unique indexes only
don't trigger a statistics update with the istat daemon.
|
void |
testSelectFromSimpleView() |
void |
testShutdownWhileScanningThenDelete()
Shuts down database while the daemon is scanning a table, and then
makes sure the database directory can be deleted.
|
void |
testStatisticsCorrectness()
Tests that the statistics computed are correct.
|
void |
testStatsCreatedOnGrowthThenDeleteDb()
Make sure stats are created when the table grows, and that the database
can be deleted after automated stats create/update -
that is verify that there are no open file handles left behind in the
daemon.
|
void |
testStatsUpdatedOnGrowth()
Make sure stats are updated when the table grows.
|
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
protected static final java.lang.String MASTERDB
private static final java.lang.String BIG_TABLE
private static final long DEFAULT_TIMEOUT
private static final java.lang.String[] TYPES
private static boolean dbCreated
private static IndexStatsUtil stats
public AutomaticIndexStatisticsTest(java.lang.String name)
public static junit.framework.Test suite()
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 testStatsCreatedOnGrowthThenDeleteDb() throws java.sql.SQLException
java.sql.SQLException
public void testStatsUpdatedOnGrowth() throws java.sql.SQLException
java.sql.SQLException
public void testShutdownWhileScanningThenDelete() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testDropWhileScanningThenDelete() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testCompressWhileScanning() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void testStatisticsCorrectness() throws java.sql.SQLException
java.sql.SQLException
- if something goes wrongpublic void testSelectFromSimpleView() throws java.sql.SQLException
java.sql.SQLException
public void testNoUpdateTriggeredBySingleColumnUniqueIndex() throws java.sql.SQLException
java.sql.SQLException
private void copyDb(java.lang.String newDbName) throws java.io.IOException, java.sql.SQLException
newDbName
- name of the copyjava.io.IOException
- if something goes wrongjava.sql.SQLException
- if something goes wrongprivate void createMasterDb() throws java.sql.SQLException
java.sql.SQLException
- if creating the database failsprivate void forceRowCountEstimateUpdate(java.lang.String table) throws java.sql.SQLException
table
- target tablejava.sql.SQLException
- if something goes wrongprivate java.io.File constructDbPath(java.lang.String relDbDirName)
relDbDirName
- the database name (relative)private void createAndInsertSimple(java.lang.String table, int rows) throws java.sql.SQLException
The table consists of a two integer columns, where the first is the primary key of the table and the second is a value with a non-unique index on it.
table
- target tablerows
- number of rows to insertjava.sql.SQLException
- if creating/populating the table failsprivate void createAndInsertSimple(java.sql.Connection con, java.lang.String table, int rows) throws java.sql.SQLException
The table consists of a two integer columns, where the first is the primary key of the table and the second is a value with a non-unique index on it.
con
- the connection to use (may be null
, in which case
the default connection will be used)table
- target tablerows
- number of rows to insertjava.sql.SQLException
- if creating/populating the table failsprivate void insertSimple(java.lang.String table, int rows, int start) throws java.sql.SQLException
table
- target tablerows
- number of rowsstart
- starting value for the first inserted rowjava.sql.SQLException
- if something goes wrongprivate void insertSimple(java.sql.Connection con, java.lang.String table, int rows, int start) throws java.sql.SQLException
con
- the connection to usetable
- target tablerows
- number of rowsstart
- starting value for the first inserted rowjava.sql.SQLException
- if something goes wrongjava.lang.NullPointerException
- if con
is null
private IndexStatsUtil.IdxStats[] getFilteredTableStats(java.lang.String table, int expectedCount, IndexStatsUtil.IdxStats[] oldStats) throws java.sql.SQLException
table
- base tableexpectedCount
- number of statistics objects to obtainoldStats
- statistics objects to ignorejava.sql.SQLException
- if something goes wrongjava.lang.AssertionError
- if the number of statistics objects expected
can't be obtained within the time limit
(DEFAULT_TIMEOUT)private static void dropIfExists(java.sql.Connection con, java.lang.String entity) throws java.sql.SQLException
con
- connection to the databaseentity
- the entity to drop (i.e. table or view)java.sql.SQLException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.