@Test(expected = RuntimeException.class) public void testWithoutPerconaAndFail() { System.setProperty(Configuration.FAIL_IF_NO_PT, "true"); PTOnlineSchemaChangeStatement.available = false; c.generateStatements(database); }
@Test public void testWithoutPercona() { PTOnlineSchemaChangeStatement.available = false; SqlStatement[] statements = c.generateStatements(database); Assert.assertEquals(1, statements.length); Assert.assertEquals(DropColumnStatement.class, statements[0].getClass()); }
@Test public void testReal() { SqlStatement[] statements = c.generateStatements(database); Assert.assertEquals(1, statements.length); Assert.assertEquals(PTOnlineSchemaChangeStatement.class, statements[0].getClass()); Assert.assertEquals( "pt-online-schema-change --alter=\"DROP COLUMN col_test\" " + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person", ((PTOnlineSchemaChangeStatement) statements[0]).printCommand(database)); }
@Test public void testUpdateSQLNoAlterSqlDryMode() { ExecutorService.getInstance() .setExecutor(database, new LoggingExecutor(null, new StringWriter(), database)); System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "true"); SqlStatement[] statements = c.generateStatements(database); Assert.assertEquals(1, statements.length); Assert.assertEquals(CommentStatement.class, statements[0].getClass()); Assert.assertEquals( "pt-online-schema-change --alter=\"DROP COLUMN col_test\" " + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person", ((CommentStatement) statements[0]).getText()); }
@Test public void testUpdateSQL() { ExecutorService.getInstance() .setExecutor(database, new LoggingExecutor(null, new StringWriter(), database)); SqlStatement[] statements = c.generateStatements(database); Assert.assertEquals(3, statements.length); Assert.assertEquals(CommentStatement.class, statements[0].getClass()); Assert.assertEquals( "pt-online-schema-change --alter=\"DROP COLUMN col_test\" " + "--host=localhost --port=3306 --user=user --password=*** --execute D=testdb,t=person", ((CommentStatement) statements[0]).getText()); Assert.assertEquals(CommentStatement.class, statements[1].getClass()); Assert.assertEquals(DropColumnStatement.class, statements[2].getClass()); }