use of com.google.spanner.v1.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()));
}
use of com.google.spanner.v1.Type in project java-spanner by googleapis.
the class SpannerClientTest method executeStreamingSqlExceptionTest.
@Test
public void executeStreamingSqlExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
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();
MockStreamObserver<PartialResultSet> responseObserver = new MockStreamObserver<>();
ServerStreamingCallable<ExecuteSqlRequest, PartialResultSet> callable = client.executeStreamingSqlCallable();
callable.serverStreamingCall(request, responseObserver);
try {
List<PartialResultSet> actualResponses = responseObserver.future().get();
Assert.fail("No exception thrown");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
use of com.google.spanner.v1.Type in project java-spanner by googleapis.
the class SpannerClientTest method partitionQueryTest.
@Test
public void partitionQueryTest() throws Exception {
PartitionResponse expectedResponse = PartitionResponse.newBuilder().addAllPartitions(new ArrayList<Partition>()).setTransaction(Transaction.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
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();
PartitionResponse actualResponse = client.partitionQuery(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
PartitionQueryRequest actualRequest = ((PartitionQueryRequest) 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.getPartitionOptions(), actualRequest.getPartitionOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class ConformanceServerTest method expectEvalTrue.
/**
* expectEvalTrue parses, checks, and evaluates the CEL expression in source and checks that the
* result is the boolean value 'true'.
*/
void expectEvalTrue(String source) {
FullPipelineResult fp = fullPipeline(source);
long rootID = fp.parseResponse.getParsedExpr().getExpr().getId();
Type topType = fp.checkResponse.getCheckedExpr().getTypeMapMap().get(rootID);
assertThat(topType).extracting(Type::getTypeKindCase).isEqualTo(Type.TypeKindCase.PRIMITIVE);
assertThat(topType).extracting(Type::getPrimitive).isEqualTo(Type.PrimitiveType.BOOL);
ExprValue er = fp.evalResponse.getResult();
assertThat(er).extracting(ExprValue::getKindCase).isEqualTo(ExprValue.KindCase.VALUE);
Value ev = er.getValue();
assertThat(ev).extracting(Value::getKindCase).isEqualTo(Value.KindCase.BOOL_VALUE);
assertThat(ev).extracting(Value::getBoolValue).isEqualTo(true);
}
use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class ConformanceServerTest method Check.
/**
* TestCheck tests the Check method.
*/
@Test
void Check() {
// If TestParse() passes, it validates a good chunk
// of the server mechanisms for data conversion, so we
// won't be as fussy here..
CheckRequest req = CheckRequest.newBuilder().setParsedExpr(parsed).build();
CheckResponse res = stub.check(req);
assertThat(res.isInitialized()).isTrue();
assertThat(res.getCheckedExpr().isInitialized()).isTrue();
Type tp = res.getCheckedExpr().getTypeMapMap().get(1L);
assertThat(tp).isNotNull();
assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
}
Aggregations