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 String
ourJdbcDriversPath
-
Constructor Summary
Constructors Constructor Description TestDB()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cleanAllTables()
static void
cleanMutableTables()
static void
createSchemaFromScratch()
Creates DB schema with data.static void
createSchemaIfNotCreated()
Creates DB schema with data on first call, do nothing on next calls.static void
createTable(DBFunctions dbf, TableDef table, boolean recreateIfExists)
static void
createTable(TableDef table, boolean recreateIfExists)
static String
debugQuery(String queryText)
static void
dropAllPermanentTables()
Drops all permanent tables in the current schema.static void
dropAllTables()
Shuts the DB facade down, drops all true schema tables and then re-init the DB facade.static void
dropAllTemporaryTables()
For Oracle and HSQL - drops all temporary tables.static void
dumpThreadsSafely()
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.static void
ensureNoOrphanConnections()
static void
ensureNoTables(String... tableNames)
Drops tables if exist.static void
fatalError(String failureShortDescription, Throwable exception, boolean dumpThreads)
static JdbcConnectionString
getConnectionString()
static DBFacade
getDBFacade()
static DatabaseFixture
getDBFixture()
static TeamCityDatabaseManager
getDbManager()
static DatabaseType
getDBType()
static SQLDialect
getDialect()
static GuidGenerator
getGuidGenerator()
static JdbcDrivers
getJdbcDrivers()
static File
getJdbcDriversDir()
static ConsoleLogger
getLogger()
static int
getNonReturnedConnectionsCount()
static Set<Connection>
getOurUsedConnections()
static ServerPaths
getServerPaths()
static SQLRunnerEx
getSqlRunner()
static TestDBAccess
getTestDBAccess()
static boolean
isDatabaseCaseSensitive()
static boolean
isTestingWithInternalDB()
static boolean
keepExistingData()
keep.db property allows reusing existing DB data in performance tests.static List<Integer>
makeListOfN(int min, int max)
static void
reinitData()
static void
reinitMutableData()
static void
resetUsedConnectionsList()
static Set<String>
retrieveTableNames(boolean includePermanent, boolean includeTemporary, boolean lowerCase)
static void
shutdownDbFacade()
static void
startupDbFacade()
static void
withDataSource(DataSourceAction action)
static <T> T
withDB(DBAction<T> action, boolean commitOnSuccess)
static void
withDB(DBActionNoResults action)
static void
withDB(DBActionNoResults action, boolean commitOnSuccess)
static void
withDB2(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()
-
-