コード例 #1
0
  @Test
  public void testGeneralteAlterStatementMultipleColumns() {
    ColumnConfig col1 = new ColumnConfig();
    col1.setName("col1_test");
    c.addColumn(col1);
    ColumnConfig col2 = new ColumnConfig();
    col2.setName("col2_test");
    c.addColumn(col2);

    Assert.assertEquals("DROP COLUMN col1_test, DROP COLUMN col2_test", c.generateAlterStatement());
  }
コード例 #2
0
  @Test(expected = RuntimeException.class)
  public void testWithoutPerconaAndFail() {
    System.setProperty(Configuration.FAIL_IF_NO_PT, "true");
    PTOnlineSchemaChangeStatement.available = false;

    c.generateStatements(database);
  }
コード例 #3
0
 @Test
 public void testWithoutPercona() {
   PTOnlineSchemaChangeStatement.available = false;
   SqlStatement[] statements = c.generateStatements(database);
   Assert.assertEquals(1, statements.length);
   Assert.assertEquals(DropColumnStatement.class, statements[0].getClass());
 }
コード例 #4
0
 @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));
 }
コード例 #5
0
  @Before
  public void setup() {
    c = new PerconaDropColumnChange();
    c.setColumnName("col_test");
    c.setTableName("person");
    c.getColumns().clear();

    DatabaseConnectionUtil.passwordForTests = "root";

    database = new MySQLDatabase();
    database.setLiquibaseSchemaName("testdb");
    DatabaseConnection conn =
        new MockDatabaseConnection("jdbc:mysql://user@localhost:3306/testdb", "user@localhost");
    database.setConnection(conn);
    ExecutorService.getInstance().setExecutor(database, new JdbcExecutor());

    PTOnlineSchemaChangeStatement.available = true;
    System.setProperty(Configuration.FAIL_IF_NO_PT, "false");
    System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "false");
  }
コード例 #6
0
  @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());
  }
コード例 #7
0
  @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());
  }
コード例 #8
0
 @Test
 public void testGenerateAlterStatement() {
   Assert.assertEquals("DROP COLUMN col_test", c.generateAlterStatement());
 }