use of com.google.cloud.spanner.DatabaseAdminClient in project spanner-jdbc by olavloite.
the class CustomStatementsTest method testShowDDLOperations.
@Test
public void testShowDDLOperations() throws SQLException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
final String ddl = "CREATE TABLE FOO (ID INT64 NOT NULL, NAME STRING(100) NOT NULL) PRIMARY KEY (ID)";
Field adminClientField = CloudSpannerConnection.class.getDeclaredField("adminClient");
adminClientField.setAccessible(true);
DatabaseAdminClient adminClient = mock(DatabaseAdminClient.class);
@SuppressWarnings("unchecked") Operation<Void, UpdateDatabaseDdlMetadata> operation = mock(Operation.class);
when(operation.reload()).then(new Returns(operation));
when(operation.getName()).then(new Returns("test"));
when(adminClient.updateDatabaseDdl(any(), any(), any(), any())).then(new Returns(operation));
adminClientField.set(connection, adminClient);
Statement statement = connection.createStatement();
assertFalse(statement.execute("SET_CONNECTION_PROPERTY AsyncDdlOperations=true"));
assertEquals(1, statement.getUpdateCount());
try (ResultSet rs = statement.executeQuery("SHOW_DDL_OPERATIONS")) {
assertFalse(rs.next());
}
statement.execute(ddl);
try (ResultSet rs = statement.executeQuery("SHOW_DDL_OPERATIONS")) {
assertTrue(rs.next());
assertEquals("test", rs.getString("NAME"));
assertNotNull(rs.getTimestamp("TIME_STARTED"));
assertEquals(ddl, rs.getString("STATEMENT"));
assertFalse(rs.getBoolean("DONE"));
assertNull(rs.getString("EXCEPTION"));
assertFalse(rs.next());
}
}
Aggregations