<commit_before>package se.arbetsformedlingen.venice;


import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.junit.Ignore;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class RestClientTest {

    @Test
    @Ignore
    public void rest_client() throws Exception {
        String uri = "http://gfr.u1/wildfly05/jolokia/read/af-probe:probe=UgkForetagProbe/";

        String user = System.getenv("PROBE_USER");
        String password = System.getenv("PROBE_PASSWORD");

        Executor executor = Executor.newInstance()
                .auth(user, password);

        String res = executor.execute(Request.Get(uri))
                .returnContent().asString();

        CompletableFuture<Object> foo = CompletableFuture.supplyAsync(() -> {
            String r = "Failure";
            try {
                r = executor.execute(Request.Get(uri))
                        .returnContent().asString();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return r;
        });

        while (!foo.isDone()) {
            System.out.print(".");
            Thread.sleep(50);
        }

        assertThat(foo.get()).isEqualTo("Hello");
    }

}
<commit_msg>Added spikes for understanding how to get probe statuses asynchronous<commit_after>package se.arbetsformedlingen.venice;


import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.junit.Ignore;
import org.junit.Test;

import java.io.IOException;
import java.util.Set;
import java.util.concurrent.*;

import static java.util.concurrent.TimeUnit.SECONDS;

public class RestClientTest {

    @Test
    @Ignore
    public void rest_client() throws Exception {
        String uri = "http://gfr.u1/wildfly05/jolokia/read/af-probe:probe=UgkForetagProbe/";

        String user = System.getenv("PROBE_USER");
        String password = System.getenv("PROBE_PASSWORD");

        Executor executor = Executor.newInstance()
                .auth(user, password);

        CompletableFuture<Object> foo = CompletableFuture.supplyAsync(() -> {
            String r = "Failure";
            try {
                r = executor.execute(Request.Get(uri))
                        .returnContent().asString();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return r;
        });

        while (!foo.isDone()) {
            Thread.sleep(50);
        }

        System.out.println(foo.get());
    }

    @Test
    @Ignore
    public void schedule_tasks() throws Exception {
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

        final Runnable beeper = () -> {
            try {
                if (Math.random() > 0.5) {
                    System.out.println("beep");
                } else {
                    throw new RuntimeException("Ooops");
                }
            } catch (Throwable t) {
                System.out.println(t.getMessage());
            }
        };

        scheduler.scheduleAtFixedRate(beeper, 1, 1, SECONDS);

        pause();

        System.out.println("Done");
    }

    @Test
    @Ignore
    public void schedule_many_executions() throws Exception {
        ProbeStatus probeStatus = new ProbeStatus();

        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        String[] hostNames = {"foo", "bar", "foobar"};

        for (String hostName : hostNames) {
            ProbeChecker probeChecker = new ProbeChecker(hostName, probeStatus);
            scheduler.scheduleAtFixedRate(probeChecker, 0, 1, SECONDS);
        }

        pause();

        for (String host : probeStatus.getHosts()) {
            System.out.println("Status for " + host + " is " + probeStatus.getStatus(host));
        }

        System.out.println("Done - updated statuses " + probeStatus.calledTimes());

    }

    private void pause() throws InterruptedException {
        Thread.sleep(6 * 1000);
    }
}

class ProbeChecker implements Runnable {
    private String hostName;
    private ProbeStatus probeStatus;

    ProbeChecker(String hostName, ProbeStatus probeStatus) {
        this.hostName = hostName;
        this.probeStatus = probeStatus;
    }

    @Override
    public void run() {
        CheckProbeFor checkProbeFor = new CheckProbeFor(hostName);
        CompletableFuture.supplyAsync(checkProbeFor)
                .thenAccept(result -> {
                    probeStatus.addStatus(hostName, result);
                    System.out.println(result);
                });
        System.out.println("submitted check");
    }
}

class CheckProbeFor implements java.util.function.Supplier<String> {
    private String hostname;

    CheckProbeFor(String hostname) {
        this.hostname = hostname;
    }

    @Override
    public String get() {
        long time = 0;
        try {
            time = randomPause();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Checking " + hostname + " took " + time + " ms");
        return "Online";
    }

    private long randomPause() throws InterruptedException {
        long time = (long) (Math.random() * 6000);
        Thread.sleep(time);
        return time;
    }

}

class ProbeStatus {
    private static ConcurrentMap<String, String> probeStatuses = new ConcurrentHashMap<>();
    private static int times = 0;

    void addStatus(String host, String status) {
        synchronized (this) {
            times++;
        }

        probeStatuses.put(host, status);
    }

    Set<String> getHosts() {
        return probeStatuses.keySet();
    }

    String getStatus(String host) {
        return probeStatuses.get(host);
    }

    int calledTimes() {
        return times;
    }
}

{'fraction_non_alphanumeric': 0.1113533456313936, 'fraction_numerical': 0.004863323830286768, 'mean_word_length': 2.143911439114391, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '6986497', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1643, 'n_words': 338}