当前位置: 首页>>代码示例>>Java>>正文


Java TestBucket.getPayload方法代码示例

本文整理汇总了Java中com.indeed.proctor.common.model.TestBucket.getPayload方法的典型用法代码示例。如果您正苦于以下问题:Java TestBucket.getPayload方法的具体用法?Java TestBucket.getPayload怎么用?Java TestBucket.getPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.indeed.proctor.common.model.TestBucket的用法示例。


在下文中一共展示了TestBucket.getPayload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPayload

import com.indeed.proctor.common.model.TestBucket; //导入方法依赖的package包/类
/**
 * Return the Payload attached to the current active bucket for |test|.
 * Always returns a payload so the client doesn't crash on a malformed
 * test definition.
 *
 * @param testName test name
 * @return pay load attached to the current active bucket
 * @deprecated Use {@link #getPayload(String, Bucket)} instead
 */
@Nonnull
protected Payload getPayload(final String testName) {
    // Get the current bucket.
    final TestBucket testBucket = buckets.get(testName);

    // Lookup Payloads for this test
    if (testBucket != null) {
        final Payload payload = testBucket.getPayload();
        if (null != payload) {
            return payload;
        }
    }

    return Payload.EMPTY_PAYLOAD;
}
 
开发者ID:indeedeng,项目名称:proctor,代码行数:25,代码来源:AbstractGroups.java

示例2: getJavaScriptConfig

import com.indeed.proctor.common.model.TestBucket; //导入方法依赖的package包/类
/**
 * Generates a list of [bucketValue, payloadValue]'s for each test defined in the client app's proctor spec.
 *
 * To be used with generated javascript files from 'ant generate-proctor-js' by serializing the list
 * to a string and passing it to {packageName}.init();
 *
 * @param tests an alphabetical list of Test enums from your generated proctor java subclass of {@link com.indeed.proctor.consumer.AbstractGroups}.
 * @param <E> Generic Type of Test
 * @return a list of 2-element lists that hold the bucketValue and payloadValue for each test in alphabetical order
 */
public <E extends Test> List<List<Object>> getJavaScriptConfig(final E[] tests) {
    final Map<String, TestBucket> buckets = getProctorResult().getBuckets();
    final List<List<Object>> groups = new ArrayList<List<Object>>(tests.length);
    for (final E test : tests) {
        final String testName = test.getName();
        final Integer bucketValue = getValue(testName, test.getFallbackValue());
        final Object payloadValue;
        final TestBucket testBucket = buckets.get(testName);
        if (testBucket != null && testBucket.getPayload() != null) {
            final Payload payload = testBucket.getPayload();
            payloadValue = payload.fetchAValue();
        } else {
            payloadValue = null;
        }
        final List<Object> definition = new ArrayList<Object>();
        definition.add(bucketValue);
        definition.add(payloadValue);
        groups.add(definition);
    }
    return groups;
}
 
开发者ID:indeedeng,项目名称:proctor,代码行数:32,代码来源:AbstractGroups.java

示例3: JsonTestBucket

import com.indeed.proctor.common.model.TestBucket; //导入方法依赖的package包/类
/**
 * Serializes the object using an existing bucket and a separate version.
 *
 * Version needs to be obtained outside of the bucket through ProctorResult.getTestVersions()
 */
public JsonTestBucket(final TestBucket bucket, final String version) {
    name = bucket.getName();
    value = bucket.getValue();
    this.version = version;

    // This means the JSON output will have type names like "stringValue" and "doubleArray".
    // It makes the API look less clean, especially for clients that use duck-typed languages.
    // But it may make deserialization easier for clients with rigid types, especially if they use something like
    // Jackson's data binding in Java.
    // This is also consistent with the test matrix definition.
    payload = bucket.getPayload();
}
 
开发者ID:indeedeng,项目名称:proctor-pipet,代码行数:18,代码来源:JsonTestBucket.java

示例4: generateSpecification

import com.indeed.proctor.common.model.TestBucket; //导入方法依赖的package包/类
/**
 * Generates a usable test specification for a given test definition
 * Uses the first bucket as the fallback value
 *
 * @param testDefinition a {@link TestDefinition}
 * @return a {@link TestSpecification} which corresponding to given test definition.
 */
public static TestSpecification generateSpecification(@Nonnull final TestDefinition testDefinition) {
    final TestSpecification testSpecification = new TestSpecification();
    // Sort buckets by value ascending
    final Map<String,Integer> buckets = Maps.newLinkedHashMap();
    final List<TestBucket> testDefinitionBuckets = Ordering.from(new Comparator<TestBucket>() {
        @Override
        public int compare(final TestBucket lhs, final TestBucket rhs) {
            return Ints.compare(lhs.getValue(), rhs.getValue());
        }
    }).immutableSortedCopy(testDefinition.getBuckets());
    int fallbackValue = -1;
    if(testDefinitionBuckets.size() > 0) {
        final TestBucket firstBucket = testDefinitionBuckets.get(0);
        fallbackValue = firstBucket.getValue(); // buckets are sorted, choose smallest value as the fallback value

        final PayloadSpecification payloadSpecification = new PayloadSpecification();
        if(firstBucket.getPayload() != null && !firstBucket.getPayload().equals(Payload.EMPTY_PAYLOAD)) {
            final PayloadType payloadType = PayloadType.payloadTypeForName(firstBucket.getPayload().fetchType());
            payloadSpecification.setType(payloadType.payloadTypeName);
            if (payloadType == PayloadType.MAP) {
                final Map<String, String> payloadSpecificationSchema = new HashMap<String, String>();
                for (Map.Entry<String, Object> entry : firstBucket.getPayload().getMap().entrySet()) {
                    payloadSpecificationSchema.put(entry.getKey(), PayloadType.payloadTypeForValue(entry.getValue()).payloadTypeName);
                }
                payloadSpecification.setSchema(payloadSpecificationSchema);
            }
            testSpecification.setPayload(payloadSpecification);
        }

        for (int i = 0; i < testDefinitionBuckets.size(); i++) {
            final TestBucket bucket = testDefinitionBuckets.get(i);
            buckets.put(bucket.getName(), bucket.getValue());
        }
    }
    testSpecification.setBuckets(buckets);
    testSpecification.setDescription(testDefinition.getDescription());
    testSpecification.setFallbackValue(fallbackValue);
    return testSpecification;
}
 
开发者ID:indeedeng,项目名称:proctor,代码行数:47,代码来源:ProctorUtils.java

示例5: isAllocationOnlyChange

import com.indeed.proctor.common.model.TestBucket; //导入方法依赖的package包/类
public static boolean isAllocationOnlyChange(final TestDefinition existingTestDefinition, final TestDefinition testDefinitionToUpdate) {
     final List<Allocation> existingAllocations = existingTestDefinition.getAllocations();
     final List<Allocation> allocationsToUpdate = testDefinitionToUpdate.getAllocations();
     final boolean nullRule = existingTestDefinition.getRule() == null;
     if (nullRule && testDefinitionToUpdate.getRule() != null) {
         return false;
     } else if (!nullRule && !existingTestDefinition.getRule().equals(testDefinitionToUpdate.getRule())) {
         return false;
     }
     if (!existingTestDefinition.getConstants().equals(testDefinitionToUpdate.getConstants())
        || !existingTestDefinition.getSpecialConstants().equals(testDefinitionToUpdate.getSpecialConstants())
        || !existingTestDefinition.getTestType().equals(testDefinitionToUpdate.getTestType())
        || !existingTestDefinition.getSalt().equals(testDefinitionToUpdate.getSalt())
        || !existingTestDefinition.getBuckets().equals(testDefinitionToUpdate.getBuckets())
        || existingAllocations.size()!=allocationsToUpdate.size())
        return false;

    /*
     * TestBucket .equals() override only checks name equality
     * loop below compares each attribute of a TestBucket
     */
    for (int i = 0; i<existingTestDefinition.getBuckets().size(); i++) {
        final TestBucket bucketOne = existingTestDefinition.getBuckets().get(i);
        final TestBucket bucketTwo = testDefinitionToUpdate.getBuckets().get(i);
        if (bucketOne == null) {
            if (bucketTwo != null) {
                return false;
            }
        } else if (bucketTwo == null) {
            return false;
        } else {
            if (bucketOne.getValue() != bucketTwo.getValue()) {
                return false;
            }
            final Payload payloadOne = bucketOne.getPayload();
            final Payload payloadTwo = bucketTwo.getPayload();
            if (payloadOne == null) {
                if (payloadTwo != null) {
                    return false;
                }
            } else if (!payloadOne.equals(payloadTwo)) {
                return false;
            }
            if (bucketOne.getDescription() == null) {
                if (bucketTwo.getDescription() != null) {
                    return false;
                }
            } else if (!bucketOne.getDescription().equals(bucketTwo.getDescription())) {
                return false;
            }
        }
    }

    /*
     * Comparing everything in an allocation except the lengths
     */
    for (int i = 0; i<existingAllocations.size(); i++) {
        final List<Range> existingAllocationRanges = existingAllocations.get(i).getRanges();
        final List<Range> allocationToUpdateRanges = allocationsToUpdate.get(i).getRanges();
        if (existingAllocations.get(i).getRule() == null && allocationsToUpdate.get(i).getRule() != null)
            return false;
        else if (existingAllocations.get(i).getRule() != null && !existingAllocations.get(i).getRule().equals(allocationsToUpdate.get(i).getRule()))
            return false;
        Map<Integer, Double> existingAllocRangeMap = generateAllocationRangeMap(existingAllocationRanges);
        Map<Integer, Double> allocToUpdateRangeMap = generateAllocationRangeMap(allocationToUpdateRanges);
        if (!existingAllocRangeMap.keySet().equals(allocToUpdateRangeMap.keySet())) {
            //An allocation was removed or added, do not autopromote
            return false;
        } else {
            for (Map.Entry<Integer, Double> entry : existingAllocRangeMap.entrySet()) {
                final int bucketVal = entry.getKey();
                final double existingLength = entry.getValue();
                final double allocToUpdateLength = allocToUpdateRangeMap.get(bucketVal);
                if (existingLength == 0 && allocToUpdateLength != 0) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
开发者ID:indeedeng,项目名称:proctor-webapp-library,代码行数:82,代码来源:ProctorTestDefinitionController.java

示例6: consolidate

import com.indeed.proctor.common.model.TestBucket; //导入方法依赖的package包/类
private static void consolidate(@Nonnull final TestMatrixArtifact testMatrix, @Nonnull final Map<String, TestSpecification> requiredTests) {
    final Map<String, ConsumableTestDefinition> definedTests = testMatrix.getTests();

    // Sets.difference returns a "view" on the original set, which would require concurrent modification while iterating (copying the set will prevent this)
    final Set<String> toRemove = ImmutableSet.copyOf(Sets.difference(definedTests.keySet(), requiredTests.keySet()));
    for (String testInMatrixNotRequired : toRemove) {
        //  we don't care about this test
        definedTests.remove(testInMatrixNotRequired);
    }

    // Next, for any required tests that are missing, ensure that
    //  there is a nonnull test definition in the matrix
    final Set<String> missing =
            ImmutableSet.copyOf(Sets.difference(requiredTests.keySet(), definedTests.keySet()));
    for (String testNotInMatrix: missing) {
        definedTests.put(testNotInMatrix, defaultFor(testNotInMatrix, requiredTests.get(testNotInMatrix)));
    }

    // Now go through definedTests: for each test, if the test spec
    // didn't ask for a payload, then remove any payload that is in
    // the test matrix.  If buckets exist in the specification that
    // do not in the matrix, add buckets with null payloads to allow
    // forcing buckets that aren't in the matrix but are in the spec.
    for (Entry<String, ConsumableTestDefinition> next : definedTests.entrySet()) {
        final String testName = next.getKey();
        final ConsumableTestDefinition testDefinition = next.getValue();
        final TestSpecification testSpec = requiredTests.get(testName);

        final boolean noPayloads = (testSpec.getPayload() == null);
        final Set<Integer> bucketValues = Sets.newHashSet();
        List<TestBucket> buckets = testDefinition.getBuckets();
        for (final TestBucket bucket : buckets) {
            // Note bucket values that exist in matrix.
            bucketValues.add(bucket.getValue());
            if (noPayloads && (bucket.getPayload() != null)) {
                // stomp the unexpected payloads.
                bucket.setPayload(null);
            }
        }

        boolean replaceBuckets = false;
        final Map<String, Integer> specBuckets = testSpec.getBuckets();
        for (final Entry<String, Integer> bucketSpec : specBuckets.entrySet()) {
            if (!bucketValues.contains(bucketSpec.getValue())) {
                if (!replaceBuckets) {
                    buckets = Lists.newArrayList(buckets);
                    replaceBuckets = true;
                }
                buckets.add(new TestBucket(bucketSpec.getKey(), bucketSpec.getValue(), null, null));
            }
        }

        if (replaceBuckets) {
            testDefinition.setBuckets(buckets);
        }
    }
}
 
开发者ID:indeedeng,项目名称:proctor,代码行数:58,代码来源:ProctorUtils.java


注:本文中的com.indeed.proctor.common.model.TestBucket.getPayload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。