<commit_before>package org.skife.gressil;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.List;

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

public class DaemonTest
{
    @Test
    public void testFoo() throws Exception
    {
        POSIX posix = POSIXFactory.getPOSIX();

        List<POSIX.SpawnFileAction> actions = asList();

        List<String> argv = asList("/bin/ls", "/tmp");

        List<String> envp = asList();

        String jh = System.getProperty("java.home");
        System.out.println(jh);


        int rs = posix.posix_spawnp("/bin/ls", actions, argv, envp);
        System.out.println(rs);
    }

    @Test
    public void testGetCommandLine() throws Exception
    {
        String pid = String.valueOf(POSIXFactory.getPOSIX().getpid());

        Process p = new ProcessBuilder().command("ps", "-p", pid, "-o", "command").start();
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    }

    public static void main(String[] args) throws Exception
    {
        File out = new File("/tmp/gressil.out");
        File err = new File("/tmp/gressil.err");
        File pid = new File("/tmp/gressil.pid");

        Status status = new Daemon().withPidFile(pid)
                                    .withStdout(out)
                                    .withStderr(err)
                                    .fork();

        if (status.isParent()) {
            // parent
            while ((!out.exists()) && (!err.exists()) && (!pid.exists())) {
                Thread.sleep(10);
            }

            String out_msg = Files.readFirstLine(out, Charsets.US_ASCII);
            assertThat(out_msg, equalTo("out out"));

            String err_msg = Files.readFirstLine(err, Charsets.US_ASCII);
            assertThat(err_msg, equalTo("err err"));

            int child_pid = Integer.parseInt(Files.readFirstLine(pid, Charsets.US_ASCII));
            assertThat(child_pid, equalTo(status.getChildPid()));

            POSIXFactory.getPOSIX().kill(status.getChildPid(), 3);

            out.delete();
            err.delete();
            pid.delete();

            System.out.println("PASSED");
        }
        else {
            // child
            System.out.println("out out");
            System.err.println("err err");
            Thread.currentThread().join();
        }

    }

}<commit_msg>clean up test<commit_after>package org.skife.gressil;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

public class DaemonTest
{
    @Test
    public void testFoo() throws Exception
    {
        POSIX posix = POSIXFactory.getPOSIX();

        List<POSIX.SpawnFileAction> actions = asList();

        List<String> argv = asList("/bin/ls", "/tmp");

        List<String> envp = asList();

        String jh = System.getProperty("java.home");
        System.out.println(jh);


        int rs = posix.posix_spawnp("/bin/ls", actions, argv, envp);
        System.out.println(rs);
    }

    @Test
    public void testGetCommandLine() throws Exception
    {
        String pid = String.valueOf(POSIXFactory.getPOSIX().getpid());

        Process p = new ProcessBuilder().command("ps", "-p", pid, "-o", "command").start();
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    }

    public static void main(String[] args) throws Exception
    {
        File out = new File("/tmp/gressil.out");
        File err = new File("/tmp/gressil.err");
        File pid = new File("/tmp/gressil.pid");
        out.delete();
        err.delete();
        pid.delete();

        Status status = new Daemon().withPidFile(pid)
            .withStdout(out)
            .withStderr(err)
            .fork();

        if (status.isParent()) {
            // parent
            while ((!out.exists()) && (!err.exists()) && (!pid.exists())) {
                Thread.sleep(10);
            }

            String out_msg = Files.readFirstLine(out, Charsets.US_ASCII);
            assertThat(out_msg, equalTo("out out"));

            String err_msg = Files.readFirstLine(err, Charsets.US_ASCII);
            assertThat(err_msg, equalTo("err err"));

            int child_pid = Integer.parseInt(Files.readFirstLine(pid, Charsets.US_ASCII));
            assertThat(child_pid, equalTo(status.getChildPid()));

            System.out.printf("child pid is %d\n", status.getChildPid());
            POSIXFactory.getPOSIX().kill(status.getChildPid(), 15);

            out.delete();
            err.delete();
            pid.delete();

            System.out.println("PASSED");
        }
        else {
            // child
            System.out.println("out out");
            System.err.println("err err");
            Thread.currentThread().join();
        }

    }

}
{'fraction_non_alphanumeric': 0.13833362816203787, 'fraction_numerical': 0.0012382805589952238, 'mean_word_length': 2.1943502824858756, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519002', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1653, 'n_words': 328}