All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rainfall.cassandra.operations.InsertOperation Maven / Gradle / Ivy

There is a newer version: 1.6.10
Show newest version
/*
 * Copyright 2014 Aurélien Broszniowski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.rainfall.cassandra.operations;

import io.rainfall.AssertionEvaluator;
import io.rainfall.Configuration;
import io.rainfall.ObjectGenerator;
import io.rainfall.Operation;
import io.rainfall.SequenceGenerator;
import io.rainfall.statistics.StatisticsHolder;

import com.datastax.driver.mapping.Mapper;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static io.rainfall.cassandra.statistics.CassandraResult.SAVE;

/**
 * @author Aurelien Broszniowski
 */

public class InsertOperation implements Operation {
  private final ObjectGenerator valueGenerator;
  private final SequenceGenerator sequenceGenerator;
  private final Mapper mapper;
  private final String name;

  public InsertOperation(final ObjectGenerator valueGenerator,
                         final SequenceGenerator sequenceGenerator, final Mapper mapper) {
    this.valueGenerator = valueGenerator;
    this.sequenceGenerator = sequenceGenerator;
    this.mapper = mapper;
    this.name = this.valueGenerator.generate(1L).getClass().getName();
  }

  @Override
  public void exec(final StatisticsHolder statisticsHolder, final Map, Configuration> configurations,
                   final List assertions) {
    long seed = sequenceGenerator.next();
    V value = valueGenerator.generate(seed);
    long start = statisticsHolder.getTimeInNs();
    mapper.save(value);
    long end = statisticsHolder.getTimeInNs();
    statisticsHolder.record(this.name, (end - start), SAVE);
  }

  @Override
  public List getDescription() {
    return Arrays.asList("Save operation", "Entity = " + this.name);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy