/** * Closes this output stream and releases any system resources * associated with this stream. The general contract of * <code>close</code> * is that it closes the output stream. A closed stream cannot * perform * output operations and cannot be reopened. */ public void close() { flush(); hasBeenClosed = true; }
public MySQLEmbeddedDB(final String databaseName, final String username, final String password) { super(databaseName, username, password, null); setPort(); this.jdbcConnectionString = "jdbc:mysql://localhost:" + port + "/" + databaseName + "?createDatabaseIfNotExist=true&allowMultiQueries=true"; }
@Override public void start() throws IOException { started.set(true); refreshTableNames(); }
@BeforeClass(groups = "mysql") public void setUp() throws Exception { embeddedDB = new MySQLEmbeddedDB(); embeddedDB.initialize(); embeddedDB.start(); }
@Override public void start() throws IOException { if (started.get()) { throw new IOException("MySQL is already running: " + jdbcConnectionString); } startMysql(); refreshTableNames(); }
private void stopMysql() throws IOException { if (mysqldResource != null) { try { mysqldResource.shutdown(); } catch (NullPointerException npe) { logger.warn("Failed to shutdown mysql properly ", npe); } try { deleteRecursive(dataDir); deleteRecursive(dbDir); } catch (FileNotFoundException e) { throw new IOException(e); } started.set(false); logger.info("MySQL stopped: " + getCmdLineConnectionString()); } }
public static synchronized EmbeddedDB get() { if (instance == null) { if ("true".equals(System.getProperty("com.ning.billing.dbi.test.h2"))) { log.info("Using h2 as the embedded database"); instance = new H2EmbeddedDB(); } else { if (isUsingLocalInstance()) { log.info("Using MySQL local database"); final String databaseName = System.getProperty("com.ning.billing.dbi.test.localDb.database", "killbill"); final String username = System.getProperty("com.ning.billing.dbi.test.localDb.password", "root"); final String password = System.getProperty("com.ning.billing.dbi.test.localDb.username", "root"); instance = new MySQLStandaloneDB(databaseName, username, password); } else { log.info("Using MySQL as the embedded database"); instance = new MySQLEmbeddedDB(); } } } return instance; }
@AfterClass(groups = "slow") public void afterClass() throws Exception { embeddedDB.stop(); }
@Override public void stop() throws IOException { if (!started.get()) { throw new IOException("MySQL is not running"); } stopMysql(); }
private static boolean deleteRecursive(final File path) throws FileNotFoundException { if (!path.exists()) { throw new FileNotFoundException(path.getAbsolutePath()); } boolean ret = true; if (path.isDirectory()) { final File[] files = path.listFiles(); if (files != null) { for (final File f : files) { ret = ret && deleteRecursive(f); } } } return ret && path.delete(); }
@Override public void refreshTableNames() throws IOException { final String query = String.format("select table_name from information_schema.tables where table_schema = '%s' and table_type = 'BASE TABLE';", databaseName); try { executeQuery(query, new ResultSetJob() { @Override public void work(final ResultSet resultSet) throws SQLException { allTables.clear(); while (resultSet.next()) { allTables.add(resultSet.getString(1)); } } }); } catch (SQLException e) { throw new IOException(e); } }
@BeforeMethod(groups = "slow") public void beforeMethod() throws Exception { embeddedDB.cleanupAllTables(); clock.resetDeltaFromReality(); metricRegistry.removeMatching(MetricFilter.ALL); }
@Override public void start() throws IOException { if (started.get()) { throw new IOException("MySQL is already running: " + jdbcConnectionString); } startMysql(); refreshTableNames(); }
/** * Closes this output stream and releases any system resources * associated with this stream. The general contract of * <code>close</code> * is that it closes the output stream. A closed stream cannot * perform * output operations and cannot be reopened. */ public void close() { flush(); hasBeenClosed = true; }
public MySQLEmbeddedDB(final String databaseName, final String username, final String password) { super(databaseName, username, password, null); setPort(); this.jdbcConnectionString = "jdbc:mysql://localhost:" + port + "/" + databaseName + "?createDatabaseIfNotExist=true&allowMultiQueries=true"; }
@Override public void start() throws IOException { started.set(true); refreshTableNames(); }
@AfterClass(groups = "mysql") public void tearDown() throws Exception { embeddedDB.stop(); }
@Override public void stop() throws IOException { if (!started.get()) { throw new IOException("MySQL is not running"); } stopMysql(); }
private static boolean deleteRecursive(final File path) throws FileNotFoundException { if (!path.exists()) { throw new FileNotFoundException(path.getAbsolutePath()); } boolean ret = true; if (path.isDirectory()) { final File[] files = path.listFiles(); if (files != null) { for (final File f : files) { ret = ret && deleteRecursive(f); } } } return ret && path.delete(); }
@Override public void refreshTableNames() throws IOException { final String query = String.format("select table_name from information_schema.tables where table_schema = '%s' and table_type = 'BASE TABLE';", databaseName); try { executeQuery(query, new ResultSetJob() { @Override public void work(final ResultSet resultSet) throws SQLException { allTables.clear(); while (resultSet.next()) { allTables.add(resultSet.getString(1)); } } }); } catch (SQLException e) { throw new IOException(e); } }