private void internalTestThrowExOnRead(bool throwEx, bool throwError) { log.info("internalTestThrowExOnRead(throwEx=" + throwEx + ", throwError=" + throwError); IDictionary <int, Stream> streams = new Dictionary <int, Stream>(); for (int i = 0; i < 3; i++) { String str = "hello-" + i; Stream istrm = new MyInputStream(Encoding.ASCII.GetBytes(str), i == 1 && throwEx, i == 1 && throwError); streams[i] = istrm; } // An exception is thrown in HWireClient. try { log.info("setImages..."); remote.SetImages(streams, -1); Assert.Fail("Exception expected"); } catch (BException e) { log.info("setImages ex=" + e + ", OK"); String expectedMessage = throwEx ? "Test Exception" : "Test Error"; String expectedDetails = throwEx ? "System.IO.IOException: Test Exception" : "System.InvalidOperationException: Test Error"; TestUtils.assertEquals(log, "Exception Code", BExceptionC.IOERROR, e.Code); TestUtils.assertEquals(log, "Exception Message", expectedMessage, e.Message); String readDetails = e.Details.Substring(0, expectedDetails.Length); TestUtils.assertEquals(log, "Exception Details", expectedDetails, readDetails); } { log.info("read streams"); IDictionary <int, Stream> istrmsR = remote.GetImages(); for (int i = 0; i < istrmsR.Count; i++) { Stream istrmR = istrmsR[i]; ByteBuffer buf = BWire.bufferFromStream(istrmR, false); String strR = Encoding.ASCII.GetString(buf.array(), buf.position(), buf.remaining()); log.info("strR=" + strR); } } // All streams must have been closed log.info("streams must be closed"); for (int i = 0; i < streams.Count; i++) { MyInputStream istrm = (MyInputStream)streams[i]; TestUtils.assertEquals(log, "InputStream.isClosed", true, istrm.isClosed); } log.info(")internalTestThrowExOnRead"); }
public void testRemoteStreamsCloseStreamAfterSend() { log.info("testRemoteStreamsCloseStreamAfterSend("); IDictionary <int, Stream> streams = new Dictionary <int, Stream>(); for (int i = 0; i < 10; i++) { String str = "hello-" + i; Stream istrm = new MyInputStream(Encoding.ASCII.GetBytes(str), false, false); streams[i] = istrm; } remote.SetImages(streams, 5); for (int i = 0; i < 10; i++) { MyInputStream istrm = (MyInputStream)streams[i]; TestUtils.assertEquals(log, "InputStream.isClosed", true, istrm.isClosed); } log.info(")testRemoteStreamsCloseStreamAfterSend"); }
public override BContentStream getStream(BTargetId targetId) { BContentStream strm = new MyInputStream(this, targetId); return(strm); }
private void internalTestThrowExOnRead(bool throwEx, bool throwError) { log.info("internalTestThrowExOnRead(throwEx=" + throwEx + ", throwError=" + throwError); IDictionary<int, Stream> streams = new Dictionary<int, Stream>(); for (int i = 0; i < 3; i++) { String str = "hello-" + i; Stream istrm = new MyInputStream(Encoding.ASCII.GetBytes(str), i == 1 && throwEx, i == 1 && throwError); streams[i] = istrm; } // An exception is thrown in HWireClient. try { log.info("setImages..."); remote.SetImages(streams, -1); Assert.Fail("Exception expected"); } catch (BException e) { log.info("setImages ex=" + e + ", OK"); String expectedMessage = throwEx ? "Test Exception" : "Test Error"; String expectedDetails = throwEx ? "System.IO.IOException: Test Exception" : "System.InvalidOperationException: Test Error"; TestUtils.assertEquals(log, "Exception Code", BExceptionC.IOERROR, e.Code); TestUtils.assertEquals(log, "Exception Message", expectedMessage, e.Message); String readDetails = e.Details.Substring(0, expectedDetails.Length); TestUtils.assertEquals(log, "Exception Details", expectedDetails, readDetails); } { log.info("read streams"); IDictionary<int, Stream> istrmsR = remote.GetImages(); for (int i = 0; i < istrmsR.Count; i++) { Stream istrmR = istrmsR[i]; ByteBuffer buf = BWire.bufferFromStream(istrmR, false); String strR = Encoding.ASCII.GetString(buf.array(), buf.position(), buf.remaining()); log.info("strR=" + strR); } } // All streams must have been closed log.info("streams must be closed"); for (int i = 0; i < streams.Count; i++) { MyInputStream istrm = (MyInputStream)streams[i]; TestUtils.assertEquals(log, "InputStream.isClosed", true, istrm.isClosed); } log.info(")internalTestThrowExOnRead"); }
public void testRemoteStreamsCloseStreamAfterSend() { log.info("testRemoteStreamsCloseStreamAfterSend("); IDictionary<int, Stream> streams = new Dictionary<int, Stream>(); for (int i = 0; i < 10; i++) { String str = "hello-" + i; Stream istrm = new MyInputStream(Encoding.ASCII.GetBytes(str), false, false); streams[i] = istrm; } remote.SetImages(streams, 5); for (int i = 0; i < 10; i++) { MyInputStream istrm = (MyInputStream)streams[i]; TestUtils.assertEquals(log, "InputStream.isClosed", true, istrm.isClosed); } log.info(")testRemoteStreamsCloseStreamAfterSend"); }