<commit_before>package no.cantara.cs.testsupport;

import com.jayway.restassured.RestAssured;
import no.cantara.cs.client.ClientConfigResource;
import no.cantara.cs.Main;
import no.cantara.cs.client.ConfigServiceClient;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Map;

public class TestServer {

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

    private Main main;
    private String url;
    private int port = 26451;

    public static final String USERNAME = "read";
    public static final String PASSWORD = "<PASSWORD>";

    public TestServer withPort(int port) {
        this.port = port;
        return this;
    }

    public void cleanAllData() throws Exception {
        String dbPath = "./db/serviceconfig.db";
        File mapDbPathFile = new File(dbPath);
        log.debug("Cleaning data in MapDB {}", mapDbPathFile.getAbsolutePath());
        mapDbPathFile.getParentFile().mkdirs();
        DB db = DBMaker.newFileDB(mapDbPathFile).make();

        db.getAll().entrySet().stream()
                .filter(e -> e.getValue() instanceof Map)
                .map(e -> (Map) e.getValue())
                .forEach(Map::clear);
        db.commit();
        db.close();
    }

    public void start() throws InterruptedException {
        new Thread(() -> {
            main = new Main(port);
            main.start();
        }).start();
        do {
            Thread.sleep(10);
        } while (main == null || !main.isStarted());
        RestAssured.port = main.getPort();

        RestAssured.basePath = Main.CONTEXT_PATH;
        url = "http://localhost:" + main.getPort() + Main.CONTEXT_PATH + ClientConfigResource.CLIENTCONFIG_PATH;
    }

    public void stop() {
        main.stop();
    }

    public ConfigServiceClient getConfigServiceClient() {
        return new ConfigServiceClient(url, USERNAME, PASSWORD);
    }

    public ConfigServiceAdminClient getAdminClient() {
        return new ConfigServiceAdminClient(TestServer.USERNAME, TestServer.PASSWORD);
    }
}
<commit_msg>Tests can now clean incompatible db<commit_after>package no.cantara.cs.testsupport;

import com.jayway.restassured.RestAssured;
import no.cantara.cs.Main;
import no.cantara.cs.client.ClientConfigResource;
import no.cantara.cs.client.ConfigServiceClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

import static java.util.Arrays.stream;

public class TestServer {

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

    private Main main;
    private String url;
    private int port = 26451;

    public static final String USERNAME = "read";
    public static final String PASSWORD = "<PASSWORD>";

    public TestServer withPort(int port) {
        this.port = port;
        return this;
    }

    public void cleanAllData() throws Exception {
        File mapDbFolder = new File("./db");
        stream(mapDbFolder.listFiles((dir, name) -> name.startsWith("serviceConfig.db"))).forEach(f -> {
            log.info("Deleting mapdb file: " + f.getAbsolutePath());
            f.delete();
        });
    }

    public void start() throws InterruptedException {
        new Thread(() -> {
            main = new Main(port);
            main.start();
        }).start();
        do {
            Thread.sleep(10);
        } while (main == null || !main.isStarted());
        RestAssured.port = main.getPort();

        RestAssured.basePath = Main.CONTEXT_PATH;
        url = "http://localhost:" + main.getPort() + Main.CONTEXT_PATH + ClientConfigResource.CLIENTCONFIG_PATH;
    }

    public void stop() {
        main.stop();
    }

    public ConfigServiceClient getConfigServiceClient() {
        return new ConfigServiceClient(url, USERNAME, PASSWORD);
    }

    public ConfigServiceAdminClient getAdminClient() {
        return new ConfigServiceAdminClient(TestServer.USERNAME, TestServer.PASSWORD);
    }
}

{'fraction_non_alphanumeric': 0.11536548980606663, 'fraction_numerical': 0.0044753853804077575, 'mean_word_length': 2.7703842549203372, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '673824', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1162, 'n_words': 265}