Search in sources :

Example 91 with PipedOutputStream

use of java.io.PipedOutputStream in project symmetric-ds by JumpMind.

the class InternalTransportManager method getFilePushTransport.

public IOutgoingWithResponseTransport getFilePushTransport(final Node targetNode, final Node sourceNode, String securityToken, String registrationUrl) throws IOException {
    final PipedOutputStream pushOs = new PipedOutputStream();
    final PipedInputStream pushIs = new PipedInputStream(pushOs);
    final PipedOutputStream respOs = new PipedOutputStream();
    final PipedInputStream respIs = new PipedInputStream(respOs);
    runAtClient(targetNode.getSyncUrl(), pushIs, respOs, new IClientRunnable() {

        public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
            // This should be basically what the push servlet does ...
            engine.getFileSyncService().loadFilesFromPush(sourceNode.getNodeId(), is, os);
        }
    });
    return new InternalOutgoingWithResponseTransport(pushOs, respIs);
}
Also used : PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) NotImplementedException(org.apache.commons.lang.NotImplementedException) IOException(java.io.IOException)

Example 92 with PipedOutputStream

use of java.io.PipedOutputStream in project flink by apache.

the class OutputEmitterTest method testWrongKeyClass.

@Test
public void testWrongKeyClass() throws Exception {
    // Test for IntValue
    final TypeComparator<Record> doubleComp = new RecordComparatorFactory(new int[] { 0 }, new Class[] { DoubleValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(ShipStrategyType.PARTITION_HASH, doubleComp, 100);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());
    PipedInputStream pipedInput = new PipedInputStream(1024 * 1024);
    DataInputView in = new DataInputViewStreamWrapper(pipedInput);
    DataOutputView out = new DataOutputViewStreamWrapper(new PipedOutputStream(pipedInput));
    Record record = new Record(1);
    record.setField(0, new IntValue());
    record.write(out);
    record = new Record();
    record.read(in);
    try {
        delegate.setInstance(record);
        selector.selectChannel(delegate);
    } catch (DeserializationException re) {
        return;
    }
    Assert.fail("Expected a NullKeyFieldException.");
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) DataInputView(org.apache.flink.core.memory.DataInputView) RecordSerializerFactory(org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) DataOutputView(org.apache.flink.core.memory.DataOutputView) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) DeserializationException(org.apache.flink.types.DeserializationException) DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) DoubleValue(org.apache.flink.types.DoubleValue) Record(org.apache.flink.types.Record) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Example 93 with PipedOutputStream

use of java.io.PipedOutputStream in project flink by apache.

the class YarnTestBase method startWithArgs.

/**
 * This method returns once the "startedAfterString" has been seen.
 */
protected Runner startWithArgs(String[] args, String startedAfterString, RunTypes type) throws IOException {
    LOG.info("Running with args {}", Arrays.toString(args));
    outContent = new ByteArrayOutputStream();
    errContent = new ByteArrayOutputStream();
    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream(out);
    PrintStream stdinPrintStream = new PrintStream(out);
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
    System.setIn(in);
    final int startTimeoutSeconds = 60;
    Runner runner = new Runner(args, flinkConfiguration, CliFrontend.getConfigurationDirectoryFromEnv(), type, 0, stdinPrintStream);
    runner.setName("Frontend (CLI/YARN Client) runner thread (startWithArgs()).");
    runner.start();
    for (int second = 0; second < startTimeoutSeconds; second++) {
        sleep(1000);
        // check output for correct TaskManager startup.
        if (outContent.toString().contains(startedAfterString) || errContent.toString().contains(startedAfterString)) {
            LOG.info("Found expected output in redirected streams");
            return runner;
        }
        // check if thread died
        if (!runner.isAlive()) {
            resetStreamsAndSendOutput();
            if (runner.getRunnerError() != null) {
                throw new RuntimeException("Runner failed with exception.", runner.getRunnerError());
            }
            Assert.fail("Runner thread died before the test was finished.");
        }
    }
    resetStreamsAndSendOutput();
    Assert.fail("During the timeout period of " + startTimeoutSeconds + " seconds the " + "expected string did not show up");
    return null;
}
Also used : PrintStream(java.io.PrintStream) PipedOutputStream(java.io.PipedOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 94 with PipedOutputStream

use of java.io.PipedOutputStream 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 95 with PipedOutputStream

use of java.io.PipedOutputStream in project nanohttpd by NanoHttpd.

the class TestCorsHttpServer 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 = { "--host", "localhost", "--port", "9090", "--dir", "src/test/resources", "--cors" };
            SimpleWebServer.main(args);
        }
    });
    serverStartThread.start();
    // give the server some tine to start.
    Thread.sleep(100);
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) BeforeClass(org.junit.BeforeClass)

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