Search in sources :

Example 1 with ResultSet

use of com.google.api.ads.admanager.axis.v202205.ResultSet in project java-spanner by googleapis.

the class SpannerClientTest method readTest.

@Test
public void readTest() throws Exception {
    ResultSet expectedResponse = ResultSet.newBuilder().setMetadata(ResultSetMetadata.newBuilder().build()).addAllRows(new ArrayList<ListValue>()).setStats(ResultSetStats.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    ReadRequest request = ReadRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setTable("table110115790").setIndex("index100346066").addAllColumns(new ArrayList<String>()).setKeySet(KeySet.newBuilder().build()).setLimit(102976443).setResumeToken(ByteString.EMPTY).setPartitionToken(ByteString.EMPTY).setRequestOptions(RequestOptions.newBuilder().build()).build();
    ResultSet actualResponse = client.read(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ReadRequest actualRequest = ((ReadRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSession(), actualRequest.getSession());
    Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
    Assert.assertEquals(request.getTable(), actualRequest.getTable());
    Assert.assertEquals(request.getIndex(), actualRequest.getIndex());
    Assert.assertEquals(request.getColumnsList(), actualRequest.getColumnsList());
    Assert.assertEquals(request.getKeySet(), actualRequest.getKeySet());
    Assert.assertEquals(request.getLimit(), actualRequest.getLimit());
    Assert.assertEquals(request.getResumeToken(), actualRequest.getResumeToken());
    Assert.assertEquals(request.getPartitionToken(), actualRequest.getPartitionToken());
    Assert.assertEquals(request.getRequestOptions(), actualRequest.getRequestOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListValue(com.google.protobuf.ListValue) PartialResultSet(com.google.spanner.v1.PartialResultSet) ResultSet(com.google.spanner.v1.ResultSet) ByteString(com.google.protobuf.ByteString) ReadRequest(com.google.spanner.v1.ReadRequest) PartitionReadRequest(com.google.spanner.v1.PartitionReadRequest) Test(org.junit.Test)

Example 2 with ResultSet

use of com.google.api.ads.admanager.axis.v202205.ResultSet in project java-spanner by googleapis.

the class SpannerClientTest method executeBatchDmlTest.

@Test
public void executeBatchDmlTest() throws Exception {
    ExecuteBatchDmlResponse expectedResponse = ExecuteBatchDmlResponse.newBuilder().addAllResultSets(new ArrayList<ResultSet>()).setStatus(Status.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    ExecuteBatchDmlRequest request = ExecuteBatchDmlRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).addAllStatements(new ArrayList<ExecuteBatchDmlRequest.Statement>()).setSeqno(109325920).setRequestOptions(RequestOptions.newBuilder().build()).build();
    ExecuteBatchDmlResponse actualResponse = client.executeBatchDml(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ExecuteBatchDmlRequest actualRequest = ((ExecuteBatchDmlRequest) actualRequests.get(0));
    Assert.assertEquals(request.getSession(), actualRequest.getSession());
    Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
    Assert.assertEquals(request.getStatementsList(), actualRequest.getStatementsList());
    Assert.assertEquals(request.getSeqno(), actualRequest.getSeqno());
    Assert.assertEquals(request.getRequestOptions(), actualRequest.getRequestOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) PartialResultSet(com.google.spanner.v1.PartialResultSet) ResultSet(com.google.spanner.v1.ResultSet) ArrayList(java.util.ArrayList) ExecuteBatchDmlResponse(com.google.spanner.v1.ExecuteBatchDmlResponse) ExecuteBatchDmlRequest(com.google.spanner.v1.ExecuteBatchDmlRequest) Test(org.junit.Test)

Example 3 with ResultSet

use of com.google.api.ads.admanager.axis.v202205.ResultSet in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerProbes method readProber.

/**
 * Probe to test Read and StreamingRead grpc call from Spanner stub.
 */
public static void readProber(SpannerGrpc.SpannerBlockingStub stub) throws ProberException {
    Session session = null;
    try {
        session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
        KeySet keySet = KeySet.newBuilder().setAll(true).build();
        // Probing read call.
        ResultSet response = stub.read(ReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setKeySet(keySet).addColumns("username").addColumns("firstname").addColumns("lastname").build());
        if (response == null) {
            throw new ProberException("Response is null when executing SQL. ");
        } else if (response.getRowsCount() != 1) {
            throw new ProberException(String.format("The number of Responses '%d' is not correct.", response.getRowsCount()));
        } else if (!response.getRows(0).getValuesList().get(0).getStringValue().equals(TEST_USERNAME)) {
            throw new ProberException("Response value is not correct when executing Reader.");
        }
        // Probing streamingRead call.
        Iterator<PartialResultSet> responsePartial = stub.streamingRead(ReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setKeySet(keySet).addColumns("username").addColumns("firstname").addColumns("lastname").build());
        if (responsePartial == null) {
            throw new ProberException("Response is null when executing streaming SQL. ");
        } else if (!responsePartial.next().getValues(0).getStringValue().equals(TEST_USERNAME)) {
            throw new ProberException("Response value is not correct when executing streaming Reader. ");
        }
    } finally {
        deleteSession(stub, session);
    }
}
Also used : KeySet(com.google.spanner.v1.KeySet) ResultSet(com.google.spanner.v1.ResultSet) PartialResultSet(com.google.spanner.v1.PartialResultSet) PartialResultSet(com.google.spanner.v1.PartialResultSet) Session(com.google.spanner.v1.Session)

Example 4 with ResultSet

use of com.google.api.ads.admanager.axis.v202205.ResultSet in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerProbes method executeSqlProber.

/**
 * Probes to test ExecuteSql and ExecuteStreamingSql call from Spanner stub.
 */
public static void executeSqlProber(SpannerGrpc.SpannerBlockingStub stub) throws ProberException {
    Session session = null;
    try {
        session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
        // Probing executeSql call.
        ResultSet response = stub.executeSql(ExecuteSqlRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + TABLE).build());
        if (response == null) {
            throw new ProberException("Response is null when executing SQL. ");
        } else if (response.getRowsCount() != 1) {
            throw new ProberException(String.format("The number of Responses '%d' is not correct.", response.getRowsCount()));
        } else if (!response.getRows(0).getValuesList().get(0).getStringValue().equals(TEST_USERNAME)) {
            throw new ProberException("Response value is not correct when executing SQL.");
        }
        // Probing streaming executeSql call.
        Iterator<PartialResultSet> responsePartial = stub.executeStreamingSql(ExecuteSqlRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + TABLE).build());
        if (responsePartial == null) {
            throw new ProberException("Response is null when executing streaming SQL. ");
        } else if (!responsePartial.next().getValues(0).getStringValue().equals(TEST_USERNAME)) {
            throw new ProberException("Response value is not correct when executing streaming SQL. ");
        }
    } finally {
        deleteSession(stub, session);
    }
}
Also used : ResultSet(com.google.spanner.v1.ResultSet) PartialResultSet(com.google.spanner.v1.PartialResultSet) PartialResultSet(com.google.spanner.v1.PartialResultSet) Session(com.google.spanner.v1.Session)

Example 5 with ResultSet

use of com.google.api.ads.admanager.axis.v202205.ResultSet in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerClientV1TestCases method testExecuteSql.

void testExecuteSql() throws InterruptedException {
    System.out.println("\nTestExecuteSql");
    SpannerClient client = getClient();
    Session session = client.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
    ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + TABLE).build();
    RpcCall<ExecuteSqlRequest, ResultSet> rpcCall = (ExecuteSqlRequest req) -> client.executeSql(req);
    doTestBlocking(request, rpcCall);
    cleanUpClient(client, session.getName());
}
Also used : ExecuteSqlRequest(com.google.spanner.v1.ExecuteSqlRequest) PartialResultSet(com.google.spanner.v1.PartialResultSet) ResultSet(com.google.spanner.v1.ResultSet) SpannerClient(com.google.cloud.spanner.v1.SpannerClient) Session(com.google.spanner.v1.Session)

Aggregations

Test (org.junit.Test)37 ResultSet (com.google.spanner.v1.ResultSet)21 PartialResultSet (com.google.spanner.v1.PartialResultSet)14 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202205.ResultSet)12 Function (com.google.common.base.Function)10 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202205.PublisherQueryLanguageServiceInterface)8 Session (com.google.spanner.v1.Session)8 DateTime (org.joda.time.DateTime)8 ListValue (com.google.protobuf.ListValue)5 ResultSet (org.apache.cassandra.cql3.ResultSet)5