<commit_before>/*
 * Copyright 2014 <NAME>. All Rights Reserved.
 *
 * 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 com.github.benmanes.caffeine.cache.testing;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.function.Supplier;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.RemovalListener;
import com.github.benmanes.caffeine.cache.testing.RemovalListeners.ConsumingRemovalListener;
import com.google.common.util.concurrent.MoreExecutors;

/**
 * The cache test specification so that a {@link org.testng.annotations.DataProvider} can construct
 * the maximum number of cache combinations to test against.
 *
 * @author <EMAIL> (<NAME>)
 */
@Target(METHOD) @Retention(RUNTIME)
public @interface CacheSpec {

  /* ---------------- Initial capacity -------------- */

  enum InitialCapacity {
    /** A flag indicating that the initial capacity is not configured. */
    DEFAULT(16),
    /** A configuration where the table grows on the first addition. */
    ZERO(0),
    /** A configuration where the table grows on the second addition. */
    ONE(1),
    /** A configuration where the table grows after the {@link Population#FULL} count. */
    FULL(100),
    /** A configuration where the table grows after the 10 x {@link Population#FULL} count. */
    EXCESSIVE(10 * 100);

    private final int size;

    private InitialCapacity(int size) {
      this.size = size;
    }

    public int size() {
      return size;
    }
  }

  /** The initial capacities, each resulting in a new combination. */
  InitialCapacity[] initialCapacity() default {
    InitialCapacity.DEFAULT,
    InitialCapacity.ZERO,
    InitialCapacity.ONE,
    InitialCapacity.FULL,
    InitialCapacity.EXCESSIVE
  };

  /* ---------------- Statistics -------------- */

  enum Stats { ENABLED, DISABLED }

  Stats[] stats() default {
    //Stats.ENABLED,
    Stats.DISABLED
  };

  /* ---------------- Maximum size -------------- */

  enum MaximumSize {
    /** A flag indicating that entries are not evicted due to a maximum size threshold. */
    DISABLED(Long.MAX_VALUE),
    /** A configuration where entries are evicted immediately. */
    ZERO(0L),
    /** A configuration that holds a single entry. */
    ONE(1L),
    /** A configuration that holds the {@link Population#FULL} count. */
    FULL(100L),
    /** A configuration where the threshold is too high for eviction to occur. */
    UNREACHABLE(Long.MAX_VALUE);

    private final long max;

    private MaximumSize(long max) {
      this.max = max;
    }

    public long max() {
      return max;
    }
  }

  /** The maximum size, each resulting in a new combination. */
  MaximumSize[] maximumSize() default {
    MaximumSize.DISABLED,
    // Disabled while BoundedLocalCache is unstable
    MaximumSize.UNREACHABLE
  };

  /* ---------------- Reference-based -------------- */

  /**
   * Whether to retain a strong reference copy of the initial cache entries within the context. This
   * allows soft/weak combinations to be tested in cases where eviction is not desired. The copy
   * held by the context can be mutated for additional flexibility during testing.
   */
  // FIXME(ben): May not be useful due to Java's integer cache (or needs to exceed cached range?)
  boolean retain() default true;

  /** The reference type of that the cache holds a key with (strong or weak only). */
  ReferenceType[] keys() default { ReferenceType.STRONG, ReferenceType.WEAK };

  /** The reference type of that the cache holds a value with (strong, soft, or weak). */
  ReferenceType[] values() default { ReferenceType.STRONG, ReferenceType.WEAK, ReferenceType.SOFT };

  /** The reference type of cache keys and/or values. */<commit_msg>Another experiment to reduce memory usage on CI<commit_after>/*
 * Copyright 2014 <NAME>. All Rights Reserved.
 *
 * 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 com.github.benmanes.caffeine.cache.testing;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.function.Supplier;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.RemovalListener;
import com.github.benmanes.caffeine.cache.testing.RemovalListeners.ConsumingRemovalListener;
import com.google.common.util.concurrent.MoreExecutors;

/**
 * The cache test specification so that a {@link org.testng.annotations.DataProvider} can construct
 * the maximum number of cache combinations to test against.
 *
 * @author ben.manes<EMAIL> (<NAME>)
 */
@Target(METHOD) @Retention(RUNTIME)
public @interface CacheSpec {

  /* ---------------- Initial capacity -------------- */

  enum InitialCapacity {
    /** A flag indicating that the initial capacity is not configured. */
    DEFAULT(16),
    /** A configuration where the table grows on the first addition. */
    ZERO(0),
    /** A configuration where the table grows on the second addition. */
    ONE(1),
    /** A configuration where the table grows after the {@link Population#FULL} count. */
    FULL(100),
    /** A configuration where the table grows after the 10 x {@link Population#FULL} count. */
    EXCESSIVE(10 * 100);

    private final int size;

    private InitialCapacity(int size) {
      this.size = size;
    }

    public int size() {
      return size;
    }
  }

  /** The initial capacities, each resulting in a new combination. */
  InitialCapacity[] initialCapacity() default {
    InitialCapacity.DEFAULT,
    InitialCapacity.FULL,
  };

  /* ---------------- Statistics -------------- */

  enum Stats { ENABLED, DISABLED }

  Stats[] stats() default {
    //Stats.ENABLED,
    Stats.DISABLED
  };

  /* ---------------- Maximum size -------------- */

  /** The maximum size, each resulting in a new combination. */
  MaximumSize[] maximumSize() default {
    MaximumSize.DISABLED,
    MaximumSize.UNREACHABLE
  };

  enum MaximumSize {
    /** A flag indicating that entries are not evicted due to a maximum size threshold. */
    DISABLED(Long.MAX_VALUE),
    /** A configuration where entries are evicted immediately. */
    ZERO(0L),
    /** A configuration that holds a single entry. */
    ONE(1L),
    /** A configuration that holds the {@link Population#FULL} count. */
    FULL(100L),
    /** A configuration where the threshold is too high for eviction to occur. */
    UNREACHABLE(Long.MAX_VALUE);

    private final long max;

    private MaximumSize(long max) {
      this.max = max;
    }

    public long max() {
      return max;
    }
  }

  /* ---------------- Reference-based -------------- */

  /**
   * Whether to retain a strong reference copy of the initial cache entries within the context. This
   * allows soft/weak combinations to be tested in cases where eviction is not desired. The copy
   * held by the context can be mutated for additional flexibility during testing.
   */
  // FIXME(ben): May not be useful due to Java's integer cache (or needs to exceed cached range?)
  boolean retain() default true;

  /** The reference type of that the cache holds a key with (strong or weak only). */
  ReferenceType[] keys() default { ReferenceType.STRONG, ReferenceType.WEAK };

  /** The reference type of that the cache holds a value with (strong, soft, or weak). */
  ReferenceType[] values() default { ReferenceType.STRONG, ReferenceType.WEAK, ReferenceType.SOFT };

  /** The reference type of cache keys and/or values. */
{'fraction_non_alphanumeric': 0.12066695919262835, 'fraction_numerical': 0.005923650724001755, 'mean_word_length': 3.068273092369478, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3317553', 'n_tokens_mistral': 2492, 'n_tokens_neox': 2393, 'n_words': 901}