<commit_before>/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. Camunda licenses this file to you under the Apache License,
 * Version 2.0; 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.camunda.bpm.engine.test.concurrency;

import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.cfg.TransactionListener;
import org.camunda.bpm.engine.impl.cfg.TransactionState;
import org.camunda.bpm.engine.impl.interceptor.Command;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.test.jobexecutor.ControllableJobExecutor;

/**
 * @author <NAME>
 */
public class CompetingHistoryCleanupAcquisitionTest extends ConcurrencyTestCase {

  protected ControllableJobExecutor jobExecutor = new ControllableJobExecutor();
  protected ThreadControl acquisitionThread;

  protected void setUp() throws Exception {
    super.setUp();

    acquisitionThread = jobExecutor.getAcquisitionThreadControl();
    acquisitionThread.reportInterrupts();

    jobExecutor.start();
  }

  protected void tearDown() throws Exception {
    clearDatabase();

    super.tearDown();
  }

  public void testCompetingHistoryCleanupAcquisition() {
    String jobId = historyService.cleanUpHistoryAsync(true).getId();

    ThreadControl cleanupThread = executeControllableCommand(new CleanupThread(jobId));

    acquisitionThread.waitForSync();

    cleanupThread.waitForSync();

    // perform acquisition
    acquisitionThread.makeContinue();

    cleanupThread.makeContinueAndWaitForSync();<commit_msg>chore(engine): exclude h2, mariadb and isolation not read committed<commit_after>/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. Camunda licenses this file to you under the Apache License,
 * Version 2.0; 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.camunda.bpm.engine.test.concurrency;

import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.cfg.TransactionListener;
import org.camunda.bpm.engine.impl.cfg.TransactionState;
import org.camunda.bpm.engine.impl.db.sql.DbSqlSessionFactory;
import org.camunda.bpm.engine.impl.interceptor.Command;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.test.jobexecutor.ControllableJobExecutor;
import org.camunda.bpm.engine.test.util.DatabaseHelper;

import java.sql.Connection;

/**
 * @author <NAME>
 */
public class CompetingHistoryCleanupAcquisitionTest extends ConcurrencyTestCase {

  protected ControllableJobExecutor jobExecutor = new ControllableJobExecutor();
  protected ThreadControl acquisitionThread;

  protected void setUp() throws Exception {
    super.setUp();

    acquisitionThread = jobExecutor.getAcquisitionThreadControl();
    acquisitionThread.reportInterrupts();

    jobExecutor.start();
  }

  protected void tearDown() throws Exception {
    if (jobExecutor.isActive()) {
      jobExecutor.shutdown();
    }

    clearDatabase();

    super.tearDown();
  }

  protected void runTest() throws Throwable {
    final Integer transactionIsolationLevel = DatabaseHelper.getTransactionIsolationLevel(processEngineConfiguration);
    String databaseType = DatabaseHelper.getDatabaseType(processEngineConfiguration);

    if (!DbSqlSessionFactory.H2.equals(databaseType) && !DbSqlSessionFactory.MARIADB.equals(databaseType) &&
      (transactionIsolationLevel == null || transactionIsolationLevel.equals(Connection.TRANSACTION_READ_COMMITTED))) {
      super.runTest();
    }
  }

  public void testCompetingHistoryCleanupAcquisition() {
    String jobId = historyService.cleanUpHistoryAsync(true).getId();

    ThreadControl cleanupThread = executeControllableCommand(new CleanupThread(jobId));

    acquisitionThread.waitForSync();

    cleanupThread.waitForSync();

    // perform acquisition
    acquisitionThread.makeContinue();

    cleanupThread.makeContinueAndWaitForSync();
{'fraction_non_alphanumeric': 0.08232856066314996, 'fraction_numerical': 0.0018839487565938207, 'mean_word_length': 4.958473625140292, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4338309', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1362, 'n_words': 389}