Search in sources :

Example 46 with PipedOutputStream

use of java.io.PipedOutputStream in project Hystrix by Netflix.

the class StreamingOutputProviderTest method testInfiniteOnNextStream.

@Test
public void testInfiniteOnNextStream() throws Exception {
    final PipedInputStream is = new PipedInputStream();
    final PipedOutputStream os = new PipedOutputStream(is);
    final AtomicInteger writes = new AtomicInteger(0);
    final HystrixStream stream = new HystrixStream(streamOfOnNexts, 100, new AtomicInteger(1));
    Thread streamingThread = startStreamingThread(stream, os);
    verifyStream(is, writes);
    // Let the provider stream for some time.
    Thread.sleep(1000);
    // Stop streaming
    streamingThread.interrupt();
    os.close();
    is.close();
    System.out.println("Total lines:" + writes.get());
    // Observable is configured to emit events in every 100 ms. So expect at least 9 in a second.
    assertTrue(writes.get() >= 9);
    // Provider is expected to decrement connection count when streaming process is terminated.
    assertTrue(hasNoMoreConcurrentConnections(stream.getConcurrentConnections(), 200, 10, TimeUnit.MILLISECONDS));
}
Also used : HystrixStream(com.netflix.hystrix.contrib.metrics.HystrixStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Example 47 with PipedOutputStream

use of java.io.PipedOutputStream in project Hystrix by Netflix.

the class StreamingOutputProviderTest method testStreamOnce.

private void testStreamOnce(Observable<String> observable) throws Exception {
    final PipedInputStream is = new PipedInputStream();
    final PipedOutputStream os = new PipedOutputStream(is);
    final AtomicInteger writes = new AtomicInteger(0);
    final HystrixStream stream = new HystrixStream(observable, 100, new AtomicInteger(1));
    startStreamingThread(stream, os);
    verifyStream(is, writes);
    Thread.sleep(1000);
    os.close();
    is.close();
    System.out.println("Total lines:" + writes.get());
    assertTrue(writes.get() == 1);
    assertTrue(hasNoMoreConcurrentConnections(stream.getConcurrentConnections(), 200, 10, TimeUnit.MILLISECONDS));
}
Also used : HystrixStream(com.netflix.hystrix.contrib.metrics.HystrixStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 48 with PipedOutputStream

use of java.io.PipedOutputStream in project jacoco by jacoco.

the class CompactDataInputOutputTest method setup.

@Before
public void setup() throws IOException {
    PipedOutputStream pipe = new PipedOutputStream();
    out = new CompactDataOutput(pipe);
    in = new CompactDataInput(new PipedInputStream(pipe));
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Before(org.junit.Before)

Example 49 with PipedOutputStream

use of java.io.PipedOutputStream in project kie-wb-common by kiegroup.

the class MavenCliOutputTest method buildAppAndWaitForMavenOutputTest.

@Test
public void buildAppAndWaitForMavenOutputTest() throws IOException {
    final Optional<Source> _source = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, "drools-workshop", "true"));
    assertTrue(_source.isPresent());
    final Source source = _source.get();
    boolean buildProcessReady = false;
    Throwable error = null;
    PipedOutputStream baosOut = new PipedOutputStream();
    PipedOutputStream baosErr = new PipedOutputStream();
    final PrintStream out = new PrintStream(baosOut, true);
    final PrintStream err = new PrintStream(baosErr, true);
    // Build the project in a different thread
    new Thread(() -> {
        buildMavenProject(source, out, err);
    }).start();
    // Use the PipeOutputStream to read the execution output and validate that the application was built.
    StringBuilder sb = new StringBuilder();
    BufferedReader bufferedReader;
    bufferedReader = new BufferedReader(new InputStreamReader(new PipedInputStream(baosOut)));
    String line;
    while (!(buildProcessReady || error != null)) {
        if ((line = bufferedReader.readLine()) != null) {
            sb.append(line).append("\n");
            if (line.contains("Building war:")) {
                buildProcessReady = true;
                out.close();
                err.close();
                baosOut.close();
                baosErr.close();
            }
        }
    }
    assertTrue(sb.toString().contains("Building war:"));
    assertTrue(buildProcessReady);
    assertTrue(error == null);
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Source(org.guvnor.ala.source.Source) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) BufferedReader(java.io.BufferedReader) Test(org.junit.Test)

Example 50 with PipedOutputStream

use of java.io.PipedOutputStream in project kie-wb-common by kiegroup.

the class GWTCodeServerMavenExecConfigExecutor method build.

public void build(final File pom, final Properties properties, final List<String> goals) throws BuildException {
    BufferedReader bufferedReader = null;
    try {
        StringBuilder sb = new StringBuilder();
        final PipedOutputStream baosOut = new PipedOutputStream();
        final PipedOutputStream baosErr = new PipedOutputStream();
        final PrintStream out = new PrintStream(baosOut, true);
        final PrintStream err = new PrintStream(baosErr, true);
        new Thread(() -> executeMaven(pom, out, err, properties, goals.toArray(new String[] {}))).start();
        String line;
        while (!(isCodeServerReady || error != null)) {
            bufferedReader = new BufferedReader(new InputStreamReader(new PipedInputStream(baosOut)));
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line).append("\n");
                if (line.contains("The code server is ready at")) {
                    isCodeServerReady = true;
                    out.close();
                    err.close();
                    baosOut.close();
                    baosErr.close();
                    LOG.info("> Code Server Started Succesfully.");
                }
            }
        }
    // @TODO: send line to client
    } catch (IOException ex) {
        Logger.getLogger(GWTCodeServerMavenExecConfigExecutor.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            bufferedReader.close();
        } catch (IOException ex) {
            Logger.getLogger(GWTCodeServerMavenExecConfigExecutor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Aggregations

PipedOutputStream (java.io.PipedOutputStream)221 PipedInputStream (java.io.PipedInputStream)199 IOException (java.io.IOException)89 Test (org.junit.Test)54 InputStream (java.io.InputStream)30 OutputStream (java.io.OutputStream)23 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 PrintStream (java.io.PrintStream)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)19 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 InputStreamReader (java.io.InputStreamReader)16 DataInputStream (java.io.DataInputStream)14 DataOutputStream (java.io.DataOutputStream)14 BufferedReader (java.io.BufferedReader)13 Before (org.junit.Before)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ExecutorService (java.util.concurrent.ExecutorService)9 ArrayList (java.util.ArrayList)7