Package com.indeed.proctor.common
Class ProctorUtils
- java.lang.Object
-
- com.indeed.proctor.common.ProctorUtils
-
public abstract class ProctorUtils extends java.lang.ObjectHelper functions mostly to verify TestMatrix instances.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringUNITLESS_ALLOCATION_IDENTIFIER
-
Constructor Summary
Constructors Constructor Description ProctorUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleancontainsUnitlessAllocation(TestDefinition testDefinition)static java.util.Map<java.lang.String,javax.el.ValueExpression>convertConstantsToValueExpressionMap(javax.el.ExpressionFactory expressionFactory, java.util.Map<java.lang.String,java.lang.Object> values)static ProvidedContextconvertContextToTestableMap(java.util.Map<java.lang.String,java.lang.String> providedContext)static ProvidedContextconvertContextToTestableMap(java.util.Map<java.lang.String,java.lang.String> providedContext, java.util.Map<java.lang.String,java.lang.Object> ruleVerificationContext)static java.lang.StringconvertToArtifact(TestMatrixVersion testMatrix)static TestMatrixArtifactconvertToConsumableArtifact(TestMatrixVersion testMatrix)static ConsumableTestDefinitionconvertToConsumableTestDefinition(TestDefinition td)static java.util.Map<java.lang.String,javax.el.ValueExpression>convertToValueExpressionMap(javax.el.ExpressionFactory expressionFactory, java.util.Map<java.lang.String,java.lang.Object> values)static java.security.MessageDigestcreateMessageDigest()static TestSpecificationgenerateSpecification(TestDefinition testDefinition)Deprecated.use SpecificationGeneratorstatic com.fasterxml.jackson.databind.JsonNodereadJsonFromFile(java.io.File input)Deprecated.Use serialization library like jacksonstatic ProctorSpecificationreadSpecification(java.io.File inputFile)static ProctorSpecificationreadSpecification(java.io.InputStream inputFile)static java.lang.StringremoveElExpressionBraces(java.lang.String rule)Removes the expression braces "${ ...static voidserializeArtifact(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, Proctor proctor)Deprecated.Use serialization library like jacksonstatic voidserializeArtifact(java.io.Writer writer, TestMatrixArtifact artifact)Deprecated.Use serialization library like jacksonstatic voidserializeTestDefinition(java.io.Writer writer, TestDefinition definition)Deprecated.Use serialization library like jacksonstatic voidserializeTestSpecification(java.io.Writer writer, TestSpecification specification)Deprecated.Use serialization library like jacksonstatic ProctorLoadResultverify(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests)verify with default function mapper and empty context and no dynamic testsstatic ProctorLoadResultverify(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests, java.util.Set<java.lang.String> dynamicTests)verify with default function mapper and empty contextstatic ProctorLoadResultverify(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests, javax.el.FunctionMapper functionMapper, ProvidedContext providedContext)verify with default function mapper and no dynamic testsstatic ProctorLoadResultverify(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests, javax.el.FunctionMapper functionMapper, ProvidedContext providedContext, java.util.Set<java.lang.String> dynamicTests)Does not mutate the TestMatrix.static ProctorLoadResultverifyAndConsolidate(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests, javax.el.FunctionMapper functionMapper)Verifies that the TestMatrix is compatible with all the required tests.static ProctorLoadResultverifyAndConsolidate(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests, javax.el.FunctionMapper functionMapper, ProvidedContext providedContext)static ProctorLoadResultverifyAndConsolidate(TestMatrixArtifact testMatrix, java.lang.String matrixSource, java.util.Map<java.lang.String,TestSpecification> requiredTests, javax.el.FunctionMapper functionMapper, ProvidedContext providedContext, java.util.Set<java.lang.String> dynamicTests)static voidverifyDynamicTest(java.lang.String testName, ConsumableTestDefinition testDefinition, java.lang.String matrixSource, javax.el.FunctionMapper functionMapper, ProvidedContext providedContext)Verifies that a single dynamic test is valid againstFunctionMapperandProvidedContext.static voidverifyInternallyConsistentDefinition(java.lang.String testName, java.lang.String matrixSource, ConsumableTestDefinition testDefinition)verifyInternallyConsistentDefinition with default functionMapper, but do not evaluate rule against any contextstatic voidverifyInternallyConsistentDefinition(java.lang.String testName, java.lang.String matrixSource, ConsumableTestDefinition testDefinition, ProvidedContext providedContext)verifyInternallyConsistentDefinition with default functionMapper and evaluate against contextstatic voidverifyRequiredTest(java.lang.String testName, ConsumableTestDefinition testDefinition, TestSpecification testSpecification, java.lang.String matrixSource, javax.el.FunctionMapper functionMapper, ProvidedContext providedContext)Verifies that a single required test is valid againstTestSpecificationandFunctionMapperandProvidedContext.static ProctorLoadResultverifyWithoutSpecification(TestMatrixArtifact testMatrix, java.lang.String matrixSource)Verifies that the TestMatrix is correct and sane without using a specification.
-
-
-
Field Detail
-
UNITLESS_ALLOCATION_IDENTIFIER
public static final java.lang.String UNITLESS_ALLOCATION_IDENTIFIER
- See Also:
- Constant Field Values
-
-
Method Detail
-
createMessageDigest
public static java.security.MessageDigest createMessageDigest()
-
convertToValueExpressionMap
@Nonnull public static java.util.Map<java.lang.String,javax.el.ValueExpression> convertToValueExpressionMap(@Nonnull javax.el.ExpressionFactory expressionFactory, @Nonnull java.util.Map<java.lang.String,java.lang.Object> values)
-
convertConstantsToValueExpressionMap
@Nonnull public static java.util.Map<java.lang.String,javax.el.ValueExpression> convertConstantsToValueExpressionMap(@Nonnull javax.el.ExpressionFactory expressionFactory, @Nonnull java.util.Map<java.lang.String,java.lang.Object> values)
-
convertToArtifact
public static java.lang.String convertToArtifact(@Nonnull TestMatrixVersion testMatrix) throws java.io.IOException- Throws:
java.io.IOException
-
serializeArtifact
@Deprecated public static void serializeArtifact(java.io.Writer writer, TestMatrixArtifact artifact) throws java.io.IOExceptionDeprecated.Use serialization library like jackson- Throws:
java.io.IOException
-
serializeArtifact
@Deprecated public static void serializeArtifact(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, Proctor proctor) throws java.io.IOExceptionDeprecated.Use serialization library like jackson- Throws:
java.io.IOException
-
serializeTestDefinition
@Deprecated public static void serializeTestDefinition(java.io.Writer writer, TestDefinition definition) throws java.io.IOExceptionDeprecated.Use serialization library like jackson- Throws:
java.io.IOException
-
readJsonFromFile
@Deprecated public static com.fasterxml.jackson.databind.JsonNode readJsonFromFile(java.io.File input) throws java.io.IOExceptionDeprecated.Use serialization library like jackson- Throws:
java.io.IOException
-
serializeTestSpecification
@Deprecated public static void serializeTestSpecification(java.io.Writer writer, TestSpecification specification) throws java.io.IOExceptionDeprecated.Use serialization library like jackson- Throws:
java.io.IOException
-
convertToConsumableArtifact
@Nonnull public static TestMatrixArtifact convertToConsumableArtifact(@Nonnull TestMatrixVersion testMatrix)
-
convertToConsumableTestDefinition
@Nonnull @Deprecated public static ConsumableTestDefinition convertToConsumableTestDefinition(@Nonnull TestDefinition td)
-
readSpecification
public static ProctorSpecification readSpecification(java.io.File inputFile)
-
readSpecification
public static ProctorSpecification readSpecification(java.io.InputStream inputFile)
-
verifyAndConsolidate
public static ProctorLoadResult verifyAndConsolidate(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests, @Nonnull javax.el.FunctionMapper functionMapper)
Verifies that the TestMatrix is compatible with all the required tests. Removes non-required tests from the TestMatrix Replaces invalid or missing tests (buckets are not compatible) with default implementation returning the fallback value see defaultFor- Parameters:
testMatrix- theTestMatrixArtifactto be verified.matrixSource- aStringof the source of proctor artifact. For example, a path of proctor artifact file.requiredTests- aMapof required test. TheTestSpecificationwould be verifiedfunctionMapper- a given elFunctionMapper- Returns:
- a
ProctorLoadResultto describe the result of verification. It contains errors of verification and a list of missing test.
-
verifyAndConsolidate
public static ProctorLoadResult verifyAndConsolidate(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests, @Nonnull javax.el.FunctionMapper functionMapper, ProvidedContext providedContext)
-
verifyAndConsolidate
public static ProctorLoadResult verifyAndConsolidate(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests, @Nonnull javax.el.FunctionMapper functionMapper, ProvidedContext providedContext, @Nonnull java.util.Set<java.lang.String> dynamicTests)
- Parameters:
testMatrix- will be modified by removing unused tests and adding missing tests
-
verifyWithoutSpecification
public static ProctorLoadResult verifyWithoutSpecification(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource)
Verifies that the TestMatrix is correct and sane without using a specification. The Proctor API doesn't use a test specification so that it can serve all tests in the matrix without restriction. Does a limited set of sanity checks that are applicable when there is no specification, and thus no required tests or provided context.- Parameters:
testMatrix- theTestMatrixArtifactto be verified.matrixSource- aStringof the source of proctor artifact. For example, a path of proctor artifact file.- Returns:
- a
ProctorLoadResultto describe the result of verification. It contains errors of verification and a list of missing test.
-
verify
public static ProctorLoadResult verify(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests)
verify with default function mapper and empty context and no dynamic tests
-
verify
public static ProctorLoadResult verify(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests, @Nonnull java.util.Set<java.lang.String> dynamicTests)
verify with default function mapper and empty context
-
verify
public static ProctorLoadResult verify(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests, @Nonnull javax.el.FunctionMapper functionMapper, ProvidedContext providedContext)
verify with default function mapper and no dynamic tests
-
verify
public static ProctorLoadResult verify(@Nonnull TestMatrixArtifact testMatrix, java.lang.String matrixSource, @Nonnull java.util.Map<java.lang.String,TestSpecification> requiredTests, @Nonnull javax.el.FunctionMapper functionMapper, ProvidedContext providedContext, @Nonnull java.util.Set<java.lang.String> dynamicTests)
Does not mutate the TestMatrix. Verifies that the test matrix contains all the required tests and that each required test is valid.- Parameters:
testMatrix- theTestMatrixArtifactto be verified.matrixSource- aStringof the source of proctor artifact. For example, a path of proctor artifact file.requiredTests- aMapof required test. TheTestSpecificationwould be verifiedfunctionMapper- a given elFunctionMapperprovidedContext- aMapcontaining variables describing the context in which the request is executing. These will be supplied to verifying all rules.dynamicTests- aSetof dynamic tests determined by filters.- Returns:
- a
ProctorLoadResultto describe the result of verification. It contains errors of verification and a list of missing test.
-
verifyRequiredTest
public static void verifyRequiredTest(@Nonnull java.lang.String testName, @Nonnull ConsumableTestDefinition testDefinition, @Nonnull TestSpecification testSpecification, @Nonnull java.lang.String matrixSource, @Nonnull javax.el.FunctionMapper functionMapper, ProvidedContext providedContext) throws IncompatibleTestMatrixExceptionVerifies that a single required test is valid againstTestSpecificationandFunctionMapperandProvidedContext.- Parameters:
testName- the name of the testtestDefinition-ConsumableTestDefinitionof the testtestSpecification-TestSpecificationdefined in an application for the testmatrixSource- aStringof the source of proctor artifact. For example, a path of proctor artifact file.functionMapper- a given elFunctionMapperprovidedContext- aMapcontaining variables describing the context in which the request is executing. These will be supplied to verifying all rules.- Throws:
IncompatibleTestMatrixException- if validation is failed.
-
verifyDynamicTest
public static void verifyDynamicTest(@Nonnull java.lang.String testName, @Nonnull ConsumableTestDefinition testDefinition, @Nonnull java.lang.String matrixSource, @Nonnull javax.el.FunctionMapper functionMapper, ProvidedContext providedContext) throws IncompatibleTestMatrixExceptionVerifies that a single dynamic test is valid againstFunctionMapperandProvidedContext.- Parameters:
testName- the name of the testtestDefinition-ConsumableTestDefinitionof the testmatrixSource- aStringof the source of proctor artifact. For example, a path of proctor artifact file.functionMapper- a given elFunctionMapperprovidedContext- aMapcontaining variables describing the context in which the request is executing. These will be supplied to verifying all rules.- Throws:
IncompatibleTestMatrixException- if validation is failed.
-
convertContextToTestableMap
public static ProvidedContext convertContextToTestableMap(java.util.Map<java.lang.String,java.lang.String> providedContext)
-
convertContextToTestableMap
public static ProvidedContext convertContextToTestableMap(java.util.Map<java.lang.String,java.lang.String> providedContext, java.util.Map<java.lang.String,java.lang.Object> ruleVerificationContext)
-
verifyInternallyConsistentDefinition
public static void verifyInternallyConsistentDefinition(java.lang.String testName, java.lang.String matrixSource, @Nonnull ConsumableTestDefinition testDefinition) throws IncompatibleTestMatrixExceptionverifyInternallyConsistentDefinition with default functionMapper, but do not evaluate rule against any context- Throws:
IncompatibleTestMatrixException
-
verifyInternallyConsistentDefinition
public static void verifyInternallyConsistentDefinition(java.lang.String testName, java.lang.String matrixSource, @Nonnull ConsumableTestDefinition testDefinition, ProvidedContext providedContext) throws IncompatibleTestMatrixExceptionverifyInternallyConsistentDefinition with default functionMapper and evaluate against context- Throws:
IncompatibleTestMatrixException
-
generateSpecification
@Deprecated public static TestSpecification generateSpecification(@Nonnull TestDefinition testDefinition)
Deprecated.use SpecificationGeneratorGenerates a usable test specification for a given test definition Uses the bucket with smallest value as the fallback value- Parameters:
testDefinition- aTestDefinition- Returns:
- a
TestSpecificationwhich corresponding to given test definition.
-
removeElExpressionBraces
@CheckForNull public static java.lang.String removeElExpressionBraces(@Nullable java.lang.String rule)Removes the expression braces "${ ... }" surrounding the rule.- Parameters:
rule- a given rule String.- Returns:
- the given rule with the most outside braces stripped
-
containsUnitlessAllocation
public static boolean containsUnitlessAllocation(@Nonnull TestDefinition testDefinition)
-
-