@Test(timeout = 1000)
    public void testConcurrentStreamPiping() throws Exception {
        final int charCount = 30;
        final char[] vals = "123456789".toCharArray();
        final int n = vals.length;
        InputStream[] istreams = new InputStream[n];

        // Generate n istreams with charCount equal elements in them.
        for (int i = 0; i < n; i++) {
            String s = "";
            for (int j = 0; j < charCount; j++) {
                s += vals[i];
            }
            InputStream is = IOUtils.toInputStream(s, "UTF-8");
            istreams[i] = new SlowInputStream(is);
        }
        ByteArrayOutputStream wrt = new ByteArrayOutputStream();
        Pipe[] pipes = new Pipe[n];
        for (int i = 0; i < n; i++) {
            pipes[i] = new Pipe(istreams[i], wrt);
        }
        for (int i = 0; i < n; i++) {
            pipes[i].start();
        }
        for (int i = 0; i < n; i++) {
            pipes[i].join();
            istreams[i].close();
        }

        // Count up elements and ensure that we've got the correct amount of
        // characters of each type.
        String out = wrt.toString("UTF-8");
        char[] output = out.toCharArray();
        wrt.close();
        for (char v : vals) {
            int sum = 0;
            for (char c : output) {
                if (c == v) {
                    sum++;
                }
            }
            assertEquals(charCount, sum);
        }
    }