// Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// 		"-Djava.rmi.server.hostname=127.0.0.1",
// 		"-Dcom.sun.management.jmxremote.authenticate=false",
// 		"-Dcom.sun.management.jmxremote.ssl=false",
// 		"-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);


import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.flink.state.benchmark;





/**
 * Base implementation of the state benchmarks.
 */
public class StateBenchmarkBase extends BenchmarkBase {
    KeyedStateBackend<Long> keyedStateBackend;

    @Param({"HEAP", "ROCKSDB"})
    protected StateBackendBenchmarkUtils.StateBackendType backendType;

    final ThreadLocalRandom random = ThreadLocalRandom.current();

    @TearDown
    public void tearDown() throws IOException {
        cleanUp(keyedStateBackend);
    }

    static AtomicInteger keyIndex;

    private static int getCurrentIndex() {
        int currentIndex = keyIndex.getAndIncrement();
        if (currentIndex == Integer.MAX_VALUE) {
            keyIndex.set(0);
        }
        return currentIndex;
    }

    @State(Scope.Thread)
    public static class KeyValue {
        @Setup(Level.Invocation)
        public void kvSetup() {
            int currentIndex = getCurrentIndex();
            setUpKey = setupKeys.get(currentIndex % setupKeyCount);
            newKey = newKeys.get(currentIndex % newKeyCount);
            mapKey = mapKeys.get(currentIndex % mapKeyCount);
            mapValue = mapValues.get(currentIndex % mapKeyCount);
            value = randomValues.get(currentIndex % randomValueCount);
// Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// 		"-Djava.rmi.server.hostname=127.0.0.1",
// 		"-Dcom.sun.management.jmxremote.authenticate=false",
// 		"-Dcom.sun.management.jmxremote.ssl=false",
// 		"-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// 
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);


// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.flink.state.benchmark;





/**
 * Base implementation of the state benchmarks.
 */
public class StateBenchmarkBase extends BenchmarkBase {
    KeyedStateBackend<Long> keyedStateBackend;

    @Param({"HEAP", "ROCKSDB"})
    protected StateBackendBenchmarkUtils.StateBackendType backendType;

    final ThreadLocalRandom random = ThreadLocalRandom.current();

    @TearDown
    public void tearDown() throws IOException {
        cleanUp(keyedStateBackend);
    }

    static AtomicInteger keyIndex;

    private static int getCurrentIndex() {
        int currentIndex = keyIndex.getAndIncrement();
        if (currentIndex == Integer.MAX_VALUE) {
            keyIndex.set(0);
        }
        return currentIndex;
    }

    @State(Scope.Thread)
    public static class KeyValue {
        @Setup(Level.Invocation)
        public void kvSetup() {
            int currentIndex = getCurrentIndex();
            setUpKey = setupKeys.get(currentIndex % setupKeyCount);
            newKey = newKeys.get(currentIndex % newKeyCount);
            mapKey = mapKeys.get(currentIndex % mapKeyCount);
            mapValue = mapValues.get(currentIndex % mapKeyCount);
            value = randomValues.get(currentIndex % randomValueCount);
            listValue = Collections.singletonList(randomValues.get(currentIndex % randomValueCount));