<commit_before>package jet.bpm.engine;

import jet.bpm.engine.api.ActivationListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jet.bpm.engine.api.Execution;
import jet.bpm.engine.event.EventPersistenceManager;
import jet.bpm.engine.event.EventPersistenceManagerImpl;
import jet.bpm.engine.api.JavaDelegate;
import jet.bpm.engine.event.InMemEventStorage;
import jet.bpm.engine.task.ServiceTaskRegistry;
import jet.bpm.engine.task.ServiceTaskRegistryImpl;
import jet.bpm.engine.model.ProcessDefinition;
import static org.junit.Assert.*;
import org.junit.Before;
import static org.mockito.Mockito.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractEngineTest implements ActivationListener {

    private static final Logger log = LoggerFactory.getLogger(AbstractEngineTest.class);

    private ProcessDefinitionProvider processDefinitionProvider;
    private ServiceTaskRegistry serviceTaskRegistry;
    protected EventPersistenceManager eventManager;
    private AbstractEngine engine;
    private Map<String, List<String>> activations;

    @Before
    public void init() {
        processDefinitionProvider = new ProcessDefinitionProviderImpl();
        serviceTaskRegistry = new ServiceTaskRegistryImpl();
        eventManager = spy(new EventPersistenceManagerImpl(new InMemEventStorage()));

        engine = new DefaultEngine(processDefinitionProvider, serviceTaskRegistry, eventManager);

        activations = new HashMap<>();
        engine.addListener(this);
    }

    protected void deploy(ProcessDefinition pd) {
        ((ProcessDefinitionProviderImpl) processDefinitionProvider).add(pd);
    }

    protected AbstractEngine getEngine() {
        return engine;
    }

    protected void register(String key, JavaDelegate d) {
        serviceTaskRegistry.register(key, d);
    }

    @Override
    public void onActivation(Execution e, String processDefinitionId, String elementId) {
        String k = e.getBusinessKey() + "/" + processDefinitionId;
        List<String> l = activations.get(k);
        if (l == null) {
            l = new ArrayList<>();
            activations.put(k, l);
        }

        l.add(elementId);
    }
<commit_msg>tests with leveldb<commit_after>package jet.bpm.engine;

import jet.bpm.engine.api.ActivationListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jet.bpm.engine.api.Execution;
import jet.bpm.engine.event.EventPersistenceManager;
import jet.bpm.engine.event.EventPersistenceManagerImpl;
import jet.bpm.engine.api.JavaDelegate;
import jet.bpm.engine.event.InMemEventStorage;
import jet.bpm.engine.leveldb.Configuration;
import jet.bpm.engine.leveldb.KryoSerializer;
import jet.bpm.engine.leveldb.LevelDbPersistenceManager;
import jet.bpm.engine.lock.StripedLockManagerImpl;
import jet.bpm.engine.task.ServiceTaskRegistry;
import jet.bpm.engine.task.ServiceTaskRegistryImpl;
import jet.bpm.engine.model.ProcessDefinition;
import org.iq80.leveldb.DBFactory;
import org.iq80.leveldb.impl.Iq80DBFactory;
import org.junit.After;
import static org.junit.Assert.*;
import org.junit.Before;
import static org.mockito.Mockito.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractEngineTest implements ActivationListener {

    private static final Logger log = LoggerFactory.getLogger(AbstractEngineTest.class);

    private ProcessDefinitionProvider processDefinitionProvider;
    private ServiceTaskRegistry serviceTaskRegistry;
    protected EventPersistenceManager eventManager;
    private AbstractEngine engine;
    private Map<String, List<String>> activations;
    private LevelDbPersistenceManager levelDbPersistenceManager;

    @Before
    public void init() {
        processDefinitionProvider = new ProcessDefinitionProviderImpl();
        serviceTaskRegistry = new ServiceTaskRegistryImpl();
        eventManager = spy(new EventPersistenceManagerImpl(new InMemEventStorage()));

        Configuration cfg = new Configuration();
        cfg.setExecutionPath("/tmp/bpm/");
        DBFactory f = new Iq80DBFactory();
        levelDbPersistenceManager = new LevelDbPersistenceManager(cfg, f, new KryoSerializer());
        levelDbPersistenceManager.init();

//        engine = new DefaultEngine(processDefinitionProvider, serviceTaskRegistry, eventManager, levelDbPersistenceManager, new StripedLockManagerImpl(1));
        engine = new DefaultEngine(processDefinitionProvider, serviceTaskRegistry, eventManager);

        activations = new HashMap<>();
        engine.addListener(this);
    }

    @After
    public void initLevelDb() {
        levelDbPersistenceManager.close();
    }

    protected void deploy(ProcessDefinition pd) {
        ((ProcessDefinitionProviderImpl) processDefinitionProvider).add(pd);
    }

    protected AbstractEngine getEngine() {
        return engine;
    }

    protected void register(String key, JavaDelegate d) {
        serviceTaskRegistry.register(key, d);
    }

    @Override
    public void onActivation(Execution e, String processDefinitionId, String elementId) {
        String k = e.getBusinessKey() + "/" + processDefinitionId;
        List<String> l = activations.get(k);
        if (l == null) {
            l = new ArrayList<>();
            activations.put(k, l);
        }

        l.add(elementId);
    }

{'fraction_non_alphanumeric': 0.09228801169590643, 'fraction_numerical': 0.0023757309941520467, 'mean_word_length': 4.1245318352059925, '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': '258775', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1457, 'n_words': 322}