@Override
 public Iterator<List<String>> getGeneratorImpl(GeneratorFactory generatorFactory) {
   Tuple2<Double, String> p1 = Tuple.tuple2(1.0, "1");
   Tuple2<Double, String> p2 = Tuple.tuple2(1.0, "2");
   Tuple2<Double, String> p3 = Tuple.tuple2(1.0, "3");
   ArrayList<Tuple2<Double, String>> items = new ArrayList<Tuple2<Double, String>>();
   items.add(p1);
   items.add(p2);
   items.add(p3);
   Iterator<Integer> amountToRetrieveGenerator = generatorFactory.uniform(0, 3);
   Iterator<List<String>> generator =
       generatorFactory.weightedDiscreteList(items, amountToRetrieveGenerator);
   return generator;
 }
Example #2
0
  @Override
  public WorkloadStreams getStreams(GeneratorFactory gf, boolean hasDbConnected)
      throws WorkloadException {
    long workloadStartTimeAsMilli = 0;

    /**
     * **************************
     *
     * <p>Initial Insert Operation Generator
     *
     * <p>**************************
     */
    // Load Insert Keys
    MinMaxGenerator<Long> insertKeyGenerator = gf.minMaxGenerator(gf.incrementing(0l, 1l), 0l, 0l);

    // Insert Fields: Names & Values
    Iterator<Long> fieldValueLengthGenerator = gf.uniform(1l, 100l);
    Iterator<Iterator<Byte>> randomFieldValueGenerator =
        gf.sizedUniformBytesGenerator(fieldValueLengthGenerator);
    List<Tuple3<Double, String, Iterator<Iterator<Byte>>>> valuedFields = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_FIELDS_IN_RECORD; i++) {
      valuedFields.add(Tuple.tuple3(1d, FIELD_NAME_PREFIX + i, randomFieldValueGenerator));
    }
    Iterator<Map<String, Iterator<Byte>>> insertValuedFieldGenerator =
        gf.weightedDiscreteMap(valuedFields, NUMBER_OF_FIELDS_IN_RECORD);

    Iterator<Operation> initialInsertOperationGenerator =
        gf.limit(
            new InsertOperationGenerator(
                TABLE, gf.prefix(insertKeyGenerator, KEY_NAME_PREFIX), insertValuedFieldGenerator),
            INITIAL_INSERT_COUNT);

    /**
     * **************************
     *
     * <p>Insert Operation Generator
     *
     * <p>**************************
     */
    // Transaction Insert Keys
    InsertOperationGenerator transactionalInsertOperationGenerator =
        new InsertOperationGenerator(
            TABLE, gf.prefix(insertKeyGenerator, KEY_NAME_PREFIX), insertValuedFieldGenerator);

    /**
     * **************************
     *
     * <p>Read Operation Generator
     *
     * <p>**************************
     */
    // Read/Update Keys
    Iterator<String> requestKeyGenerator =
        gf.prefix(gf.dynamicRangeUniform(insertKeyGenerator), KEY_NAME_PREFIX);

    // Read Fields: Names
    List<Tuple2<Double, String>> fields = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_FIELDS_IN_RECORD; i++) {
      fields.add(Tuple.tuple2(1d, FIELD_NAME_PREFIX + i));
    }

    Iterator<List<String>> readFieldsGenerator =
        gf.weightedDiscreteList(fields, NUMBER_OF_FIELDS_TO_READ);

    ReadOperationGenerator readOperationGenerator =
        new ReadOperationGenerator(TABLE, requestKeyGenerator, readFieldsGenerator);

    /**
     * **************************
     *
     * <p>Update Operation Generator
     *
     * <p>**************************
     */
    // Update Fields: Names & Values
    Iterator<Map<String, Iterator<Byte>>> updateValuedFieldsGenerator =
        gf.weightedDiscreteMap(valuedFields, NUMBER_OF_FIELDS_TO_UPDATE);

    UpdateOperationGenerator updateOperationGenerator =
        new UpdateOperationGenerator(TABLE, requestKeyGenerator, updateValuedFieldsGenerator);

    /**
     * **************************
     *
     * <p>Scan Operation Generator
     *
     * <p>**************************
     */
    // Scan Fields: Names & Values
    Iterator<List<String>> scanFieldsGenerator =
        gf.weightedDiscreteList(fields, NUMBER_OF_FIELDS_TO_READ);

    // Scan Length: Number of Records
    Iterator<Integer> scanLengthGenerator = gf.uniform(MIN_SCAN_LENGTH, MAX_SCAN_LENGTH);

    ScanOperationGenerator scanOperationGenerator =
        new ScanOperationGenerator(
            TABLE, requestKeyGenerator, scanLengthGenerator, scanFieldsGenerator);

    /**
     * **************************
     *
     * <p>ReadModifyWrite Operation Generator
     *
     * <p>**************************
     */
    ReadModifyWriteOperationGenerator readModifyWriteOperationGenerator =
        new ReadModifyWriteOperationGenerator(
            TABLE, requestKeyGenerator, readFieldsGenerator, updateValuedFieldsGenerator);

    /**
     * **************************
     *
     * <p>Transactional Workload Operations
     *
     * <p>**************************
     */
    // proportion of transactions reads/update/insert/scan/read-modify-write
    List<Tuple2<Double, Iterator<Operation>>> operations = new ArrayList<>();
    operations.add(Tuple.tuple2(READ_RATIO, (Iterator<Operation>) readOperationGenerator));
    operations.add(Tuple.tuple2(UPDATE_RATIO, (Iterator<Operation>) updateOperationGenerator));
    operations.add(
        Tuple.tuple2(INSERT_RATIO, (Iterator<Operation>) transactionalInsertOperationGenerator));
    operations.add(Tuple.tuple2(SCAN_RATIO, (Iterator<Operation>) scanOperationGenerator));
    operations.add(
        Tuple.tuple2(
            READ_MODIFY_WRITE_RATIO, (Iterator<Operation>) readModifyWriteOperationGenerator));

    Iterator<Operation> transactionalOperationGenerator =
        gf.weightedDiscreteDereferencing(operations);

    // iterates initialInsertOperationGenerator before starting with
    // transactionalInsertOperationGenerator
    Iterator<Operation> workloadOperations =
        Iterators.concat(initialInsertOperationGenerator, transactionalOperationGenerator);

    Iterator<Long> startTimesAsMilli = gf.incrementing(workloadStartTimeAsMilli + 1, 100l);
    Iterator<Long> dependencyTimesAsMilli = gf.constant(workloadStartTimeAsMilli);

    WorkloadStreams workloadStreams = new WorkloadStreams();
    workloadStreams.setAsynchronousStream(
        Sets.<Class<? extends Operation>>newHashSet(),
        Sets.<Class<? extends Operation>>newHashSet(),
        Collections.<Operation>emptyIterator(),
        gf.assignDependencyTimes(
            dependencyTimesAsMilli, gf.assignStartTimes(startTimesAsMilli, workloadOperations)),
        null);
    return workloadStreams;
  }