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()));
}
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()));
}
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);
}
}
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);
}
}
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());
}
Aggregations