use of com.google.api.expr.v1alpha1.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.api.expr.v1alpha1.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.api.expr.v1alpha1.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.api.expr.v1alpha1.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);
}
use of com.google.api.expr.v1alpha1.Type in project cel-java by projectnessie.
the class ConformanceServerTest method FullUp.
/**
* TestFullUp tests Parse, Check, and Eval back-to-back.
*/
@Test
void FullUp() {
ParseRequest preq = ParseRequest.newBuilder().setCelSource("x + y").build();
ParseResponse pres = stub.parse(preq);
assertThat(pres.isInitialized()).isTrue();
ParsedExpr parsedExpr = pres.getParsedExpr();
assertThat(parsedExpr.isInitialized()).isTrue();
CheckRequest creq = CheckRequest.newBuilder().setParsedExpr(parsedExpr).addTypeEnv(Decls.newVar("x", Decls.Int)).addTypeEnv(Decls.newVar("y", Decls.Int)).build();
CheckResponse cres = stub.check(creq);
assertThat(cres.isInitialized()).isTrue();
CheckedExpr checkedExpr = cres.getCheckedExpr();
assertThat(checkedExpr.isInitialized()).isTrue();
Type tp = checkedExpr.getTypeMapMap().get(1L);
assertThat(tp).isNotNull();
assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
EvalRequest ereq = EvalRequest.newBuilder().setCheckedExpr(checkedExpr).putBindings("x", exprValueInt64(1)).putBindings("y", exprValueInt64(2)).build();
EvalResponse eres = stub.eval(ereq);
assertThat(eres.isInitialized()).isTrue();
assertThat(eres.getResult().isInitialized()).isTrue();
assertThat(eres.getResult().getKindCase()).isSameAs(KindCase.VALUE);
assertThat(eres.getResult().getValue().getKindCase()).isSameAs(Value.KindCase.INT64_VALUE);
assertThat(eres.getResult().getValue().getInt64Value()).isEqualTo(3L);
}
Aggregations