Package com.indeed.proctor.common.model

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


            for(String sRange : allRanges) {
                // Could handle index-out of bounds + number formatting exception better.
                String[] rangeParts = sRange.split(":");
                ranges.add(new Range(Integer.parseInt(rangeParts[0], 10), Double.parseDouble(rangeParts[1])));
            }
            allocationList.add(new Allocation(rule, ranges));
        }
        return allocationList;
    }
View Full Code Here


            for(String sRange : allRanges) {
                // Could handle index-out of bounds + number formatting exception better.
                String[] rangeParts = sRange.split(":");
                ranges.add(new Range(Integer.parseInt(rangeParts[0], 10), Double.parseDouble(rangeParts[1])));
            }
            allocationList.add(new Allocation(rule, ranges));
        }
        return allocationList;
    }
View Full Code Here

            Assert.assertEquals("test", testBucket.getName());
            Assert.assertEquals(1, testBucket.getValue());
            Assert.assertNull(testBucket.getDescription());

            Assert.assertEquals(2, definition.getAllocations().size());
            final Allocation englishAllocation = definition.getAllocations().get(0);
            Assert.assertEquals("${lang == ENGLISH}", englishAllocation.getRule());
            Assert.assertEquals(0.25, englishAllocation.getRanges().get(0).getLength(), 1E-16);
            Assert.assertEquals(0, englishAllocation.getRanges().get(0).getBucketValue());
            Assert.assertEquals(0.75, englishAllocation.getRanges().get(1).getLength(), 1E-16);
            Assert.assertEquals(1, englishAllocation.getRanges().get(1).getBucketValue());

            final Allocation defaultAllocation = definition.getAllocations().get(1);
            Assert.assertNull(defaultAllocation.getRule());
            Assert.assertEquals(0.1, defaultAllocation.getRanges().get(0).getLength(), 1E-16);
            Assert.assertEquals(0, defaultAllocation.getRanges().get(0).getBucketValue());
            Assert.assertEquals(0.90, defaultAllocation.getRanges().get(1).getLength(), 1E-16);
            Assert.assertEquals(1, defaultAllocation.getRanges().get(1).getBucketValue());
        } finally {
            input.close();
        }

    }
View Full Code Here

        final List<Allocation> allocations = testDefinition.getAllocations();
        this.rangeToBucket = new TestBucket[allocations.size()][];
        this.rules = new String[allocations.size()];
        for (int i = 0; i < allocations.size(); i++) {
            final Allocation allocation = allocations.get(i);
            rules[i] = allocation.getRule();
            final List<Range> ranges = allocation.getRanges();
            this.rangeToBucket[i] = new TestBucket[ranges.size()];
            for (int j = 0; j < ranges.size(); j++) {
                this.rangeToBucket[i][j] = bucketValueToTest.get(ranges.get(j).getBucketValue());
            }
        }
View Full Code Here

    /**
     * @deprecated Temporary implementation; this should be more like {@link StandardTestChooser}, with the cutoffs etc. set in the constructor.
     */
    TestBucket allocateRandomGroup(final int matchingRuleIndex) {
        final TestBucket[] matchingBucketRange = testRangeSelector.getBucketRange(matchingRuleIndex);
        final Allocation allocation = allocations.get(matchingRuleIndex);
        final List<Range> ranges = allocation.getRanges();

        final double nextDouble = random.nextDouble();
        double current = 0;

        for (final Range range : ranges) {
View Full Code Here

        }

        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

    @Nonnull
    private static ConsumableTestDefinition defaultFor(final String testName, @Nonnull final TestSpecification testSpecification) {
        final String missingTestSoleBucketName = "inactive";
        final String missingTestSoleBucketDescription = "inactive";
        final Allocation allocation = new Allocation();
        allocation.setRanges(ImmutableList.of(new Range(testSpecification.getFallbackValue(), 1.0)));

        return new ConsumableTestDefinition(
                "default",
                null,
                TestType.RANDOM,
View Full Code Here

        for (final TestBucket bucket : buckets) {
            definedBuckets.add(bucket.getValue());
        }

        for(int i = 0; i < allocations.size(); i++ ) {
            final Allocation allocation = allocations.get(i);
            final List<Range> ranges = allocation.getRanges();
            //  ensure that each range refers to a known bucket
            double bucketTotal = 0;
            for (final Range range : ranges) {
                bucketTotal += range.getLength();
                // Internally consistent (within matrix itself)
                if (!definedBuckets.contains(range.getBucketValue())) {
                    throw new IncompatibleTestMatrixException("Allocation range in " + testName + " from " + matrixSource + " refers to unknown bucket value " + range.getBucketValue());
                }
            }
            //  I hate floating points.  TODO: extract a required precision constant/parameter?
            if (bucketTotal < 0.9999 || bucketTotal > 1.0001) { //  compensate for FP imprecision.  TODO: determine what these bounds really should be by testing stuff
                final StringBuilder sb = new StringBuilder(testName + " range with rule " + allocation.getRule() + " does not add up to 1 : ").append(ranges.get(0).getLength());
                for (int r = 1; r < ranges.size(); r++) {
                    sb.append(" + ").append(ranges.get(r).getLength());
                }
                sb.append(" = ").append(bucketTotal);
                throw new IncompatibleTestMatrixException(sb.toString());
            }
            final String rule = allocation.getRule();
            final boolean lastAllocation = i == allocations.size() - 1;
            final String bareRule = removeElExpressionBraces(rule);
            if(lastAllocation) {
                if (!isEmptyWhitespace(bareRule)) {
                    throw new IncompatibleTestMatrixException("Allocation[" + i + "] for test " + testName + " from " + matrixSource + " has non-empty rule: " + allocation.getRule());
                }
            } else {
                if (isEmptyWhitespace(bareRule)) {
                    throw new IncompatibleTestMatrixException("Allocation[" + i + "] for test " + testName + " from " + matrixSource + " has empty rule: " + allocation.getRule());
                }
            }
            //verify allocation rules are valid EL
            if(!isEmptyWhitespace(bareRule)){
                try {
View Full Code Here

        final List<TestBucket> abcBuckets = Lists.newArrayList(abcBucket0);
        final Map<String, Object> abcTestConstants = Maps.newHashMap();
        abcTestConstants.put("ANOTHER_NUM", Integer.valueOf(5));
        abcTestConstants.put("SOME_NUM", Integer.valueOf(1));

        final List<Allocation> abcAllocations = Collections.singletonList(new Allocation(null, Arrays.asList(new Range[] { new Range(abcBucket0.getValue(), 1) })));

        /**
final int id, final int version, final String rule, final TestType testType, final String salt, final List<TestBucket> buckets, final List<RuleRatio> ratios,
final Map<String, Object> constants, final String description) {

         */
        final ConsumableTestDefinition abcTD = new ConsumableTestDefinition("1", "${num > SOME_NUM && num < ANOTHER_NUM}", TestType.ANONYMOUS_USER, "abcsalt", abcBuckets, abcAllocations, abcTestConstants, "zingle boppity zip zop");

        final TestBucket defBucket0 = new TestBucket("control", 0, "control description", null);
        final TestBucket defBucket1 = new TestBucket("test1", 1, "test1 description", null);
        final TestBucket defBucket2 = new TestBucket("test2", 2, "test2 description", null);
        final List<TestBucket> defBuckets = Lists.newArrayList(defBucket0, defBucket1, defBucket2);
        final Map<String, Object> defTestConstants = Maps.newHashMap();
        defTestConstants.put("T", Boolean.TRUE);
        defTestConstants.put("COUNTRIES", Sets.newHashSet("AE", "IO", "UY"));
        final List<Allocation> defAllocations = Collections.singletonList(new Allocation(null, Arrays.asList(new Range[] {
                new Range(defBucket0.getValue(), 1/3f),
                new Range(defBucket1.getValue(), 1/3f),
                new Range(defBucket2.getValue(), 1/3f),
        })));
        final ConsumableTestDefinition defTD = new ConsumableTestDefinition("2", "${proctor:contains(COUNTRIES, country) && T}", TestType.ANONYMOUS_USER, "defsalt", defBuckets, defAllocations, defTestConstants, "finkle fangle foop");

        final TestBucket ghiBucket0 = new TestBucket("inactive", -1, "inactive description", null);
        final TestBucket ghiBucket1 = new TestBucket("control", 0, "control desc", null);
        final TestBucket ghiBucket2 = new TestBucket("optionA", 1, "option A desc", null);
        final TestBucket ghiBucket3 = new TestBucket("optionB", 2, "option B desc", null);
        final TestBucket ghiBucket4 = new TestBucket("optionC", 3, "option C desc", null);
        final List<TestBucket> ghiBuckets = Lists.newArrayList(ghiBucket0, ghiBucket1, ghiBucket2, ghiBucket3, ghiBucket4);
        final Map<String, Object> ghiTestConstants = Maps.newHashMap();
        ghiTestConstants.put("LANGUAGES", Sets.newHashSet("es", "fr", "pt", "nl"));
        ghiTestConstants.put("COUNTRIES", Sets.newHashSet("AE", "IO", "UY"));
        final List<Allocation> ghiAllocations = Collections.singletonList(new Allocation(null,
                Arrays.asList(new Range[] {
                        new Range(ghiBucket0.getValue(), 0.2),
                        new Range(ghiBucket1.getValue(), 0.2),
                        new Range(ghiBucket2.getValue(), 0.2),
                        new Range(ghiBucket3.getValue(), 0.2),
View Full Code Here

TOP

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

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.