<commit_before>package io.primeval.codex.dispatcher;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.assertj.core.api.Assertions;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.osgi.util.promise.Promise;
import org.osgi.util.promise.Promises;

import io.primeval.codex.test.rules.WithCodex;

public class PromiseQueueTest {

    @ClassRule
    public static final WithCodex wCodex = new WithCodex();

    @Rule
    public Timeout globalTimeout = Timeout.seconds(120);
    
    
    @Test
    public void testUnboundedQueue() throws Exception {
        PromiseQueue<Integer> promiseQueue = new PromiseQueue<>(wCodex.getDispatcher()::dispatch, 6, 0);
        List<Promise<Integer>> pmsList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            int j = i;
            Promise<Integer> promise = promiseQueue.dispatch(() -> {
                long sleepTime = sleepTime();
                Thread.sleep(sleepTime);
                return j;
            });
            pmsList.add(promise);
        }
        Promise<List<Integer>> list = Promises.all(pmsList);

        Assertions.assertThat(list.getValue()).isNotNull();
    }

    @Test
    public void testBoundedQueue() throws Exception {
        PromiseQueue<Integer> promiseQueue = new PromiseQueue<>(wCodex.getDispatcher()::dispatch, 6, 20);
        List<Promise<Integer>> pmsList = new ArrayList<>();
        for (int i = 0; i < 25; i++) {
            int j = i;
            Promise<Integer> promise = promiseQueue.dispatch(() -> {
                long sleepTime = sleepTime();
                Thread.sleep(sleepTime);
                return j;
            });
            pmsList.add(promise);
        }
        Promise<List<Integer>> list = Promises.all(pmsList);

        Assertions.assertThat(list.getValue()).isNotNull();
    }

    private long sleepTime() {
        Random random = new java.util.Random();
        boolean positive = random.nextBoolean();
        int value = random.nextInt(1_000);
        return 1_000L + (positive ? value : -value);
    }

}<commit_msg>PromiseQueue: fix tests that don't block on completion and print stacktraces<commit_after>package io.primeval.codex.dispatcher;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.assertj.core.api.Assertions;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.osgi.util.promise.Promise;
import org.osgi.util.promise.Promises;

import io.primeval.codex.test.rules.WithCodex;

public class PromiseQueueTest {

    @ClassRule
    public static final WithCodex wCodex = new WithCodex();

    @Rule
    public Timeout globalTimeout = Timeout.seconds(120);
    
    
    @Test
    public void testUnboundedQueue() throws Exception {
        PromiseQueue<Integer> promiseQueue = new PromiseQueue<>(wCodex.getDispatcher()::dispatch, 6, 0);
        List<Promise<Integer>> pmsList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            int j = i;
            Promise<Integer> promise = promiseQueue.dispatch(() -> {
                long sleepTime = sleepTime();
                Thread.sleep(sleepTime);
                return j;
            });
            pmsList.add(promise);
        }
        Promise<List<Integer>> list = Promises.all(pmsList);

        Assertions.assertThat(list.getValue()).isNotNull();
        
        list.getValue();
    }

    @Test
    public void testBoundedQueue() throws Exception {
        PromiseQueue<Integer> promiseQueue = new PromiseQueue<>(wCodex.getDispatcher()::dispatch, 6, 20);
        List<Promise<Integer>> pmsList = new ArrayList<>();
        for (int i = 0; i < 25; i++) {
            int j = i;
            Promise<Integer> promise = promiseQueue.dispatch(() -> {
                long sleepTime = sleepTime();
                Thread.sleep(sleepTime);
                return j;
            });
            pmsList.add(promise);
        }
        Promise<List<Integer>> list = Promises.all(pmsList);

        Assertions.assertThat(list.getValue()).isNotNull();
        
        list.getValue();
    }

    private long sleepTime() {
        Random random = new java.util.Random();
        boolean positive = random.nextBoolean();
        int value = random.nextInt(1_000);
        return 1_000L + (positive ? value : -value);
    }

}
{'fraction_non_alphanumeric': 0.12081742645407591, 'fraction_numerical': 0.010330114529530653, 'mean_word_length': 2.4182655410590943, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '6815908', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1254, 'n_words': 288}