Package com.indeed.proctor.common.model

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


            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets,
                                                      // Allocations do not add up to 1
                                                      fromCompactAllocationFormat("ruleA|-1:0.5,0:0.5,1:0.0", "-1:0.0,0:0.0,1:0.0")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // verifyAndConsolidate should not throw an error because the 'invalidbuckets' test is not required.
            assertEquals(1, matrix.getTests().size());
            assertValid("invalid test not required, sum{allocations} < 1.0", matrix, Collections.<String, TestSpecification>emptyMap());
            assertEquals("non-required tests should be removed from the matrix", 0, matrix.getTests().size());
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets,
                                                      // Allocations do not add up to 1
                                                      fromCompactAllocationFormat("ruleA|-1:0.5,0:0.5,1:0.0", "-1:0.0,0:0.0,1:0.0")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // verifyAndConsolidate should throw an error because the 'invalidbuckets' test is required.
            assertEquals(1, matrix.getTests().size());
            assertInvalid("bucket allocation sums are unchecked, sum{allocations} < 1.0", matrix, requiredTests);
            assertEquals("required tests should not be removed from the matrix", 1, matrix.getTests().size());
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets,
                                                      // Allocations do not add up to 1
                                                      fromCompactAllocationFormat("ruleA|-1:0.5,0:0.5,1:0.0", "-1:0.5,0:0.5,1:0.5")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertEquals(1, matrix.getTests().size());
            // verifyAndConsolidate should not throw an error because the 'invalidbuckets' test is not required.
            assertValid("invalid test not required, sum{allocations} > 1.0", matrix, Collections.<String, TestSpecification>emptyMap());
            assertEquals("non-required tests should be removed from the matrix", 0, matrix.getTests().size());
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets,
                                                      // Allocations do not add up to 1
                                                      fromCompactAllocationFormat("ruleA|-1:0.5,0:0.5,1:0.0", "-1:0.5,0:0.5,1:0.5")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertEquals(1, matrix.getTests().size());
            // verifyAndConsolidate should throw an error because the 'testa' test is required.
            assertInvalid("bucket allocation sums are unchecked, sum{allocations} > 1.0", matrix, requiredTests);
            assertEquals("required tests should not be removed from the matrix", 1, matrix.getTests().size());
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets,
                                                      // Allocations add up to 1.0
                                                      fromCompactAllocationFormat("ruleA|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertEquals(1, matrix.getTests().size());
            assertValid("bucket allocation sums are unchecked, sum{allocations} == 1.0", matrix, Collections.<String, TestSpecification>emptyMap());
            assertEquals("non-required tests should be removed from the matrix", 0, matrix.getTests().size());
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets,
                                                      // Allocations add up to 1.0
                                                      fromCompactAllocationFormat("ruleA|-1:0.5,0:0.5,1:0.0", "-1:0.25,0:0.5,1:0.25")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertEquals(1, matrix.getTests().size());
            assertValid("bucket allocation sums are unchecked, sum{allocations} == 1.0", matrix, requiredTests);
            assertEquals("required tests should not be removed from the matrix", 1, matrix.getTests().size());
        }
    }
View Full Code Here


        Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets));
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets, Collections.<Allocation>emptyList()));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertValid("test missing allocations is not required", matrix, Collections.<String, TestSpecification>emptyMap());
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets, Collections.<Allocation>emptyList()));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertInvalid("test missing allocations is required", matrix, requiredTests);
        }
    }
View Full Code Here

            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
            assertInvalid("allocation for externally unknown bucket (two) > 0", matrix, requiredTests);
            assertEquals("trivially expected only one test in the matrix", 1, matrix.getTests().size());
            final List<Allocation> allocations = matrix.getTests().values().iterator().next().getAllocations();
            assertEquals("trivially expected only one allocation in the test (same as source)", 1, allocations.size());
            final List<Range> ranges = allocations.iterator().next().getRanges();
            assertEquals("Expected the ranges to be reduced from 3 to 1, since only the fallback value is now present", 1, ranges.size());
            final Range onlyRange = ranges.iterator().next();
            assertEquals("Should have adopted the fallback value from the test spec", onlyRange.getBucketValue(), testSpecification.getFallbackValue());
            assertEquals("Trivially should have been set to 100% fallback", 1.0, onlyRange.getLength(), 0.005);
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            // Allocation of bucketValue=2 is == 0
            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("0:0.5,1:0.5,2:0")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertValid("allocation for externally unknown bucket (two) == 0", matrix, requiredTests);
        }
    }
View Full Code Here

        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            // Allocation has 4 buckets, bucket with non-zero allocation in an unknown bucket
            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("0:0,1:0,2:0.5,3:0.5")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally inconsistent matrix
            assertInvalid("allocation for internally unknown bucket (three) > 0", matrix, requiredTests);
        }
        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            // There is an unknown bucket with non-zero allocation
            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("0:0,1:0,2:0.5,3:0.5")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally inconsistent matrix
            assertInvalid("allocation for internally unknown bucket (three) == 0", matrix, requiredTests);
        }
    }
View Full Code Here

        {
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets_matrix, fromCompactAllocationFormat("0:0,1:1.0")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally inconsistent matrix
            assertValid("test-matrix has a subset of required buckets", matrix, requiredTests);
        }
    }
View Full Code Here

            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            // The Bucket Names and Values intentionally do not match
            tests.put(TEST_A, constructDefinition(fromCompactBucketFormat("zero:1,one:0"),
                                                  fromCompactAllocationFormat("0:0,1:1.0")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertValid("test-matrix has a different {bucketValue} -> {bucketName} mapping than required Tests", matrix, requiredTests);
        }
        {
            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(fromCompactBucketFormat("zero:0,one:1,two:2")));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            // The Bucket Names and Values intentionally do not match
            tests.put(TEST_A, constructDefinition(fromCompactBucketFormat("zero:0,one:2"),
                                                  fromCompactAllocationFormat("0:0,2:1.0")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertValid("test-matrix has a different {bucketValue} -> {bucketName} mapping than required Tests", matrix, requiredTests);
        }
    }
View Full Code Here

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

            // Artifact only has 1 of the 2 required tests
            final TestMatrixArtifact matrix = constructArtifact(tests);

            // 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")));
            tests.put(TEST_B, constructDefinition(buckets_B, fromCompactAllocationFormat("0:0.5,1:0.5")));

            // Artifact both of the required tests
            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("both required tests are present in the matrix", matrix, requiredTests);
        }
        {
            Map<String, TestSpecification> only_TestA_Required = ImmutableMap.of(TEST_A, transformTestBuckets(buckets_A));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();
            tests.put(TEST_A, constructDefinition(buckets_A, fromCompactAllocationFormat("0:0,1:0.5,2:0.5")));
            // Intentionally making the non-required test B allocation sum to 0.5
            tests.put(TEST_B, constructDefinition(buckets_B, fromCompactAllocationFormat("0:0,1:0.5")));

            // Artifact both of the required tests
            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertEquals(2, matrix.getTests().size());
            assertValid("required test A is present in the matrix", matrix, only_TestA_Required);

            assertEquals("Only required test A should remain in the matrix", 1, matrix.getTests().size());
            assertTrue("Only required test A should remain in the matrix", matrix.getTests().containsKey(TEST_A));
            assertFalse("Only required test A should remain in the matrix", matrix.getTests().containsKey(TEST_B));
        }
    }
View Full Code Here

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("all payloads of the same type", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setLongValue(-1L);
            buckets.get(0).setPayload(p);
            // bucket 1 is missing a payload here.
            p = new Payload();
            p.setLongValue(1L);
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("not all payloads of the test defined", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setStringValue("inact");
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setStringValue("foo");
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setStringValue("bar");
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("all payloads of the wrong type", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setLongValue(-1L);
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setLongValue(0L);
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setStringValue("foo");
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally inconsistent matrix: different payload types in test
            assertInvalid("all payloads not of the same type", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setStringArray(new String[]{})// empty arrays are allowed.
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setStringArray(new String[]{"foo", "bar"});
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setStringArray(new String[]{"baz", "quux", "xyzzy"});
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "stringArray", null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("vector payloads can be different lengths", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2","one","val3",new ArrayList<String>()));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2","tw","val3",new ArrayList<String>(){{add("a");add("c");}}));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2","th","val3",new ArrayList<String>(){{add("foo");add("bar");}}));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","stringValue","val3","stringArray"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertValid("correct allocation and object, map with double values", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2",3.0,"val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val3",1.0,"val4",3.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",2.0,"val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","doubleValue","val3","doubleValue"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("map payloads can't have different variable names", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2","yea1","val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2","yea2","val3",3.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2","yea3","val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","doubleValue","val3","doubleValue"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("map payloads can't have different variable types than specified", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2",3.0,"val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",1.0,"val3",3.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",2.0,"val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","doubleValue","val3","doubleValue","val4","doubleArray"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("map payloads can't have less variable types than specified", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2",3.0,"val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",new ArrayList<Double>(){{add(1.0D);}},"val3",3.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",2.0,"val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","doubleValue","val3","doubleValue"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("map payloads can't have different variable types than specified -- an array instead of a single value", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2",ImmutableMap.<String,Object>of("a",1,"b",2),"val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",ImmutableMap.<String,Object>of("c",3,"d",4),"val3",3.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",ImmutableMap.<String,Object>of("e",5,"f",6),"val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","map","val3","doubleValue"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("map payloads can't nested map payloads", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2","one","val3",new ArrayList<String>()));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2","tw","val3",new ArrayList<String>(){{add("a");add("c");}}));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2","th","val3",new ArrayList(){{add(2.1D);add("bar");}}));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets,"map",
                    ImmutableMap.of("val1","doubleValue","val2","stringValue","val3","stringArray"), null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            assertInvalid("map payload nested arrays can't have multiple types", matrix, requiredTests);
        }
    }
View Full Code Here

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "doubleValue", "${value >= 0}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("doubleValue: all payload values pass validation", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setDoubleValue(0D);
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setDoubleValue(10D);
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setDoubleValue(-1D);
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "doubleValue", "${value >= 0}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("doubleValue: a payload value doesn't pass validation", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setLongValue(0L);
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setLongValue(10L);
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setLongValue(20L);
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", "${value >= 0}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("longValue: all payload values pass validation", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setLongValue(0L);
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setLongValue(10L);
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setLongValue(-1L);
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", "${value >= 0}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("longValue: a payload value doesn't pass validation", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setStringValue("inactive");
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setStringValue("foo");
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setStringValue("bar");
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "stringValue", "${value >= \"b\"}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("stringValue: all payload values pass validation", matrix, requiredTests);
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setStringValue("inactive");
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setStringValue("foo");
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setStringValue("abba");
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "stringValue", "${value >= \"b\"}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("stringValue: a payload value doesn't pass validation", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2",3.0,"val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",4.0,"val3",1.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",2.0,"val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "map", ImmutableMap.of("val1","doubleValue","val2","doubleValue","val3","doubleValue"), "${val1 + val2 + val3 < 10}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("map: a payload value that should pass validation", matrix, requiredTests);
        }
        {
            final List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",1.0,"val2",3.0,"val3",1.0));
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",4.0,"val3",1.0));
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setMap(ImmutableMap.<String,Object>of("val1",2.0,"val2",6.0,"val3",2.0));
            buckets.get(2).setPayload(p);

            final Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "map", ImmutableMap.of("val1","doubleValue","val2","doubleValue","val3","doubleValue"), "${val1 + val2 + val3 < 10}"));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertInvalid("map: a payload value doesn't pass validation", matrix, requiredTests);
        }
    }
View Full Code Here

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets)); // no payload type specified
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("no payload expected; payloads supplied of the same type", matrix, requiredTests);

            // 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());
                }
            }
        }
        {
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");
            Payload p = new Payload();
            p.setLongValue(-1L);
            buckets.get(0).setPayload(p);
            p = new Payload();
            p.setLongValue(0L);
            buckets.get(1).setPayload(p);
            p = new Payload();
            p.setStringValue("foo");
            buckets.get(2).setPayload(p);

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets)); // no payload type specified
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally inconsistent matrix: different payload types in test
            assertInvalid("no payload expected; payloads supplied of different types", matrix, requiredTests);
        }
        {
            // Proctor should not break if it consumes a test matrix
            // with no payloads when it is expecting one.
            List<TestBucket> buckets = fromCompactBucketFormat("inactive:-1,control:0,test:1");

            Map<String, TestSpecification> requiredTests = ImmutableMap.of(TEST_A, transformTestBuckets(buckets, "longValue", null));
            final Map<String, ConsumableTestDefinition> tests = Maps.newHashMap();

            tests.put(TEST_A, constructDefinition(buckets, fromCompactAllocationFormat("-1:0.2,0:0.4,1:0.4")));

            final TestMatrixArtifact matrix = constructArtifact(tests);

            // internally consistent matrix
            assertValid("payload expected; no payloads supplied", matrix, requiredTests);
            // Should have gotten back a test.
            assertEquals("required tests should not be removed from the matrix", 1, matrix.getTests().size());
        }
    }
View Full Code Here

TOP

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

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.