Search in sources :

Example 1 with InstanceNotFoundException

use of com.google.cloud.spanner.InstanceNotFoundException in project java-spanner by googleapis.

the class ITDatabaseTest method instanceNotFound.

@Test
public void instanceNotFound() {
    InstanceId testId = env.getTestHelper().getInstanceId();
    InstanceId nonExistingInstanceId = InstanceId.of(testId.getProject(), testId.getInstance() + "-na");
    DatabaseClient client = env.getTestHelper().getClient().getDatabaseClient(DatabaseId.of(nonExistingInstanceId, "some-db"));
    try (ResultSet rs = client.singleUse().executeQuery(Statement.of("SELECT 1"))) {
        rs.next();
        fail("missing expected exception");
    } catch (InstanceNotFoundException e) {
        assertThat(e.getResourceName()).isEqualTo(nonExistingInstanceId.getName());
    }
}
Also used : DatabaseClient(com.google.cloud.spanner.DatabaseClient) InstanceId(com.google.cloud.spanner.InstanceId) InstanceNotFoundException(com.google.cloud.spanner.InstanceNotFoundException) ResultSet(com.google.cloud.spanner.ResultSet) ParallelIntegrationTest(com.google.cloud.spanner.ParallelIntegrationTest) Test(org.junit.Test)

Aggregations

DatabaseClient (com.google.cloud.spanner.DatabaseClient)1 InstanceId (com.google.cloud.spanner.InstanceId)1 InstanceNotFoundException (com.google.cloud.spanner.InstanceNotFoundException)1 ParallelIntegrationTest (com.google.cloud.spanner.ParallelIntegrationTest)1 ResultSet (com.google.cloud.spanner.ResultSet)1 Test (org.junit.Test)1