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));
}
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));
}
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));
}
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);
}
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);
}
}
}
Aggregations