public void TestBigWrite() { PipedInputStream pin = new PipedInputStream(); PipedOutputStream pout = new PipedOutputStream(pin); Random r = new Random(0); byte[] data = new byte [PipedInputStream.PIPE_SIZE * 3]; r.NextBytes(data); ThreadPool.QueueUserWorkItem(delegate { pout.Write(data); pout.Close(); }); int n = 0; byte[] buffer = new byte [100]; int nr; while ((nr = pin.Read(buffer)) != -1) { for (int i = 0; i < nr; i++) { Assert.AreEqual(buffer[i], data[n++], "Position " + n); } } }
public virtual void TestTimeout_readByte_Success2() { byte[] exp = new byte[] { (byte)('a'), (byte)('b'), (byte)('c') }; @out.Write(exp); NUnit.Framework.Assert.AreEqual(exp[0], @is.Read()); NUnit.Framework.Assert.AreEqual(exp[1], @is.Read()); NUnit.Framework.Assert.AreEqual(exp[2], @is.Read()); @out.Close(); NUnit.Framework.Assert.AreEqual(-1, @is.Read()); }
private void CheckOutput(string[] args, string pattern, TextWriter @out, Type clazz ) { ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); try { PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(pipeOut, PipeBufferSize); if (@out == System.Console.Out) { Runtime.SetOut(new TextWriter(pipeOut)); } else { if (@out == System.Console.Error) { Runtime.SetErr(new TextWriter(pipeOut)); } } if (clazz == typeof(DelegationTokenFetcher)) { ExpectDelegationTokenFetcherExit(args); } else { if (clazz == typeof(JMXGet)) { ExpectJMXGetExit(args); } else { if (clazz == typeof(DFSAdmin)) { ExpectDfsAdminPrint(args); } } } pipeOut.Close(); ByteStreams.Copy(pipeIn, outBytes); pipeIn.Close(); NUnit.Framework.Assert.IsTrue(Sharpen.Runtime.GetStringForBytes(outBytes.ToByteArray ()).Contains(pattern)); } catch (Exception ex) { NUnit.Framework.Assert.Fail("checkOutput error " + ex); } }
/// <exception cref="System.Exception"/> private static bool CheckPrintAllValues(JMXGet jmx) { int size = 0; byte[] bytes = null; string pattern = "List of all the available keys:"; PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(pipeOut); Runtime.SetErr(new TextWriter(pipeOut)); jmx.PrintAllValues(); if ((size = pipeIn.Available()) != 0) { bytes = new byte[size]; pipeIn.Read(bytes, 0, bytes.Length); } pipeOut.Close(); pipeIn.Close(); return(bytes != null?Sharpen.Runtime.GetStringForBytes(bytes).Contains(pattern) : false); }
public void Close() { channel.disconnect(); writer_po.Close(); reader.Close(); }