<commit_before>package io.goshawkdb.test;

import org.junit.Test;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedDeque;

import io.goshawkdb.client.Connection;
import io.goshawkdb.client.GoshawkObj;
import io.goshawkdb.client.VarUUId;

public class ParCountTest extends TestBase {

    public ParCountTest() throws CertificateException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, InvalidKeyException, IOException {
        super();
    }

    @Test
    public void test() throws Throwable {
        final int threadCount = 8;
        final Connection conn = factory.connect(certs, "localhost", 10001);
        final ArrayList<GoshawkObj> roots = conn.runTransaction((txn) -> {
            final ArrayList<GoshawkObj> objs = new ArrayList<>(threadCount);
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++) {
                objs.add(txn.createObject(ByteBuffer.allocate(0)));
            }
            final GoshawkObj root = txn.getRoot();
            root.setReferences(objs.toArray(new GoshawkObj[threadCount]));
            return objs;
        });
        conn.close();

        final ConcurrentLinkedDeque<Throwable> exceptionQueue = new ConcurrentLinkedDeque<>();

        final Thread[] threads = new Thread[threadCount];
        for (int threadIndex = 0; threadIndex < threads.length; threadIndex++) {
            final int threadIndexCopy = threadIndex;
            final Thread t = new Thread(() -> {
                try {
                    final Connection c = factory.connect(certs, "localhost", 10001);
                    final VarUUId rootId = c.runTransaction(txn ->
                            txn.getRoot().getReferences()[threadIndexCopy].id
                    );
                    final long start = System.nanoTime();
                    long expected = 0L;
                    for (int idx = 0; idx < 1000; idx++) {
                        final int idy = idx;
                        final long expectedCopy = expected;
                        expected = c.runTransaction((txn) -> {
                            final GoshawkObj root = txn.getObject(rootId);
                            if (idy == 0) {
                                root.set(ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(0));
                                return 0L;
                            } else {
                                final long old = root.getValue().order(ByteOrder.BIG_ENDIAN).getLong(0);
                                if (old == expectedCopy) {
                                    final long val = old + 1;
                                    root.set(ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(0, val));
                                    return val;
                                } else {
                                    throw new IllegalStateException("" + threadIndexCopy + ": Expected " + expectedCopy + " but found " + old);
                                }
                            }
                        });
                    }
                    final long end = System.nanoTime();
                    System.out.println("" + threadIndexCopy + ": Elapsed time: " + ((double) (end - start)) / 1000000D + "ms");
                    c.close();
                } catch (Throwable e) {
                    exceptionQueue.add(e);
                } finally {
                    try {
                        conn.close();
                    } catch (InterruptedException e) {
                        exceptionQueue.add(e);
                    }
                }
            });
            threads[threadIndex] = t;
            t.start();
        }
        for (Thread t : threads) {
            t.join();
        }
        final Throwable t = exceptionQueue.peek();
        if (t != null) {
            throw t;
        }
        factory.group.shutdownGracefully();
    }
}
<commit_msg>tidy. Ref T33.<commit_after>package io.goshawkdb.test;

import org.junit.Test;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.InvalidKeyException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedDeque;

import io.goshawkdb.client.Connection;
import io.goshawkdb.client.GoshawkObj;
import io.goshawkdb.client.VarUUId;

public class ParCountTest extends TestBase {

    public ParCountTest() throws CertificateException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, InvalidKeyException, IOException {
        super();
    }

    @Test
    public void test() throws Throwable {
        final int threadCount = 8;
        final Connection conn = factory.connect(certs, "localhost", 10001);
        conn.runTransaction((txn) -> {
            final GoshawkObj[] roots = new GoshawkObj[threadCount];
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++) {
                roots[threadIndex] = txn.createObject(ByteBuffer.allocate(0));
            }
            final GoshawkObj root = txn.getRoot();
            root.setReferences(roots);
            return null;
        });
        conn.close();

        final ConcurrentLinkedDeque<Throwable> exceptionQueue = new ConcurrentLinkedDeque<>();

        final Thread[] threads = new Thread[threadCount];
        for (int threadIndex = 0; threadIndex < threads.length; threadIndex++) {
            final int threadIndexCopy = threadIndex;
            final Thread t = new Thread(() -> {
                try {
                    final Connection c = factory.connect(certs, "localhost", 10001);
                    final VarUUId rootId = c.runTransaction(txn ->
                            txn.getRoot().getReferences()[threadIndexCopy].id
                    );
                    final long start = System.nanoTime();
                    long expected = 0L;
                    for (int idx = 0; idx < 1000; idx++) {
                        final int idy = idx;
                        final long expectedCopy = expected;
                        expected = c.runTransaction((txn) -> {
                            final GoshawkObj root = txn.getObject(rootId);
                            if (idy == 0) {
                                root.set(ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(0));
                                return 0L;
                            } else {
                                final long old = root.getValue().order(ByteOrder.BIG_ENDIAN).getLong(0);
                                if (old == expectedCopy) {
                                    final long val = old + 1;
                                    root.set(ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(0, val));
                                    return val;
                                } else {
                                    throw new IllegalStateException("" + threadIndexCopy + ": Expected " + expectedCopy + " but found " + old);
                                }
                            }
                        });
                    }
                    final long end = System.nanoTime();
                    System.out.println("" + threadIndexCopy + ": Elapsed time: " + ((double) (end - start)) / 1000000D + "ms");
                    c.close();
                } catch (Throwable e) {
                    exceptionQueue.add(e);
                } finally {
                    try {
                        conn.close();
                    } catch (InterruptedException e) {
                        exceptionQueue.add(e);
                    }
                }
            });
            threads[threadIndex] = t;
            t.start();
        }
        for (Thread t : threads) {
            t.join();
        }
        final Throwable t = exceptionQueue.peek();
        if (t != null) {
            throw t;
        }
        factory.group.shutdownGracefully();
    }
}

{'fraction_non_alphanumeric': 0.09653725078698845, 'fraction_numerical': 0.008394543546694649, 'mean_word_length': 1.5125951962507322, 'pattern_counts': {'":': 4, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1882062', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2059, 'n_words': 463}