<commit_before>package io.rainfall.ehcache;

import io.rainfall.ObjectGenerator;
import io.rainfall.Runner;
import io.rainfall.Scenario;
import io.rainfall.SyntaxException;
import io.rainfall.configuration.ConcurrencyConfig;
import io.rainfall.configuration.DistributedConfig;
import io.rainfall.configuration.ReportingConfig;
import io.rainfall.ehcache.statistics.EhcacheResult;
import io.rainfall.ehcache2.CacheConfig;
import io.rainfall.ehcache2.execution.UntilCacheFull;
import io.rainfall.generator.ByteArrayGenerator;
import io.rainfall.generator.StringGenerator;
import io.rainfall.generator.sequence.Distribution;
import io.rainfall.statistics.StatisticsPeekHolder;
import io.rainfall.utils.SystemTest;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.MemoryUnit;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import static io.rainfall.configuration.DistributedConfig.address;
import static io.rainfall.configuration.ReportingConfig.html;
import static io.rainfall.configuration.ReportingConfig.text;
import static io.rainfall.ehcache2.Ehcache2Operations.get;
import static io.rainfall.ehcache2.Ehcache2Operations.put;
import static io.rainfall.execution.Executions.during;
import static io.rainfall.execution.Executions.times;
import static io.rainfall.unit.TimeDivision.minutes;
import static io.rainfall.unit.TimeDivision.seconds;
import static java.util.concurrent.TimeUnit.MINUTES;

/**
 * @author <NAME>
 */
@Category(SystemTest.class)
public class PerfTest2 {

  @Test
  @Ignore
  public void testDistributedLoad() throws SyntaxException {

    CacheManager cacheManager = null;
    try {
      Configuration configuration = new Configuration().name("EhcacheTest")
          .defaultCache(new CacheConfiguration("default", 0).eternal(true))
          .cache(new CacheConfiguration().name("one")
              .maxBytesLocalHeap(100, MemoryUnit.MEGABYTES));
      cacheManager = CacheManager.create(configuration);

      Ehcache one = cacheManager.getEhcache("one");

      ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig()
          .threads(4).timeout(50, MINUTES);

      int nbElements = 250000;
      ObjectGenerator<String> keyGenerator = StringGenerator.fixedLength(10);
      ObjectGenerator<byte[]> valueGenerator = ByteArrayGenerator.fixedLength(1000);

      Runner.setUp(
          Scenario.scenario("warmup phase").exec(
              put(String.class, byte[].class).using(keyGenerator, valueGenerator).sequentially()
          ))
          .executed(times(nbElements))
          .config(concurrency, ReportingConfig.report(EhcacheResult.class).log(text()))
          .config(CacheConfig.<String, byte[]>cacheConfig().caches(one))
          .start();

      StatisticsPeekHolder finalStats = Runner.setUp(
          Scenario.scenario("Test phase").exec(
              put(String.class, byte[].class).withWeight(0.20)
                  .atRandom(Distribution.GAUSSIAN, 0, nbElements, 10000)
                  .using(keyGenerator, valueGenerator),
              get(String.class, byte[].class).withWeight(0.80)
                  .atRandom(Distribution.GAUSSIAN, 0, nbElements, 10000)
                  .using(keyGenerator, valueGenerator)
          ))
          .executed(during(20, seconds))
          .config(concurrency, ReportingConfig.report(EhcacheResult.class).log(text(), html()))
          .config(CacheConfig.<String, byte[]>cacheConfig().caches(one))
          .config(DistributedConfig.distributedConfig().master(address("localhost", 9911), 2))
          .start();

    } finally {
      if (cacheManager != null) {
        cacheManager.shutdown();
      }
    }
  }

  @Test
  @Ignore
  public void testLoad() throws SyntaxException {

    CacheManager cacheManager = null;
    try {
      Configuration configuration = new Configuration().name("EhcacheTest")
          .defaultCache(new CacheConfiguration("default", 0).eternal(true))
          .cache(new CacheConfiguration().name("one")
              .maxBytesLocalHeap(100, MemoryUnit.MEGABYTES)
              .maxBytesLocalOffHeap(200, MemoryUnit.MEGABYTES))<commit_msg>changed distributed config api<commit_after>package io.rainfall.ehcache;

import io.rainfall.ObjectGenerator;
import io.rainfall.Runner;
import io.rainfall.Scenario;
import io.rainfall.SyntaxException;
import io.rainfall.configuration.ConcurrencyConfig;
import io.rainfall.configuration.DistributedConfig;
import io.rainfall.configuration.ReportingConfig;
import io.rainfall.ehcache.statistics.EhcacheResult;
import io.rainfall.ehcache2.CacheConfig;
import io.rainfall.ehcache2.execution.UntilCacheFull;
import io.rainfall.generator.ByteArrayGenerator;
import io.rainfall.generator.StringGenerator;
import io.rainfall.generator.sequence.Distribution;
import io.rainfall.statistics.StatisticsPeekHolder;
import io.rainfall.utils.SystemTest;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.MemoryUnit;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import static io.rainfall.configuration.DistributedConfig.address;
import static io.rainfall.configuration.ReportingConfig.html;
import static io.rainfall.configuration.ReportingConfig.text;
import static io.rainfall.ehcache2.Ehcache2Operations.get;
import static io.rainfall.ehcache2.Ehcache2Operations.put;
import static io.rainfall.execution.Executions.during;
import static io.rainfall.execution.Executions.times;
import static io.rainfall.unit.TimeDivision.minutes;
import static io.rainfall.unit.TimeDivision.seconds;
import static java.util.concurrent.TimeUnit.MINUTES;

/**
 * @author <NAME>
 */
@Category(SystemTest.class)
public class PerfTest2 {

  @Test
  @Ignore
  public void testDistributedLoad() throws SyntaxException {

    CacheManager cacheManager = null;
    try {
      Configuration configuration = new Configuration().name("EhcacheTest")
          .defaultCache(new CacheConfiguration("default", 0).eternal(true))
          .cache(new CacheConfiguration().name("one")
              .maxBytesLocalHeap(100, MemoryUnit.MEGABYTES));
      cacheManager = CacheManager.create(configuration);

      Ehcache one = cacheManager.getEhcache("one");

      ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig()
          .threads(4).timeout(50, MINUTES);

      int nbElements = 250000;
      ObjectGenerator<String> keyGenerator = StringGenerator.fixedLength(10);
      ObjectGenerator<byte[]> valueGenerator = ByteArrayGenerator.fixedLength(1000);

      Runner.setUp(
          Scenario.scenario("warmup phase").exec(
              put(String.class, byte[].class).using(keyGenerator, valueGenerator).sequentially()
          ))
          .executed(times(nbElements))
          .config(DistributedConfig.distributedConfig(address("localhost", 9911), 2))
          .config(concurrency, ReportingConfig.report(EhcacheResult.class).log(text()))
          .config(CacheConfig.<String, byte[]>cacheConfig().caches(one))
          .start();

      StatisticsPeekHolder finalStats = Runner.setUp(
          Scenario.scenario("Test phase").exec(
              put(String.class, byte[].class).withWeight(0.20)
                  .atRandom(Distribution.GAUSSIAN, 0, nbElements, 10000)
                  .using(keyGenerator, valueGenerator),
              get(String.class, byte[].class).withWeight(0.80)
                  .atRandom(Distribution.GAUSSIAN, 0, nbElements, 10000)
                  .using(keyGenerator, valueGenerator)
          ))
          .executed(during(20, seconds))
          .config(concurrency, ReportingConfig.report(EhcacheResult.class).log(text(), html()))
          .config(CacheConfig.<String, byte[]>cacheConfig().caches(one))
          .config(DistributedConfig.distributedConfig(address("localhost", 9911), 2))
          .start();

    } finally {
      if (cacheManager != null) {
        cacheManager.shutdown();
      }
    }
  }

  @Test
  @Ignore
  public void testLoad() throws SyntaxException {

    CacheManager cacheManager = null;
    try {
      Configuration configuration = new Configuration().name("EhcacheTest")
          .defaultCache(new CacheConfiguration("default", 0).eternal(true))
          .cache(new CacheConfiguration().name("one")
              .maxBytesLocalHeap(100, MemoryUnit.MEGABYTES)
              .maxBytesLocalOffHeap(200, MemoryUnit.MEGABYTES))
{'fraction_non_alphanumeric': 0.11248554913294798, 'fraction_numerical': 0.013988439306358381, 'mean_word_length': 3.8765501691093576, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2883722', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2394, 'n_words': 401}