Class TestDB
- java.lang.Object
-
- jetbrains.buildServer.serverSide.db.TestDB
-
public class TestDB extends Object
Contains a static DBFacade for testing. This facade initializes on startup and never closes during tests.
-
-
Field Summary
Fields Modifier and Type Field Description static StringourJdbcDriversPath
-
Constructor Summary
Constructors Constructor Description TestDB()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcleanAllTables()static voidcleanMutableTables()static voidcreateSchemaFromScratch()Creates DB schema with data.static voidcreateSchemaIfNotCreated()Creates DB schema with data on first call, do nothing on next calls.static voidcreateTable(DBFunctions dbf, TableDef table, boolean recreateIfExists)static voidcreateTable(TableDef table, boolean recreateIfExists)static StringdebugQuery(String queryText)static voiddropAllPermanentTables()Drops all permanent tables in the current schema.static voiddropAllTables()Shuts the DB facade down, drops all true schema tables and then re-init the DB facade.static voiddropAllTemporaryTables()For Oracle and HSQL - drops all temporary tables.static voiddumpThreadsSafely()static voidensureIntTable(int N, boolean withKey)Creates a table named "intN" or "intNk" (where N is the given number) with one field name "x", and fill it with rows from 1 to N.static voidensureNoOrphanConnections()static voidensureNoTables(String... tableNames)Drops tables if exist.static voidfatalError(String failureShortDescription, Throwable exception, boolean dumpThreads)static JdbcConnectionStringgetConnectionString()static DBFacadegetDBFacade()static DatabaseFixturegetDBFixture()static TeamCityDatabaseManagergetDbManager()static DatabaseTypegetDBType()static SQLDialectgetDialect()static GuidGeneratorgetGuidGenerator()static JdbcDriversgetJdbcDrivers()static FilegetJdbcDriversDir()static ConsoleLoggergetLogger()static intgetNonReturnedConnectionsCount()static Set<Connection>getOurUsedConnections()static ServerPathsgetServerPaths()static SQLRunnerExgetSqlRunner()static TestDBAccessgetTestDBAccess()static booleanisDatabaseCaseSensitive()static booleanisTestingWithInternalDB()static booleankeepExistingData()keep.db property allows reusing existing DB data in performance tests.static List<Integer>makeListOfN(int min, int max)static voidreinitData()static voidreinitMutableData()static voidresetUsedConnectionsList()static Set<String>retrieveTableNames(boolean includePermanent, boolean includeTemporary, boolean lowerCase)static voidshutdownDbFacade()static voidstartupDbFacade()static voidwithDataSource(DataSourceAction action)static <T> TwithDB(DBAction<T> action, boolean commitOnSuccess)static voidwithDB(DBActionNoResults action)static voidwithDB(DBActionNoResults action, boolean commitOnSuccess)static voidwithDB2(DBAction2 actions, boolean commitOnSuccess)
-
-
-
Field Detail
-
ourJdbcDriversPath
public static final String ourJdbcDriversPath
- See Also:
- Constant Field Values
-
-
Method Detail
-
startupDbFacade
public static void startupDbFacade()
-
shutdownDbFacade
public static void shutdownDbFacade()
-
getTestDBAccess
@NotNull public static TestDBAccess getTestDBAccess()
-
getNonReturnedConnectionsCount
public static int getNonReturnedConnectionsCount()
-
createSchemaFromScratch
public static void createSchemaFromScratch()
Creates DB schema with data. Drops all tables before creating (if any exist).
-
createTable
public static void createTable(@NotNull TableDef table, boolean recreateIfExists)
-
createTable
public static void createTable(DBFunctions dbf, TableDef table, boolean recreateIfExists)
-
createSchemaIfNotCreated
public static void createSchemaIfNotCreated()
Creates DB schema with data on first call, do nothing on next calls.Use this procedure carefully - it doesn't guarantee anything.
-
reinitData
public static void reinitData()
-
reinitMutableData
public static void reinitMutableData()
-
dropAllTables
public static void dropAllTables()
Shuts the DB facade down, drops all true schema tables and then re-init the DB facade. They are all permanent tables for any type of database, and also all temporary tables for Oracle and HSQL.All borrowed connections must be released before this method call!
- See Also:
dropAllPermanentTables(),dropAllTemporaryTables()
-
keepExistingData
public static boolean keepExistingData()
keep.db property allows reusing existing DB data in performance tests. Make sure - all your build configurations/projects in your tests are persisted - test seed data is not re-initialized with keep.db property is set - teamcity data directory is not a temporary one, but a fixed non-cleaned up directory
-
dropAllPermanentTables
public static void dropAllPermanentTables()
Drops all permanent tables in the current schema.
-
dropAllTemporaryTables
public static void dropAllTemporaryTables()
For Oracle and HSQL - drops all temporary tables. For other database types - does nothing. Note 1: in order to drop temporary tables in another DB type just close the connection(s). Note 2: in order to be able to drop temporary tables on Oracle, there are must be no borrowed connections.
-
ensureNoTables
public static void ensureNoTables(String... tableNames)
Drops tables if exist.- Parameters:
tableNames- table names to drop.
-
cleanAllTables
public static void cleanAllTables()
-
cleanMutableTables
public static void cleanMutableTables()
-
retrieveTableNames
public static Set<String> retrieveTableNames(boolean includePermanent, boolean includeTemporary, boolean lowerCase)
-
resetUsedConnectionsList
public static void resetUsedConnectionsList()
-
getOurUsedConnections
public static Set<Connection> getOurUsedConnections()
-
withDB
public static void withDB(@NotNull DBActionNoResults action)
-
withDB
public static void withDB(@NotNull DBActionNoResults action, boolean commitOnSuccess)
-
withDB
public static <T> T withDB(@NotNull DBAction<T> action, boolean commitOnSuccess)
-
withDB2
public static void withDB2(@NotNull DBAction2 actions, boolean commitOnSuccess)
-
withDataSource
public static void withDataSource(@NotNull DataSourceAction action)
-
getDialect
@NotNull public static SQLDialect getDialect()
-
getSqlRunner
@NotNull public static SQLRunnerEx getSqlRunner()
-
getDBFacade
@NotNull public static DBFacade getDBFacade()
-
getDBFixture
@NotNull public static DatabaseFixture getDBFixture()
-
getDBType
@NotNull public static DatabaseType getDBType()
-
getServerPaths
public static ServerPaths getServerPaths()
-
getDbManager
@NotNull public static TeamCityDatabaseManager getDbManager()
-
isDatabaseCaseSensitive
public static boolean isDatabaseCaseSensitive()
-
dumpThreadsSafely
public static void dumpThreadsSafely()
-
fatalError
public static void fatalError(@NotNull String failureShortDescription, @Nullable Throwable exception, boolean dumpThreads)
-
getConnectionString
public static JdbcConnectionString getConnectionString()
-
getJdbcDriversDir
public static File getJdbcDriversDir()
-
isTestingWithInternalDB
public static boolean isTestingWithInternalDB()
-
getJdbcDrivers
public static JdbcDrivers getJdbcDrivers()
-
ensureNoOrphanConnections
public static void ensureNoOrphanConnections()
-
ensureIntTable
public static void ensureIntTable(int N, boolean withKey)Creates a table named "intN" or "intNk" (where N is the given number) with one field name "x", and fill it with rows from 1 to N.- Parameters:
N-
-
getGuidGenerator
public static GuidGenerator getGuidGenerator()
-
getLogger
public static ConsoleLogger getLogger()
-
-