private void installDDLSilently(final String resourceName) throws IOException { final ClassLoader classLoader = MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(), DBTestingHelper.class.getClassLoader()); final Enumeration<URL> resources = classLoader.getResources(resourceName); while (resources.hasMoreElements()) { final URL inputStream = resources.nextElement(); final String ddl; try { ddl = IOUtils.toString(inputStream.openStream()); getInstance().executeScript(ddl); } catch (final Exception ignored) { // The test doesn't have this module ddl in the classpath - that's fine } } }
protected void cleanupAllTables() { try { DBTestingHelper.get().getInstance().cleanupAllTables(); } catch (final Exception e) { Assert.fail("Unable to clean database", e); } }
@BeforeMethod(groups = "slow") public void cleanupTablesBetweenMethods() { try { DBTestingHelper.get().getInstance().cleanupAllTables(); } catch (final Exception ignored) { } }
@AfterSuite(groups = "slow") public void shutdownMysqlAfterTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException { if (hasFailed()) { log.error("**********************************************************************************************"); log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****"); log.error(DBTestingHelper.get().getInstance().getCmdLineConnectionString()); log.error("**********************************************************************************************"); return; } try { DBTestingHelper.get().getInstance().stop(); } catch (final Exception ignored) { } } }
final EmbeddedDB embeddedDB = DBTestingHelper.get().getInstance(); final List<String> tables = embeddedDB.getAllTables();
@AfterSuite(groups = "slow") public void afterSuite() throws Exception { if (hasFailed()) { threadDump(); dumpDB(); log.error("**********************************************************************************************"); log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****"); log.error(DBTestingHelper.get().getInstance().getCmdLineConnectionString()); log.error("**********************************************************************************************"); return; } if (cacheManager != null) { cacheManager.close(); } if (redissonCachingClient != null) { redissonCachingClient.shutdown(); } try { DBTestingHelper.get().getInstance().stop(); } catch (final Exception ignored) { } }
protected synchronized void executePostStartupScripts() throws IOException { final EmbeddedDB instance = getInstance(); final String databaseSpecificDDL = "org/killbill/billing/util/" + "ddl-" + instance.getDBEngine().name().toLowerCase() + ".sql"; installDDLSilently(databaseSpecificDDL);
private void installDDLSilently(final String resourceName) throws IOException { final ClassLoader classLoader = MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(), DBTestingHelper.class.getClassLoader()); final Enumeration<URL> resources = classLoader.getResources(resourceName); while (resources.hasMoreElements()) { final URL inputStream = resources.nextElement(); final String ddl; try { ddl = IOUtils.toString(inputStream.openStream()); getInstance().executeScript(ddl); } catch (final Exception ignored) { // The test doesn't have this module ddl in the classpath - that's fine } } }
@BeforeMethod(groups = "slow") public void cleanupTablesBetweenMethods() { try { DBTestingHelper.get().getInstance().cleanupAllTables(); } catch (final Exception ignored) { } }
protected void cleanupAllTables() { try { DBTestingHelper.get().getInstance().cleanupAllTables(); } catch (final Exception e) { Assert.fail("Unable to clean database", e); } }
@AfterSuite(groups = "slow") public void shutdownMysqlAfterTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException { if (hasFailed()) { log.error("**********************************************************************************************"); log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****"); log.error(DBTestingHelper.get().getInstance().getCmdLineConnectionString()); log.error("**********************************************************************************************"); return; } try { DBTestingHelper.get().getInstance().stop(); } catch (final Exception ignored) { } } }
final EmbeddedDB embeddedDB = DBTestingHelper.get().getInstance(); final List<String> tables = embeddedDB.getAllTables();
@AfterSuite(groups = "slow") public void afterSuite() throws Exception { if (hasFailed()) { threadDump(); dumpDB(); log.error("**********************************************************************************************"); log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****"); log.error(DBTestingHelper.get().getInstance().getCmdLineConnectionString()); log.error("**********************************************************************************************"); return; } if (cacheManager != null) { cacheManager.close(); } if (redissonCachingClient != null) { redissonCachingClient.shutdown(); } try { DBTestingHelper.get().getInstance().stop(); } catch (final Exception ignored) { } }
protected synchronized void executePostStartupScripts() throws IOException { final EmbeddedDB instance = getInstance(); final String databaseSpecificDDL = "org/killbill/billing/util/" + "ddl-" + instance.getDBEngine().name().toLowerCase() + ".sql"; installDDLSilently(databaseSpecificDDL);