Package com.indeed.proctor.common.model

Examples of com.indeed.proctor.common.model.ConsumableTestDefinition


    @Test
    public void testProvidedContextConversion() throws IncompatibleTestMatrixException {
        final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
        { //verify primitive types convert correctly
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time eq ''}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextString = new HashMap<String, String>();
            providedContextString.put("time", "String");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextString);
            ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion String", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
            //checking to make sure it can evaluate with converted provided context
        }
        { //verify primitive types convert correctly
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time eq 0}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextInteger = new HashMap<String, String>();
            providedContextInteger.put("time", "int");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextInteger);
            ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Integer", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
            //checking to make sure it can evaluate with converted provided context
        }
        { //verify primitive types convert correctly
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time eq ''}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextChar = new HashMap<String, String>();
            providedContextChar.put("time", "char");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextChar);
            ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Char", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
            //checking to make sure it can evaluate with converted provided context
        }
        { //verify primitive types convert correctly
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextBoolean = new HashMap<String, String>();
            providedContextBoolean.put("time", "Boolean");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextBoolean);
            ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Boolean", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
            //checking to make sure it can evaluate with converted provided context
        }
        { //verify User Defined enum Classes convert correctly
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time eq 'SPADES'}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextClass = new HashMap<String, String>();
            providedContextClass.put("time", "com.indeed.proctor.common.TestEnumType");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextClass);
            ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Class", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
            //checking to make sure it can evaluate with converted provided context
        }
        { //verify enums are actually used and an error is thrown with a nonexistent constant
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time eq 'SP'}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextClass = new HashMap<String, String>();
            providedContextClass.put("time", "com.indeed.proctor.common.TestEnumType");
            try {
                final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextClass);
View Full Code Here


    @Test
    public void testELValidity_atTestMatrixLoadTime() throws IncompatibleTestMatrixException, IOException {
        final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
        {
            //testing recognition of test constants
            final ConsumableTestDefinition testDefValConstants = constructDefinition(buckets,
                    fromCompactAllocationFormat("${proctor:now()>time}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, Object> providedConstantsVal = new HashMap<String, Object>();
            providedConstantsVal.put("time", "1");
            testDefValConstants.setConstants(providedConstantsVal);
            final Map<String, String> providedContext = Collections.emptyMap();
            ProctorUtils.verifyInternallyConsistentDefinition("testELevalwithcontext", "test context recognition", testDefValConstants, RuleEvaluator.FUNCTION_MAPPER,
                    ProctorUtils.convertContextToTestableMap(providedContext));
        }
        {//test if the providedContext is read in correctly
            final ConsumableTestDefinition testDefValConstants2 = constructDefinition(buckets,
                    fromCompactAllocationFormat("${proctor:now()>time}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final ObjectMapper objectMapper = new ObjectMapper();
            final ProctorSpecification spec = objectMapper.readValue(getClass().getResourceAsStream("no-context-specification.json"), ProctorSpecification.class);
            final Map<String, String> providedContext2 = spec.getProvidedContext(); //needs to read in empty provided context as Collections.emptyMap() and not null
            try {
                ProctorUtils.verifyInternallyConsistentDefinition("testELevalwithcontext", "test context recognition", testDefValConstants2, RuleEvaluator.FUNCTION_MAPPER,
                        ProctorUtils.convertContextToTestableMap(providedContext2));
                fail("expected IncompatibleTestMatrixException");
            } catch (IncompatibleTestMatrixException e) {
                //expected
            }
        }
        {//test that an error is thrown with missing providedContext
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${time eq ''}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            try {
                ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextMissing", "test Provided Context Missing", testDef, RuleEvaluator.FUNCTION_MAPPER, new ProvidedContext(ProvidedContext.EMPTY_CONTEXT,true));
                //checking to make sure it can evaluate with converted provided context
                fail("expected IncompatibleTestMatrixException due to missing provided Context");
            } catch (IncompatibleTestMatrixException e) {
                //expected
            }
        }
        {//testing recognition of providedContext in testRule
            final Map<String, String> providedContextVal = new HashMap<String, String>();
            providedContextVal.put("time", "Integer");
            ConsumableTestDefinition testDefValContextTestRule = constructDefinition(buckets,
                    fromCompactAllocationFormat("${proctor:now()>-1}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            testDefValContextTestRule.setRule("${proctor:now()>time}");
            ProctorUtils.verifyInternallyConsistentDefinition("testELevalwithcontext", "test context recognition in test rule", testDefValContextTestRule, RuleEvaluator.FUNCTION_MAPPER,
                    ProctorUtils.convertContextToTestableMap(providedContextVal));
        }
        { //testing that invalid properties are recognized
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${ua.iPad}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextClass = new HashMap<String, String>();
            providedContextClass.put("ua", "com.indeed.proctor.common.TestRulesClass");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextClass);
            try {
                ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Class", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
                fail("expected IncompatibleTestMatrixException due to missing attribute");
            } catch (IncompatibleTestMatrixException e) {
                // expected due to incorrect spelling
            }
        }
        { //testing that valid properties are recognized
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${ua.IPad}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));
            final Map<String, String> providedContextClass = new HashMap<String, String>();
            providedContextClass.put("ua", "com.indeed.proctor.common.TestRulesClass");
            final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(providedContextClass);
            ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Class", testDef, RuleEvaluator.FUNCTION_MAPPER, providedContext);
        }
        { //testing that invalid functions are recognized
            final ConsumableTestDefinition testDef = constructDefinition(buckets,
                    fromCompactAllocationFormat("${proctor:notafunction(5)}|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25"));

            try {
                ProctorUtils.verifyInternallyConsistentDefinition("testProvidedContextConversion", "test Provided Context Conversion Class", testDef, RuleEvaluator.FUNCTION_MAPPER, new ProvidedContext(ProvidedContext.EMPTY_CONTEXT,true));
                fail("expected IncompatibleTestMatrixException due to missing function");
View Full Code Here

        Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, testSpecification);

        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            // Allocation of bucketValue=2 is > 0
            final ConsumableTestDefinition testDefinition = constructDefinition(buckets, fromCompactAllocationFormat("0:0,1:0,2:1.0"));
            tests.put(TEST_A, testDefinition);

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // externally inconsistent matrix
View Full Code Here

            // internally inconsistent matrix
            assertNull("missing testB should not be present prior to consolidation", matrix.getTests().get(TEST_B));
            assertMissing("required testB is missing from the test matrix", matrix, requiredTests);

            final ConsumableTestDefinition consolidatedTestB = matrix.getTests().get(TEST_B);
            assertNotNull("autogenerated testB definition missing from consolidated matrix", consolidatedTestB);
            assertEquals(
                    "autogenerated testB definition should have used custom fallback value",
                    testSpecB.getFallbackValue(),
                    consolidatedTestB.getAllocations().get(0).getRanges().get(0).getBucketValue());

        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets_A, fromCompactAllocationFormat("0:0,1:0.5,2:0.5")));
View Full Code Here

            // Should have gotten back a test.
            assertEquals("required tests should not be removed from the matrix", 1, matrix.getTests().size());

            // Make sure we don't have any payloads in the resulting tests.
            for (Entry<String, ConsumableTestDefinition> next : matrix.getTests().entrySet()) {
                final ConsumableTestDefinition testDefinition = next.getValue();

                for (final TestBucket bucket : testDefinition.getBuckets()) {
                    assertNull(bucket.getPayload());
                }
            }
        }
        {
View Full Code Here

    }

    @Test
    public void testUnrecognizedTestType() throws Exception {
        final InputStream input = Preconditions.checkNotNull(getClass().getResourceAsStream(PATH_UNKNOWN_TEST_TYPE), "Missing test definition");
        final ConsumableTestDefinition test = Serializers.lenient().readValue(input, ConsumableTestDefinition.class);

        List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
        final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets));
        final Map<String, ConsumableTestDefinition> tests = ImmutableMap.of(TEST_A, test);

        {
            final TestMatrixArtifact matrix = constructArtifact(tests);

            // verifyAndConsolidate should not throw an error because the 'invalidbuckets' test is not required.
            assertEquals(1, matrix.getTests().size());
            assertInvalid("Test not recognized, replaced with 'invalid' marker test", matrix, requiredTests);
            assertEquals(1, matrix.getTests().size());
            final ConsumableTestDefinition replacement = matrix.getTests().values().iterator().next();
            assertEquals(TestType.RANDOM, replacement.getTestType());
            assertEquals(1, replacement.getBuckets().size());
            assertEquals(-1, replacement.getBuckets().iterator().next().getValue());
        }

        final TestType unrecognizedTestType = TestType.register("UNRECOGNIZED");
        {
            final TestMatrixArtifact matrix = constructArtifact(tests);

            // verifyAndConsolidate should not throw an error because the 'invalidbuckets' test is not required.
            assertEquals(1, matrix.getTests().size());
            final ConsumableTestDefinition original = matrix.getTests().values().iterator().next();
            assertEquals("Expected only the control and test buckets", 2, original.getBuckets().size());

            assertValid("Test now valid", matrix, requiredTests);
            assertEquals(1, matrix.getTests().size());
            final ConsumableTestDefinition stillOriginal = matrix.getTests().values().iterator().next();
            assertEquals(unrecognizedTestType, stillOriginal.getTestType());
            assertEquals("Expected only the control and test buckets", 2, stillOriginal.getBuckets().size());
        }
    }
View Full Code Here

    }

    private ConsumableTestDefinition constructDefinition(List<TestBucket> buckets,
                                                         List<Allocation> allocations) {

        final ConsumableTestDefinition test = new ConsumableTestDefinition();
        test.setVersion(""); // don't care about version for this test
        test.setSalt(null); // don't care about salt for this test
        test.setRule(null); // don't care about rule for this test
        test.setTestType(TestType.ANONYMOUS_USER);    // don't really care, but need a valid value
        test.setConstants(Collections.<String, Object>emptyMap()); // don't care about constants for this test

        test.setBuckets(buckets);
        test.setAllocations(allocations);
        return test;
    }
View Full Code Here

    private TestMatrixArtifact createThreeFakeTests()
    {
        final TestMatrixArtifact matrix = new TestMatrixArtifact();
        final Map<String, ConsumableTestDefinition> testMap = Maps.newHashMap();
        testMap.put("one", new ConsumableTestDefinition());
        testMap.put("two", new ConsumableTestDefinition());
        testMap.put("three", new ConsumableTestDefinition());

        // For appendTests to work, the testType property must not be null.
        testMap.get("one").setTestType(TestType.RANDOM);
        testMap.get("two").setTestType(TestType.RANDOM);
        testMap.get("three").setTestType(TestType.RANDOM);
View Full Code Here

        final Map<String, TestChooser<?>> testChoosers = Maps.newLinkedHashMap();
        final Map<String, String> versions = Maps.newLinkedHashMap();

        for (final Entry<String, ConsumableTestDefinition> entry : matrix.getTests().entrySet()) {
            final String testName = entry.getKey();
            final ConsumableTestDefinition testDefinition = entry.getValue();
            final TestType testType = testDefinition.getTestType();
            final TestChooser<?> testChooser;
            if (TestType.RANDOM.equals(testType)) {
                testChooser = new RandomTestChooser(expressionFactory, functionMapper, testName, testDefinition);
            } else {
                testChooser = new StandardTestChooser(expressionFactory, functionMapper, testName, testDefinition);
            }
            testChoosers.put(testName, testChooser);
            versions.put(testName, testDefinition.getVersion());
        }

        return new Proctor(matrix, loadResult, testChoosers);
    }
View Full Code Here

    @VisibleForTesting
    StandardTestChooser(@Nonnull final TestRangeSelector selector) {
        this.testRangeSelector = selector;
        this.hasher = newHasherFor(selector);

        final ConsumableTestDefinition testDefinition = selector.getTestDefinition();

        final Map<Integer, TestBucket> bucketValueToTest = Maps.newHashMap();
        for (final TestBucket testBucket : testDefinition.getBuckets()) {
            bucketValueToTest.put(testBucket.getValue(), testBucket);
        }

        final List<Allocation> allocations = testDefinition.getAllocations();
        this.cutoffs = new int[allocations.size()][];
        for (int i = 0; i < allocations.size(); i++) {
            final Allocation allocation = allocations.get(i);
            final List<Range> ranges = allocation.getRanges();
            cutoffs[i] = constructCutoffArray(allocation.getRule(), ranges);
View Full Code Here

TOP

Related Classes of com.indeed.proctor.common.model.ConsumableTestDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.