use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class RandomResultSetGenerator method generate.
public ResultSet generate() {
ResultSet.Builder builder = ResultSet.newBuilder();
for (int row = 0; row < rowCount; row++) {
ListValue.Builder rowBuilder = ListValue.newBuilder();
for (Type type : TYPES) {
Value.Builder valueBuilder = Value.newBuilder();
setRandomValue(valueBuilder, type);
rowBuilder.addValues(valueBuilder.build());
}
builder.addRows(rowBuilder.build());
}
builder.setMetadata(METADATA);
return builder.build();
}
use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class RandomResultSetGenerator method generate.
public ResultSet generate() {
ResultSet.Builder builder = ResultSet.newBuilder();
for (int row = 0; row < rowCount; row++) {
ListValue.Builder rowBuilder = ListValue.newBuilder();
for (Type type : TYPES) {
Value.Builder valueBuilder = Value.newBuilder();
setRandomValue(valueBuilder, type);
rowBuilder.addValues(valueBuilder.build());
}
builder.addRows(rowBuilder.build());
}
builder.setMetadata(METADATA);
return builder.build();
}
use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class SpannerClientTest method partitionQueryExceptionTest.
@Test
public void partitionQueryExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setPartitionOptions(PartitionOptions.newBuilder().build()).build();
client.partitionQuery(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class SpannerClientTest method executeSqlExceptionTest.
@Test
public void executeSqlExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setResumeToken(ByteString.EMPTY).setPartitionToken(ByteString.EMPTY).setSeqno(109325920).setQueryOptions(ExecuteSqlRequest.QueryOptions.newBuilder().build()).setRequestOptions(RequestOptions.newBuilder().build()).build();
client.executeSql(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.api.expr.v1alpha1.Type in project java-spanner by googleapis.
the class SpannerClientTest method executeSqlTest.
@Test
public void executeSqlTest() throws Exception {
ResultSet expectedResponse = ResultSet.newBuilder().setMetadata(ResultSetMetadata.newBuilder().build()).addAllRows(new ArrayList<ListValue>()).setStats(ResultSetStats.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).setTransaction(TransactionSelector.newBuilder().build()).setSql("sql114126").setParams(Struct.newBuilder().build()).putAllParamTypes(new HashMap<String, Type>()).setResumeToken(ByteString.EMPTY).setPartitionToken(ByteString.EMPTY).setSeqno(109325920).setQueryOptions(ExecuteSqlRequest.QueryOptions.newBuilder().build()).setRequestOptions(RequestOptions.newBuilder().build()).build();
ResultSet actualResponse = client.executeSql(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExecuteSqlRequest actualRequest = ((ExecuteSqlRequest) actualRequests.get(0));
Assert.assertEquals(request.getSession(), actualRequest.getSession());
Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
Assert.assertEquals(request.getSql(), actualRequest.getSql());
Assert.assertEquals(request.getParams(), actualRequest.getParams());
Assert.assertEquals(request.getParamTypesMap(), actualRequest.getParamTypesMap());
Assert.assertEquals(request.getResumeToken(), actualRequest.getResumeToken());
Assert.assertEquals(request.getQueryMode(), actualRequest.getQueryMode());
Assert.assertEquals(request.getPartitionToken(), actualRequest.getPartitionToken());
Assert.assertEquals(request.getSeqno(), actualRequest.getSeqno());
Assert.assertEquals(request.getQueryOptions(), actualRequest.getQueryOptions());
Assert.assertEquals(request.getRequestOptions(), actualRequest.getRequestOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations