use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class InstanceAdminGaxTest method getInstanceTest.
@Test
public void getInstanceTest() {
Exception exception = setupException();
InstanceName name2 = InstanceName.of(PROJECT, "INSTANCE");
String displayName = "displayName1615086568";
InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name2.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(3).build();
if (exceptionAtCall == 0) {
mockInstanceAdmin.addException(exception);
}
mockInstanceAdmin.addResponse(expectedResponse);
if (exceptionAtCall == 1) {
mockInstanceAdmin.addException(exception);
}
mockInstanceAdmin.addResponse(expectedResponse);
InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
for (int i = 0; i < 2; i++) {
Instance actualResponse = client.getInstance(name.toString());
Assert.assertEquals(displayName, actualResponse.getDisplayName());
}
List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
Assert.assertEquals(2, actualRequests.size());
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class InstanceAdminGaxTest method updateInstanceTest.
@Test
public void updateInstanceTest() throws Exception {
boolean methodIsIdempotent = !spanner.getOptions().getInstanceAdminStubSettings().updateInstanceOperationSettings().getInitialCallSettings().getRetryableCodes().isEmpty();
if (!methodIsIdempotent && exceptionType == ExceptionType.DELAYED) {
// Skip this test as the method is non-idempotent and won't retry anyways.
return;
}
Exception exception = setupException();
InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
String displayName = "displayName1615086568";
int nodeCount = 1539922066;
com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(nodeCount).build();
com.google.longrunning.Operation resultOperation = com.google.longrunning.Operation.newBuilder().setName("updateInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
if (exceptionAtCall == 0) {
mockInstanceAdmin.addException(exception);
}
mockInstanceAdmin.addResponse(resultOperation);
if (exceptionAtCall == 1) {
mockInstanceAdmin.addException(exception);
}
mockInstanceAdmin.addResponse(resultOperation);
for (int i = 0; i < 2; i++) {
OperationFuture<Instance, UpdateInstanceMetadata> actualResponse = client.updateInstance(InstanceInfo.newBuilder(InstanceId.of(PROJECT, "INSTANCE")).setDisplayName(displayName).setNodeCount(nodeCount).build());
try {
Instance returnedInstance = actualResponse.get();
if (!methodIsIdempotent && i == exceptionAtCall) {
fail("missing expected exception");
}
Assert.assertEquals(displayName, returnedInstance.getDisplayName());
} catch (ExecutionException e) {
if (!exceptionType.isRetryable() || methodIsIdempotent || i != exceptionAtCall) {
Throwables.throwIfUnchecked(e.getCause());
throw e;
}
}
}
List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
if (methodIsIdempotent) {
Assert.assertEquals(2, actualRequests.size());
} else {
Assert.assertEquals(1, actualRequests.size());
}
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class InstanceAdminGaxTest method createInstanceTest.
@Test
public void createInstanceTest() throws Exception {
boolean methodIsIdempotent = !spanner.getOptions().getInstanceAdminStubSettings().createInstanceOperationSettings().getInitialCallSettings().getRetryableCodes().isEmpty();
if (!methodIsIdempotent && exceptionType == ExceptionType.DELAYED) {
// Skip this test as the method is non-idempotent and won't retry anyways.
return;
}
Exception exception = setupException();
InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
String displayName = "displayName1615086568";
int nodeCount = 1539922066;
com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(nodeCount).build();
com.google.longrunning.Operation resultOperation = com.google.longrunning.Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
if (exceptionAtCall == 0) {
mockInstanceAdmin.addException(exception);
}
mockInstanceAdmin.addResponse(resultOperation);
if (exceptionAtCall == 1) {
mockInstanceAdmin.addException(exception);
}
mockInstanceAdmin.addResponse(resultOperation);
for (int i = 0; i < 2; i++) {
OperationFuture<Instance, CreateInstanceMetadata> actualResponse = client.createInstance(InstanceInfo.newBuilder(InstanceId.of(PROJECT, "INSTANCE")).setDisplayName(displayName).setNodeCount(nodeCount).build());
try {
Instance returnedInstance = actualResponse.get();
if (!methodIsIdempotent && i == exceptionAtCall) {
fail("missing expected exception");
}
Assert.assertEquals(displayName, returnedInstance.getDisplayName());
} catch (ExecutionException e) {
if (!exceptionType.isRetryable() || methodIsIdempotent || i != exceptionAtCall) {
Throwables.throwIfUnchecked(e.getCause());
throw e;
}
}
}
List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
if (methodIsIdempotent) {
Assert.assertEquals(2, actualRequests.size());
} else {
Assert.assertEquals(1, actualRequests.size());
}
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class SpannerThreadsTest method mockGetInstanceResponse.
private void mockGetInstanceResponse() {
InstanceName name2 = InstanceName.of("[PROJECT]", "[INSTANCE]");
InstanceConfigName config = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]");
String displayName = "displayName1615086568";
int nodeCount = 1539922066;
Instance expectedResponse = Instance.newBuilder().setName(name2.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(nodeCount).build();
mockInstanceAdmin.addResponse(expectedResponse);
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class DatabaseAdminClientTest method listBackupOperationsExceptionTest.
@Test
public void listBackupOperationsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDatabaseAdmin.addException(exception);
try {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
client.listBackupOperations(parent);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations