Search in sources :

Example 11 with VerifyException

use of com.google.common.base.VerifyException in project grpc-java by grpc.

the class ServiceConfigUtil method getStatusCodesFromList.

private static Set<Status.Code> getStatusCodesFromList(List<?> statuses) {
    EnumSet<Status.Code> codes = EnumSet.noneOf(Status.Code.class);
    for (Object status : statuses) {
        Status.Code code;
        if (status instanceof Double) {
            Double statusD = (Double) status;
            int codeValue = statusD.intValue();
            verify((double) codeValue == statusD, "Status code %s is not integral", status);
            code = Status.fromCodeValue(codeValue).getCode();
            verify(code.value() == statusD.intValue(), "Status code %s is not valid", status);
        } else if (status instanceof String) {
            try {
                code = Status.Code.valueOf((String) status);
            } catch (IllegalArgumentException iae) {
                throw new VerifyException("Status code " + status + " is not valid", iae);
            }
        } else {
            throw new VerifyException("Can not convert status code " + status + " to Status.Code, because its type is " + status.getClass());
        }
        codes.add(code);
    }
    return Collections.unmodifiableSet(codes);
}
Also used : Status(io.grpc.Status) VerifyException(com.google.common.base.VerifyException)

Example 12 with VerifyException

use of com.google.common.base.VerifyException in project auto by google.

the class AutoBuilderProcessor method build.

private String build(ExecutableElement executable) {
    TypeElement enclosing = MoreElements.asType(executable.getEnclosingElement());
    String type = TypeEncoder.encodeRaw(enclosing.asType());
    switch(executable.getKind()) {
        case CONSTRUCTOR:
            boolean generic = !enclosing.getTypeParameters().isEmpty();
            String typeParams = generic ? "<>" : "";
            return "new " + type + typeParams;
        case METHOD:
            return type + "." + executable.getSimpleName();
        default:
            throw new VerifyException("Unexpected executable kind " + executable.getKind());
    }
}
Also used : VerifyException(com.google.common.base.VerifyException) TypeElement(javax.lang.model.element.TypeElement)

Example 13 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class PageProcessorCompiler method generateMethodsForLambdaAndTry.

private PreGeneratedExpressions generateMethodsForLambdaAndTry(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression projection, String methodPrefix) {
    Set<RowExpression> lambdaAndTryExpressions = ImmutableSet.copyOf(extractLambdaAndTryExpressions(projection));
    ImmutableMap.Builder<CallExpression, MethodDefinition> tryMethodMap = ImmutableMap.builder();
    ImmutableMap.Builder<LambdaDefinitionExpression, FieldDefinition> lambdaFieldMap = ImmutableMap.builder();
    int counter = 0;
    for (RowExpression expression : lambdaAndTryExpressions) {
        if (expression instanceof CallExpression) {
            CallExpression tryExpression = (CallExpression) expression;
            verify(!Signatures.TRY.equals(tryExpression.getSignature().getName()));
            Parameter session = arg("session", ConnectorSession.class);
            List<Parameter> blocks = toBlockParameters(getInputChannels(tryExpression.getArguments()));
            Parameter position = arg("position", int.class);
            BytecodeExpressionVisitor innerExpressionVisitor = new BytecodeExpressionVisitor(callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(callSiteBinder), metadata.getFunctionRegistry(), new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build()));
            List<Parameter> inputParameters = ImmutableList.<Parameter>builder().add(session).addAll(blocks).add(position).build();
            MethodDefinition tryMethod = defineTryMethod(innerExpressionVisitor, containerClassDefinition, methodPrefix + "_try_" + counter, inputParameters, Primitives.wrap(tryExpression.getType().getJavaType()), tryExpression, callSiteBinder);
            tryMethodMap.put(tryExpression, tryMethod);
        } else if (expression instanceof LambdaDefinitionExpression) {
            LambdaDefinitionExpression lambdaExpression = (LambdaDefinitionExpression) expression;
            PreGeneratedExpressions preGeneratedExpressions = new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build());
            FieldDefinition methodHandleField = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, methodPrefix + "_lambda_" + counter, containerClassDefinition, preGeneratedExpressions, callSiteBinder, cachedInstanceBinder, metadata.getFunctionRegistry());
            lambdaFieldMap.put(lambdaExpression, methodHandleField);
        } else {
            throw new VerifyException(format("unexpected expression: %s", expression.toString()));
        }
        counter++;
    }
    return new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build());
}
Also used : FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) RowExpression(com.facebook.presto.sql.relational.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) VerifyException(com.google.common.base.VerifyException) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) CallExpression(com.facebook.presto.sql.relational.CallExpression) LambdaDefinitionExpression(com.facebook.presto.sql.relational.LambdaDefinitionExpression)

Example 14 with VerifyException

use of com.google.common.base.VerifyException in project presto by prestodb.

the class CursorProcessorCompiler method generateMethodsForLambdaAndTry.

private PreGeneratedExpressions generateMethodsForLambdaAndTry(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression projection, String methodPrefix) {
    Set<RowExpression> lambdaAndTryExpressions = ImmutableSet.copyOf(extractLambdaAndTryExpressions(projection));
    ImmutableMap.Builder<CallExpression, MethodDefinition> tryMethodMap = ImmutableMap.builder();
    ImmutableMap.Builder<LambdaDefinitionExpression, FieldDefinition> lambdaFieldMap = ImmutableMap.builder();
    int counter = 0;
    for (RowExpression expression : lambdaAndTryExpressions) {
        if (expression instanceof CallExpression) {
            CallExpression tryExpression = (CallExpression) expression;
            verify(!Signatures.TRY.equals(tryExpression.getSignature().getName()));
            Parameter session = arg("session", ConnectorSession.class);
            Parameter cursor = arg("cursor", RecordCursor.class);
            List<Parameter> inputParameters = ImmutableList.<Parameter>builder().add(session).add(cursor).build();
            BytecodeExpressionVisitor innerExpressionVisitor = new BytecodeExpressionVisitor(callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(cursor), metadata.getFunctionRegistry(), new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build()));
            MethodDefinition tryMethod = defineTryMethod(innerExpressionVisitor, containerClassDefinition, methodPrefix + "_try_" + counter, inputParameters, Primitives.wrap(tryExpression.getType().getJavaType()), tryExpression, callSiteBinder);
            tryMethodMap.put(tryExpression, tryMethod);
        } else if (expression instanceof LambdaDefinitionExpression) {
            LambdaDefinitionExpression lambdaExpression = (LambdaDefinitionExpression) expression;
            String fieldName = methodPrefix + "_lambda_" + counter;
            PreGeneratedExpressions preGeneratedExpressions = new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build());
            FieldDefinition methodHandleField = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, fieldName, containerClassDefinition, preGeneratedExpressions, callSiteBinder, cachedInstanceBinder, metadata.getFunctionRegistry());
            lambdaFieldMap.put(lambdaExpression, methodHandleField);
        } else {
            throw new VerifyException(format("unexpected expression: %s", expression.toString()));
        }
        counter++;
    }
    return new PreGeneratedExpressions(tryMethodMap.build(), lambdaFieldMap.build());
}
Also used : FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) RowExpression(com.facebook.presto.sql.relational.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) VerifyException(com.google.common.base.VerifyException) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) CallExpression(com.facebook.presto.sql.relational.CallExpression) LambdaDefinitionExpression(com.facebook.presto.sql.relational.LambdaDefinitionExpression)

Example 15 with VerifyException

use of com.google.common.base.VerifyException in project grpc-java by grpc.

the class DetailErrorSample method verifyErrorReply.

static void verifyErrorReply(Throwable t) {
    Status status = Status.fromThrowable(t);
    Metadata trailers = Status.trailersFromThrowable(t);
    Verify.verify(status.getCode() == Status.Code.INTERNAL);
    Verify.verify(trailers.containsKey(DEBUG_INFO_TRAILER_KEY));
    Verify.verify(status.getDescription().equals(DEBUG_DESC));
    try {
        Verify.verify(trailers.get(DEBUG_INFO_TRAILER_KEY).equals(DEBUG_INFO));
    } catch (IllegalArgumentException e) {
        throw new VerifyException(e);
    }
}
Also used : Status(io.grpc.Status) VerifyException(com.google.common.base.VerifyException) Metadata(io.grpc.Metadata)

Aggregations

VerifyException (com.google.common.base.VerifyException)25 ImmutableMap (com.google.common.collect.ImmutableMap)8 PrestoException (com.facebook.presto.spi.PrestoException)6 List (java.util.List)6 Map (java.util.Map)6 Objects.requireNonNull (java.util.Objects.requireNonNull)6 Logger (com.facebook.airlift.log.Logger)5 Type (com.facebook.presto.common.type.Type)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Slice (io.airlift.slice.Slice)5 ArrayList (java.util.ArrayList)5 Optional (java.util.Optional)5 Set (java.util.Set)5 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 String.format (java.lang.String.format)4 Collection (java.util.Collection)4 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)3