Search in sources :

Example 11 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class LoadBalancerStrategyPropertiesConverterTest method testLoadBalancerStrategyPropertiesConverter.

@Test
public void testLoadBalancerStrategyPropertiesConverter() {
    final Double globalStepDown = 0.4;
    final Double globalStepUp = 0.3;
    final Double recoveryLevel = 1.0;
    final Double ringRampFactor = 0.01;
    final Double highWaterMark = 1000d;
    final Double lowWaterMark = 500d;
    final Integer pointsPerWeight = 100;
    final Long updateIntervalMs = 50000l;
    final Integer minCallCountHighWaterMark = 3000;
    final Integer minCallCountLowWaterMark = 1500;
    final hashMethodEnum hashMethod = hashMethodEnum.URI_REGEX;
    final hashConfigType hashConfig = new hashConfigType();
    final StringArray regexes = new StringArray();
    final Double hashringPointCleanupRate = 0.2;
    final ConsistentHashAlgorithmEnum consistentHashAlgorithm = ConsistentHashAlgorithmEnum.MULTI_PROBE;
    final Integer numProbes = 1024;
    final Double quarantineMaxPercent = 0.2;
    final String quarantineMethod = "OPTIONS:/test/path";
    final Long quarantineLatency = 200l;
    final quarantineInfo quarantineInfo = new quarantineInfo().setQuarantineMaxPercent(quarantineMaxPercent).setQuarantineMethod(quarantineMethod).setQuarantineLatency(quarantineLatency);
    final String errorStatusRegex = "(5..)";
    regexes.add("+231{w+)");
    hashConfig.setUriRegexes(regexes);
    hashConfig.setWarnOnNoMatch(false);
    hashConfig.setFailOnNoMatch(true);
    Map<String, Object> loadBalancerStrategyProperties = new HashMap<>();
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_GLOBAL_STEP_DOWN, globalStepDown.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_GLOBAL_STEP_UP, globalStepUp.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_INITIAL_RECOVERY_LEVEL, recoveryLevel.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR, ringRampFactor.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HIGH_WATER_MARK, highWaterMark.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_LOW_WATER_MARK, lowWaterMark.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_POINTS_PER_WEIGHT, pointsPerWeight.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, updateIntervalMs.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK, minCallCountHighWaterMark.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK, minCallCountLowWaterMark.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASH_METHOD, DegraderLoadBalancerStrategyV3.HASH_METHOD_URI_REGEX);
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASHRING_POINT_CLEANUP_RATE, hashringPointCleanupRate.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_ALGORITHM, DegraderRingFactory.MULTI_PROBE_CONSISTENT_HASH);
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_NUM_PROBES, numProbes.toString());
    Map<String, Object> hashConfigMap = new HashMap<>();
    hashConfigMap.put(URIRegexHash.KEY_REGEXES, regexes.stream().collect(Collectors.toList()));
    hashConfigMap.put(URIRegexHash.KEY_WARN_ON_NO_MATCH, "false");
    hashConfigMap.put(URIRegexHash.KEY_FAIL_ON_NO_MATCH, "true");
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASH_CONFIG, hashConfigMap);
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, quarantineMaxPercent.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_METHOD, quarantineMethod);
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_LATENCY, quarantineLatency.toString());
    loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX, errorStatusRegex);
    D2LoadBalancerStrategyProperties d2LoadBalancerStrategyProperties = new D2LoadBalancerStrategyProperties().setGlobalStepDown(globalStepDown).setGlobalStepUp(globalStepUp).setInitialRecoveryLevel(recoveryLevel).setRingRampFactor(ringRampFactor).setHighWaterMark(highWaterMark).setLowWaterMark(lowWaterMark).setPointsPerWeight(pointsPerWeight).setUpdateIntervalMs(updateIntervalMs).setMinCallCountHighWaterMark(minCallCountHighWaterMark).setMinCallCountLowWaterMark(minCallCountLowWaterMark).setHashMethod(hashMethod).setHashConfig(hashConfig).setHashRingPointCleanupRate(hashringPointCleanupRate).setConsistentHashAlgorithm(consistentHashAlgorithm).setNumberOfProbes(numProbes).setQuarantineCfg(quarantineInfo).setErrorStatusRegex(errorStatusRegex);
    Assert.assertEquals(LoadBalancerStrategyPropertiesConverter.toConfig(loadBalancerStrategyProperties), d2LoadBalancerStrategyProperties);
    Assert.assertEquals(LoadBalancerStrategyPropertiesConverter.toProperties(d2LoadBalancerStrategyProperties), loadBalancerStrategyProperties);
}
Also used : ConsistentHashAlgorithmEnum(com.linkedin.d2.ConsistentHashAlgorithmEnum) HashMap(java.util.HashMap) StringArray(com.linkedin.data.template.StringArray) com.linkedin.d2.quarantineInfo(com.linkedin.d2.quarantineInfo) com.linkedin.d2.hashMethodEnum(com.linkedin.d2.hashMethodEnum) D2LoadBalancerStrategyProperties(com.linkedin.d2.D2LoadBalancerStrategyProperties) com.linkedin.d2.hashConfigType(com.linkedin.d2.hashConfigType) Test(org.testng.annotations.Test)

Example 12 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class TransportClientPropertiesConverterTest method testTransportClientPropertiesConverter.

@Test
public void testTransportClientPropertiesConverter() {
    final Integer queryPostThreshold = 8192;
    final Long requestTimeout = 10000l;
    final Long maxResponseSize = 1003300l;
    final Integer poolSize = 200;
    final Integer poolWaiterSize = 32768;
    final Long idleTimeout = 600000l;
    final Long shutdownTimeout = 50000l;
    final List<String> responseCompressionRaw = Arrays.asList("finder:*");
    final List<String> responseContentEncoding = Arrays.asList("gzip", "snappy");
    final List<String> requestContentEncoding = Arrays.asList("lz4", "identity");
    final Boolean useResponseCompression = true;
    final Integer maxHeaderSize = 8192;
    final Integer maxChunkSize = 4096;
    final poolStrategyType poolStrategy = poolStrategyType.LRU;
    final Integer minPoolSize = 5;
    final Integer maxConcurrentConnections = 1000;
    final HttpProtocolVersionType protocolVersion = HttpProtocolVersionType.HTTP_1_1;
    final List<String> allowedClientOverrideKeys = Arrays.asList(PropertyKeys.HTTP_REQUEST_TIMEOUT, PropertyKeys.HTTP_QUERY_POST_THRESHOLD);
    Map<String, Object> transportClientProperties = new HashMap<>();
    transportClientProperties.put(PropertyKeys.HTTP_QUERY_POST_THRESHOLD, queryPostThreshold.toString());
    transportClientProperties.put(PropertyKeys.HTTP_REQUEST_TIMEOUT, requestTimeout.toString());
    transportClientProperties.put(PropertyKeys.HTTP_MAX_RESPONSE_SIZE, maxResponseSize.toString());
    transportClientProperties.put(PropertyKeys.HTTP_POOL_SIZE, poolSize.toString());
    transportClientProperties.put(PropertyKeys.HTTP_POOL_WAITER_SIZE, poolWaiterSize.toString());
    transportClientProperties.put(PropertyKeys.HTTP_IDLE_TIMEOUT, idleTimeout.toString());
    transportClientProperties.put(PropertyKeys.HTTP_SHUTDOWN_TIMEOUT, shutdownTimeout.toString());
    transportClientProperties.put(PropertyKeys.HTTP_RESPONSE_COMPRESSION_OPERATIONS, responseCompressionRaw.stream().collect(Collectors.joining(",")));
    transportClientProperties.put(PropertyKeys.HTTP_RESPONSE_CONTENT_ENCODINGS, responseContentEncoding.stream().collect(Collectors.joining(",")));
    transportClientProperties.put(PropertyKeys.HTTP_REQUEST_CONTENT_ENCODINGS, requestContentEncoding.stream().collect(Collectors.joining(",")));
    transportClientProperties.put(PropertyKeys.HTTP_USE_RESPONSE_COMPRESSION, useResponseCompression.toString());
    transportClientProperties.put(PropertyKeys.HTTP_MAX_HEADER_SIZE, maxHeaderSize.toString());
    transportClientProperties.put(PropertyKeys.HTTP_MAX_CHUNK_SIZE, maxChunkSize.toString());
    transportClientProperties.put(PropertyKeys.HTTP_POOL_STRATEGY, poolStrategy.name());
    transportClientProperties.put(PropertyKeys.HTTP_POOL_MIN_SIZE, minPoolSize.toString());
    transportClientProperties.put(PropertyKeys.HTTP_MAX_CONCURRENT_CONNECTIONS, maxConcurrentConnections.toString());
    transportClientProperties.put(PropertyKeys.HTTP_PROTOCOL_VERSION, protocolVersion.name());
    transportClientProperties.put(PropertyKeys.ALLOWED_CLIENT_OVERRIDE_KEYS, allowedClientOverrideKeys.stream().collect(Collectors.joining(",")));
    D2TransportClientProperties d2TransportClientProperties = new D2TransportClientProperties().setQueryPostThreshold(queryPostThreshold).setRequestTimeout(requestTimeout).setMaxResponseSize(maxResponseSize).setPoolSize(poolSize).setPoolWaiterSize(poolWaiterSize).setIdleTimeout(idleTimeout).setShutdownTimeout(shutdownTimeout).setResponseCompressionOperations(new StringArray(responseCompressionRaw)).setResponseContentEncodings(new StringArray(responseContentEncoding)).setRequestContentEncodings(new StringArray(requestContentEncoding)).setUseResponseCompression(useResponseCompression).setMaxHeaderSize(maxHeaderSize).setMaxChunkSize(maxChunkSize).setPoolStrategy(poolStrategy).setMinPoolSize(minPoolSize).setMaxConcurrentConnections(maxConcurrentConnections).setProtocolVersion(protocolVersion).setAllowedClientOverrideKeys(new StringArray(allowedClientOverrideKeys));
    Assert.assertEquals(TransportClientPropertiesConverter.toConfig(transportClientProperties), d2TransportClientProperties);
    Assert.assertEquals(TransportClientPropertiesConverter.toProperties(d2TransportClientProperties), transportClientProperties);
}
Also used : HttpProtocolVersionType(com.linkedin.d2.HttpProtocolVersionType) StringArray(com.linkedin.data.template.StringArray) HashMap(java.util.HashMap) com.linkedin.d2.poolStrategyType(com.linkedin.d2.poolStrategyType) D2TransportClientProperties(com.linkedin.d2.D2TransportClientProperties) Test(org.testng.annotations.Test)

Example 13 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class TestMap method testStringArrayMap.

@Test
public void testStringArrayMap() {
    TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new MapTest(), "stringArrayMap");
    @SuppressWarnings("unchecked") Class<StringArrayMap> templateClass = (Class<StringArrayMap>) fieldInfo.getFieldClass();
    MapDataSchema schema = (MapDataSchema) fieldInfo.getField().getType();
    Map<String, StringArray> input = new HashMap<String, StringArray>();
    for (int i = 0; i < 5; ++i) {
        String key = "input" + i;
        input.put(key, new StringArray());
        input.get(key).add("subinput" + i);
    }
    Map<String, StringArray> adds = new HashMap<String, StringArray>();
    for (int i = 0; i < 5; ++i) {
        String key = "add" + i;
        adds.put(key, new StringArray());
        adds.get(key).add("subadd" + i);
    }
    TestMapTemplate.testMap(templateClass, schema, input, adds);
}
Also used : TestDataTemplateUtil(com.linkedin.data.template.TestDataTemplateUtil) StringArrayMap(com.linkedin.data.template.StringArrayMap) HashMap(java.util.HashMap) MapDataSchema(com.linkedin.data.schema.MapDataSchema) StringArray(com.linkedin.data.template.StringArray) Test(org.testng.annotations.Test)

Example 14 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class ArrayGeneratorTest method testWithPrimitivesArray.

@Test
public void testWithPrimitivesArray() throws Throwable {
    String json = load("WithPrimitivesArray.json");
    WithPrimitivesArray original = new WithPrimitivesArray();
    IntegerArray ints = new IntegerArray();
    ints.add(1);
    ints.add(2);
    ints.add(3);
    original.setInts(ints);
    LongArray longs = new LongArray();
    longs.add(10L);
    longs.add(20L);
    longs.add(30L);
    original.setLongs(longs);
    FloatArray floats = new FloatArray();
    floats.add(1.1f);
    floats.add(2.2f);
    floats.add(3.3f);
    original.setFloats(floats);
    DoubleArray doubles = new DoubleArray();
    doubles.add(11.1d);
    doubles.add(22.2d);
    doubles.add(33.3d);
    original.setDoubles(doubles);
    BooleanArray booleans = new BooleanArray();
    booleans.add(false);
    booleans.add(true);
    original.setBooleans(booleans);
    StringArray strings = new StringArray();
    strings.add("a");
    strings.add("b");
    strings.add("c");
    original.setStrings(strings);
    BytesArray bytes = new BytesArray();
    bytes.add(SchemaFixtures.bytes1);
    bytes.add(SchemaFixtures.bytes2);
    original.setBytes(bytes);
    assertJson(original, json);
    WithPrimitivesArray roundTripped = new WithPrimitivesArray(roundTrip(original.data()));
    assertJson(roundTripped, json);
}
Also used : LongArray(com.linkedin.data.template.LongArray) BytesArray(com.linkedin.data.template.BytesArray) FloatArray(com.linkedin.data.template.FloatArray) StringArray(com.linkedin.data.template.StringArray) WithPrimitivesArray(com.linkedin.pegasus.generator.test.idl.arrays.WithPrimitivesArray) DoubleArray(com.linkedin.data.template.DoubleArray) IntegerArray(com.linkedin.data.template.IntegerArray) BooleanArray(com.linkedin.data.template.BooleanArray) Test(org.testng.annotations.Test)

Example 15 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class ResourceModelEncoder method appendSupportsNodeToCollectionSchema.

private void appendSupportsNodeToCollectionSchema(final CollectionSchema collectionSchema, final ResourceModel resourceModel) {
    StringArray supportsArray = buildSupportsNode(resourceModel);
    collectionSchema.setSupports(supportsArray);
}
Also used : StringArray(com.linkedin.data.template.StringArray)

Aggregations

StringArray (com.linkedin.data.template.StringArray)25 Test (org.testng.annotations.Test)12 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)5 HashMap (java.util.HashMap)5 DataMap (com.linkedin.data.DataMap)4 ArrayList (java.util.ArrayList)4 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)3 D2LoadBalancerStrategyProperties (com.linkedin.d2.D2LoadBalancerStrategyProperties)2 com.linkedin.d2.hashConfigType (com.linkedin.d2.hashConfigType)2 com.linkedin.d2.quarantineInfo (com.linkedin.d2.quarantineInfo)2 DataList (com.linkedin.data.DataList)2 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)2 DataSchema (com.linkedin.data.schema.DataSchema)2 MapDataSchema (com.linkedin.data.schema.MapDataSchema)2 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)2 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)2 BooleanArray (com.linkedin.data.template.BooleanArray)2 BytesArray (com.linkedin.data.template.BytesArray)2 DoubleArray (com.linkedin.data.template.DoubleArray)2 FloatArray (com.linkedin.data.template.FloatArray)2