Java Collection Random Element generateMetricsDataWithPartialWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime)

Here you can find the source of generateMetricsDataWithPartialWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime)

Description

generate Metrics Data With Partial Wrong Types

License

Apache License

Declaration

private static List<Map<String, Object>> generateMetricsDataWithPartialWrongTypes(String metricPostfix,
            boolean generateRandomTenant, long collectionTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

public class Main {
    private static final Random random = new Random();

    private static List<Map<String, Object>> generateMetricsDataWithPartialWrongTypes(String metricPostfix,
            boolean generateRandomTenant, long collectionTime) {

        List<Map<String, Object>> metricsList = generateMetricsDataWithAllWrongTypes(metricPostfix,
                generateRandomTenant, collectionTime);

        // add a few valid ones
        Map<String, Object> testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }//w  w  w  .jav a  2 s .c om
        testMetric.put("metricName", "mzord.small.numeric.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", 123);
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        // numeric metrics
        testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }
        testMetric.put("metricName", "mzord.another.numeric.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "ounces");
        testMetric.put("metricValue", 4525);
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        return metricsList;
    }

    public static List<Map<String, Object>> generateMetricsDataWithAllWrongTypes(String metricPostfix,
            boolean generateRandomTenant, long collectionTime) {

        List<Map<String, Object>> metricsList = new ArrayList<Map<String, Object>>();

        // String metric value
        Map<String, Object> testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }
        testMetric.put("metricName", "mzord.string.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", "random_string");
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        // String numeric metric value
        testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }
        testMetric.put("metricName", "mzord.string.numeric.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", "666");
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        // boolean metric value
        testMetric = new TreeMap<String, Object>();
        if (generateRandomTenant) {
            testMetric.put("tenantId", random.nextInt());
        }
        testMetric.put("metricName", "mzord.boolean.metric" + metricPostfix);
        testMetric.put("ttlInSeconds", 1234566);
        testMetric.put("unit", "milliseconds");
        testMetric.put("metricValue", true);
        testMetric.put("collectionTime", collectionTime);
        metricsList.add(testMetric);

        return metricsList;
    }
}

Related

  1. chooseElement(Collection elements, T alternative)
  2. chooseRandomThing(Collection possibleroutes)
  3. chooseWithoutCheck(Collection collection, long seed)
  4. generateMetricsDataWithAllWrongTypes(String metricPostfix, boolean generateRandomTenant, long collectionTime)
  5. getRandom(Collection collection)
  6. getRandomNumber(Collection collection, int number)
  7. nextItem(Collection items, Random random)
  8. oneOf(Collection array)