Search in sources :

Example 16 with PipedInputStream

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);
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) BeforeClass(org.junit.BeforeClass)

Example 17 with PipedInputStream

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());
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with PipedInputStream

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);
}
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 19 with PipedInputStream

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);
}
Also used : HystrixStream(com.netflix.hystrix.contrib.metrics.HystrixStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 20 with PipedInputStream

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"));
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) TempFolder(org.sonar.api.utils.TempFolder) WsResponse(org.sonarqube.ws.client.WsResponse) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Aggregations

PipedInputStream (java.io.PipedInputStream)128 PipedOutputStream (java.io.PipedOutputStream)121 IOException (java.io.IOException)42 Test (org.junit.Test)33 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 DataInputStream (java.io.DataInputStream)13 DataOutputStream (java.io.DataOutputStream)13 InputStream (java.io.InputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Before (org.junit.Before)10 OutputStream (java.io.OutputStream)9 PrintStream (java.io.PrintStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStreamReader (java.io.InputStreamReader)6 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)5