Search in sources :

Example 1 with InstanceConfigName

use of com.google.spanner.admin.instance.v1.InstanceConfigName in project java-spanner by googleapis.

the class InstanceAdminGaxTest method getInstanceConfigTest.

@Test
public void getInstanceConfigTest() {
    Exception exception = setupException();
    for (int i = 0; i < 2; i++) {
        InstanceConfigName name2 = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
        String displayName = "displayName1615086568";
        List<String> leaderOptions = Arrays.asList("leader option 1", "leader option 2");
        InstanceConfig expectedResponse = InstanceConfig.newBuilder().setName(name2.toString()).setDisplayName(displayName).addAllLeaderOptions(leaderOptions).build();
        if (exceptionAtCall == 0) {
            mockInstanceAdmin.addException(exception);
        }
        mockInstanceAdmin.addResponse(expectedResponse);
        if (exceptionAtCall == 1) {
            mockInstanceAdmin.addException(exception);
        }
        InstanceConfigName name = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
        com.google.cloud.spanner.InstanceConfig actualResponse = client.getInstanceConfig(name.toString());
        Assert.assertEquals(displayName, actualResponse.getDisplayName());
        Assert.assertEquals(leaderOptions, actualResponse.getLeaderOptions());
        List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
        Assert.assertEquals(i + 1, actualRequests.size());
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) InstanceConfig(com.google.spanner.admin.instance.v1.InstanceConfig) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) Test(org.junit.Test)

Example 2 with InstanceConfigName

use of com.google.spanner.admin.instance.v1.InstanceConfigName in project java-spanner by googleapis.

the class InstanceAdminClientTest method getInstanceConfigTest.

@Test
public void getInstanceConfigTest() throws Exception {
    InstanceConfig expectedResponse = InstanceConfig.newBuilder().setName(InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]").toString()).setDisplayName("displayName1714148973").addAllReplicas(new ArrayList<ReplicaInfo>()).addAllLeaderOptions(new ArrayList<String>()).build();
    mockInstanceAdmin.addResponse(expectedResponse);
    InstanceConfigName name = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]");
    InstanceConfig actualResponse = client.getInstanceConfig(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetInstanceConfigRequest actualRequest = ((GetInstanceConfigRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) InstanceConfig(com.google.spanner.admin.instance.v1.InstanceConfig) ReplicaInfo(com.google.spanner.admin.instance.v1.ReplicaInfo) GetInstanceConfigRequest(com.google.spanner.admin.instance.v1.GetInstanceConfigRequest) ArrayList(java.util.ArrayList) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) Test(org.junit.Test)

Example 3 with InstanceConfigName

use of com.google.spanner.admin.instance.v1.InstanceConfigName in project java-spanner by googleapis.

the class GapicSpannerRpc method getInstanceConfig.

@Override
public InstanceConfig getInstanceConfig(String instanceConfigName) throws SpannerException {
    GetInstanceConfigRequest request = GetInstanceConfigRequest.newBuilder().setName(instanceConfigName).build();
    GrpcCallContext context = newCallContext(null, projectName, request, InstanceAdminGrpc.getGetInstanceConfigMethod());
    return get(instanceAdminStub.getInstanceConfigCallable().futureCall(request, context));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) GetInstanceConfigRequest(com.google.spanner.admin.instance.v1.GetInstanceConfigRequest)

Example 4 with InstanceConfigName

use of com.google.spanner.admin.instance.v1.InstanceConfigName 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());
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) Test(org.junit.Test)

Example 5 with InstanceConfigName

use of com.google.spanner.admin.instance.v1.InstanceConfigName 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());
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) InstanceName(com.google.spanner.admin.instance.v1.InstanceName) UpdateInstanceMetadata(com.google.spanner.admin.instance.v1.UpdateInstanceMetadata) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

InstanceConfigName (com.google.spanner.admin.instance.v1.InstanceConfigName)7 Test (org.junit.Test)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 InstanceName (com.google.spanner.admin.instance.v1.InstanceName)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 ExpectedException (org.junit.rules.ExpectedException)4 GetInstanceConfigRequest (com.google.spanner.admin.instance.v1.GetInstanceConfigRequest)2 InstanceConfig (com.google.spanner.admin.instance.v1.InstanceConfig)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 CreateInstanceMetadata (com.google.spanner.admin.instance.v1.CreateInstanceMetadata)1 Instance (com.google.spanner.admin.instance.v1.Instance)1 ReplicaInfo (com.google.spanner.admin.instance.v1.ReplicaInfo)1 UpdateInstanceMetadata (com.google.spanner.admin.instance.v1.UpdateInstanceMetadata)1 ArrayList (java.util.ArrayList)1