use of java.io.PipedInputStream in project nanohttpd by NanoHttpd.
the class TestNanolets method setUp.
@BeforeClass
public static void setUp() throws Exception {
stdIn = new PipedOutputStream();
System.setIn(new PipedInputStream(stdIn));
serverStartThread = new Thread(new Runnable() {
@Override
public void run() {
String[] args = {};
AppNanolets.main(args);
}
});
serverStartThread.start();
// give the server some tine to start.
Thread.sleep(200);
}
use of java.io.PipedInputStream in project nanohttpd by NanoHttpd.
the class EchoWebSocketsTest method testDirectoryArgument.
@Test
public void testDirectoryArgument() throws IOException, InterruptedException {
final String testPort = "9458";
PipedOutputStream stdIn = new PipedOutputStream();
System.setIn(new PipedInputStream(stdIn));
Thread testServer = new Thread(new Runnable() {
@Override
public void run() {
String[] args = { testPort, "-d" };
try {
EchoSocketSample.main(args);
} catch (IOException e) {
fail("Exception: " + e.getMessage());
}
}
});
testServer.start();
Thread.sleep(1000);
stdIn.write(System.getProperty("line.separator").getBytes());
testServer.join(1000);
assertFalse("Test server failed to close", testServer.isAlive());
}
use of java.io.PipedInputStream 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(stream.getConcurrentConnections().get() == 0);
}
use of java.io.PipedInputStream 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(stream.getConcurrentConnections().get() == 0);
}
use of java.io.PipedInputStream in project sonarqube by SonarSource.
the class ReportPublisherTest method test_ws_parameters.
@Test
public void test_ws_parameters() throws Exception {
ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "MyOrg");
WsResponse response = mock(WsResponse.class);
PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
WsCe.SubmitResponse.newBuilder().build().writeTo(out);
out.close();
when(response.failIfNotSuccessful()).thenReturn(response);
when(response.contentStream()).thenReturn(in);
when(wsClient.call(any(WsRequest.class))).thenReturn(response);
underTest.upload(temp.newFile());
ArgumentCaptor<WsRequest> capture = ArgumentCaptor.forClass(WsRequest.class);
verify(wsClient).call(capture.capture());
WsRequest wsRequest = capture.getValue();
assertThat(wsRequest.getParams()).containsOnly(entry("organization", "MyOrg"), entry("projectKey", "struts"));
}
Aggregations