<commit_before>package com.hazelcast.stabilizer.worker.tasks;

import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.Logger;
import com.hazelcast.stabilizer.test.TestContext;
import com.hazelcast.stabilizer.test.annotations.Performance;
import com.hazelcast.stabilizer.worker.selector.OperationSelector;
import com.hazelcast.stabilizer.worker.selector.OperationSelectorBuilder;

import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Abstract worker class which is returned by {@link com.hazelcast.stabilizer.test.annotations.RunWithWorker} annotated test
 * methods.
 * <p/>
 * Implicitly logs and measures performance. The related properties can be overwritten with the properties of the test.
 * The Operation counter is automatically increased after each doRun() call.
 *
 * @param <O> Type of Enum used by the {@link com.hazelcast.stabilizer.worker.selector.OperationSelector}
 */
public abstract class AbstractWorkerTask<O extends Enum<O>> implements Runnable {

    final static ILogger LOGGER = Logger.getLogger(AbstractWorkerTask.class);

    final Random random = new Random();
    final OperationSelector<O> selector;

    // these fields will be injected by the TestContainer
    TestContext testContext;
    AtomicLong operationCount;

    // these fields will be injected by test.properties of the test
    long logFrequency = 10000;
    long performanceUpdateFrequency = 10000;

    // local variables
    long iteration = 0;

    public AbstractWorkerTask(OperationSelectorBuilder<O> operationSelectorBuilder) {
        this.selector = operationSelectorBuilder.build();
    }

    @Override
    public void run() {
        while (!testContext.isStopped()) {
            doRun(selector.select());

            increaseIteration();
        }
        operationCount.addAndGet(iteration % performanceUpdateFrequency);
    }

    @Performance
    public long getOperationCount() {
        return operationCount.get();
    }

    protected abstract void doRun(O operation);

    protected int nextInt(int upperBond) {
        return random.nextInt(upperBond);
    }

    void increaseIteration() {
        iteration++;
        if (iteration % logFrequency == 0) {
            LOGGER.info(Thread.currentThread().getName() + " At iteration: " + iteration);
        }

        if (iteration % performanceUpdateFrequency == 0) {
            operationCount.addAndGet(performanceUpdateFrequency);
        }
    }
}
<commit_msg>Adjusted performanceUpdateFrequency in AbstractWorkerTask. Added a setter to overwrite the value in a test class without the need of a runtime property via test.properties.<commit_after>package com.hazelcast.stabilizer.worker.tasks;

import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.Logger;
import com.hazelcast.stabilizer.test.TestContext;
import com.hazelcast.stabilizer.test.annotations.Performance;
import com.hazelcast.stabilizer.worker.selector.OperationSelector;
import com.hazelcast.stabilizer.worker.selector.OperationSelectorBuilder;

import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Abstract worker class which is returned by {@link com.hazelcast.stabilizer.test.annotations.RunWithWorker} annotated test
 * methods.
 * <p/>
 * Implicitly logs and measures performance. The related properties can be overwritten with the properties of the test.
 * The Operation counter is automatically increased after each doRun() call.
 *
 * @param <O> Type of Enum used by the {@link com.hazelcast.stabilizer.worker.selector.OperationSelector}
 */
public abstract class AbstractWorkerTask<O extends Enum<O>> implements Runnable {

    final static ILogger LOGGER = Logger.getLogger(AbstractWorkerTask.class);

    final Random random = new Random();
    final OperationSelector<O> selector;

    // these fields will be injected by the TestContainer
    TestContext testContext;
    AtomicLong operationCount;

    // these fields will be injected by test.properties of the test
    long logFrequency = 10000;
    long performanceUpdateFrequency = 10;

    // local variables
    long iteration = 0;

    public AbstractWorkerTask(OperationSelectorBuilder<O> operationSelectorBuilder) {
        this.selector = operationSelectorBuilder.build();
    }

    @Override
    public void run() {
        while (!testContext.isStopped()) {
            doRun(selector.select());

            increaseIteration();
        }
        operationCount.addAndGet(iteration % performanceUpdateFrequency);
    }

    @Performance
    public long getOperationCount() {
        return operationCount.get();
    }

    protected void setPerformanceUpdateFrequency(long performanceUpdateFrequency) {
        if (performanceUpdateFrequency <= 0) {
            throw new IllegalArgumentException("performanceUpdateFrequency must be a positive number!");
        }
        this.performanceUpdateFrequency = performanceUpdateFrequency;
    }

    protected abstract void doRun(O operation);

    protected int nextInt(int upperBond) {
        return random.nextInt(upperBond);
    }

    void increaseIteration() {
        iteration++;
        if (iteration % logFrequency == 0) {
            LOGGER.info(Thread.currentThread().getName() + " At iteration: " + iteration);
        }

        if (iteration % performanceUpdateFrequency == 0) {
            operationCount.addAndGet(performanceUpdateFrequency);
        }
    }
}

{'fraction_non_alphanumeric': 0.08528705925789182, 'fraction_numerical': 0.004430496584825549, 'mean_word_length': 3.583756345177665, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 15, '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': '6724638', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1392, 'n_words': 380}