[jboss-remoting-commits] JBoss Remoting SVN: r6116 - in remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test: stream and 1 other directory.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Sep 24 21:41:02 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-09-24 21:41:02 -0400 (Fri, 24 Sep 2010)
New Revision: 6116

Added:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/stream/
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/stream/StreamsTestCase.java
Removed:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/StreamsTestCase.java
Log:
JBREM-1228: Moved to org.jboss.remoting3.test.stream and added a bunch of methods.

Deleted: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/StreamsTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/StreamsTestCase.java	2010-09-24 16:11:58 UTC (rev 6115)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/StreamsTestCase.java	2010-09-25 01:41:02 UTC (rev 6116)
@@ -1,115 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.remoting3.test;
-
-import java.io.EOFException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Vector;
-import org.jboss.remoting3.stream.ObjectSink;
-import org.jboss.remoting3.stream.ObjectSource;
-import org.jboss.remoting3.stream.Streams;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-/**
- *
- */
- at Test(suiteName = "streams")
-public final class StreamsTestCase {
-
-    public void testCollectionObjectSink() throws Throwable {
-        final ArrayList<String> strings = new ArrayList<String>();
-        final ObjectSink<String> sink = Streams.getCollectionObjectSink(strings);
-        sink.accept("Instance 1");
-        sink.accept("Instance 2");
-        sink.accept("Instance 3");
-        sink.accept("Instance 4");
-        sink.accept("Instance 5");
-        sink.close();
-        final Iterator<String> i = strings.iterator();
-        assertEquals(i.next(), "Instance 1");
-        assertEquals(i.next(), "Instance 2");
-        assertEquals(i.next(), "Instance 3");
-        assertEquals(i.next(), "Instance 4");
-        assertEquals(i.next(), "Instance 5");
-        assertFalse(i.hasNext());
-    }
-
-    public void testIteratorObjectSource() throws Throwable {
-        final ObjectSource<String> source = Streams.getIteratorObjectSource(Arrays.asList("One", "Two", "Three", "Four", "Five").iterator());
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "One");
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "Two");
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "Three");
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "Four");
-        assertTrue(source.hasNext());
-        assertTrue(source.hasNext()); // tricky!
-        assertEquals(source.next(), "Five");
-        assertFalse(source.hasNext());
-        assertFalse(source.hasNext()); // also tricky!
-        source.close();
-        assertFalse(source.hasNext()); // also also tricky!
-        assertFalse(source.hasNext()); // also also also tricky!
-        try {
-            source.next();
-        } catch (EOFException t) {
-            return;
-        }
-        fail("No exception thrown at end of iterator");
-    }
-
-    public void testEnumerationObjectSource() throws Throwable {
-        final ObjectSource<String> source = Streams.getEnumerationObjectSource(new Vector<String>(Arrays.asList("One", "Two", "Three", "Four", "Five")).elements());
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "One");
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "Two");
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "Three");
-        assertTrue(source.hasNext());
-        assertEquals(source.next(), "Four");
-        assertTrue(source.hasNext());
-        assertTrue(source.hasNext()); // tricky!
-        assertEquals(source.next(), "Five");
-        assertFalse(source.hasNext());
-        assertFalse(source.hasNext()); // also tricky!
-        source.close();
-        assertFalse(source.hasNext()); // also also tricky!
-        assertFalse(source.hasNext()); // also also also tricky!
-        try {
-            source.next();
-        } catch (EOFException t) {
-            return;
-        }
-        fail("No exception thrown at end of iterator");
-    }
-}

Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/stream/StreamsTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/stream/StreamsTestCase.java	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/stream/StreamsTestCase.java	2010-09-25 01:41:02 UTC (rev 6116)
@@ -0,0 +1,502 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test.stream;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.Vector;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.marshalling.ByteBufferInput;
+import org.jboss.marshalling.ByteInput;
+import org.jboss.marshalling.OutputStreamByteOutput;
+import org.jboss.marshalling.Pair;
+import org.jboss.remoting3.stream.ObjectSink;
+import org.jboss.remoting3.stream.ObjectSource;
+import org.jboss.remoting3.stream.Streams;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.Test;
+
+/**
+ *
+ */
+ at Test(suiteName = "streams")
+public final class StreamsTestCase {
+
+   private static Logger log = Logger.getLogger(StreamsTestCase.class);
+   
+    public void testCollectionObjectSink() throws Throwable {
+        final ArrayList<String> strings = new ArrayList<String>();
+        final ObjectSink<String> sink = Streams.getCollectionObjectSink(strings);
+        sink.accept("Instance 1");
+        sink.accept("Instance 2");
+        sink.accept("Instance 3");
+        sink.accept("Instance 4");
+        sink.accept("Instance 5");
+        sink.close();
+        final Iterator<String> i = strings.iterator();
+        assertEquals(i.next(), "Instance 1");
+        assertEquals(i.next(), "Instance 2");
+        assertEquals(i.next(), "Instance 3");
+        assertEquals(i.next(), "Instance 4");
+        assertEquals(i.next(), "Instance 5");
+        assertFalse(i.hasNext());
+    }
+
+    public void testCollectionObjectSinkRealTime() throws Throwable {
+       final ArrayList<String> strings = new ArrayList<String>();
+       final ObjectSink<String> sink = Streams.getCollectionObjectSink(strings);
+       sink.accept("Instance 1");
+       assertEquals(strings.get(0), "Instance 1");
+       sink.accept("Instance 2");
+       assertEquals(strings.get(1), "Instance 2");
+       sink.accept("Instance 3");
+       assertEquals(strings.get(2), "Instance 3");
+       sink.accept("Instance 4");
+       assertEquals(strings.get(3), "Instance 4");
+       sink.accept("Instance 5");
+       assertEquals(strings.get(4), "Instance 5");
+       sink.close();
+   }
+    
+    public void testIteratorObjectSource() throws Throwable {
+        final ObjectSource<String> source = Streams.getIteratorObjectSource(Arrays.asList("One", "Two", "Three", "Four", "Five").iterator());
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "One");
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "Two");
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "Three");
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "Four");
+        assertTrue(source.hasNext());
+        assertTrue(source.hasNext()); // tricky!
+        assertEquals(source.next(), "Five");
+        assertFalse(source.hasNext());
+        assertFalse(source.hasNext()); // also tricky!
+        source.close();
+        assertFalse(source.hasNext()); // also also tricky!
+        assertFalse(source.hasNext()); // also also also tricky!
+        try {
+            source.next();
+        } catch (EOFException t) {
+            return;
+        }
+        fail("No exception thrown at end of iterator");
+    }
+    
+    public void testCollectionObjectSource() throws Throwable {
+       final ObjectSource<String> source = Streams.getCollectionObjectSource(Arrays.asList("One", "Two", "Three", "Four", "Five"));
+       assertTrue(source.hasNext());
+       assertEquals(source.next(), "One");
+       assertTrue(source.hasNext());
+       assertEquals(source.next(), "Two");
+       assertTrue(source.hasNext());
+       assertEquals(source.next(), "Three");
+       assertTrue(source.hasNext());
+       assertEquals(source.next(), "Four");
+       assertTrue(source.hasNext());
+       assertTrue(source.hasNext()); // tricky!
+       assertEquals(source.next(), "Five");
+       assertFalse(source.hasNext());
+       assertFalse(source.hasNext()); // also tricky!
+       source.close();
+       assertFalse(source.hasNext()); // also also tricky!
+       assertFalse(source.hasNext()); // also also also tricky!
+       try {
+           source.next();
+       } catch (EOFException t) {
+           return;
+       }
+       fail("No exception thrown at end of iterator");
+    }
+    
+    public void testMapObjectSink() throws Throwable {
+       final HashMap<String, String> map = new HashMap<String, String>();
+       final ObjectSink<Pair<String, String>> sink = Streams.getMapObjectSink(map);
+       sink.accept(new Pair<String, String>("k1", "v1"));
+       sink.accept(new Pair<String, String>("k2", "v2"));
+       sink.accept(new Pair<String, String>("k3", "v3"));
+       sink.accept(new Pair<String, String>("k4", "v4"));
+       sink.accept(new Pair<String, String>("k5", "v5"));
+       sink.close();
+
+       assertEquals(5, map.keySet().size());
+       assertEquals(map.get("k1"), "v1");
+       assertEquals(map.get("k2"), "v2");
+       assertEquals(map.get("k3"), "v3");
+       assertEquals(map.get("k4"), "v4");
+       assertEquals(map.get("k5"), "v5");
+    }
+
+    
+    public void testMapObjectSinkRealTime() throws Throwable {
+       final HashMap<String, String> map = new HashMap<String, String>();
+       final ObjectSink<Pair<String, String>> sink = Streams.getMapObjectSink(map);
+       sink.accept(new Pair<String, String>("k1", "v1"));
+       assertEquals(1, map.keySet().size());
+       assertEquals(map.get("k1"), "v1");
+       sink.accept(new Pair<String, String>("k2", "v2"));
+       assertEquals(2, map.keySet().size());
+       assertEquals(map.get("k2"), "v2");
+       sink.accept(new Pair<String, String>("k3", "v3"));
+       assertEquals(3, map.keySet().size());
+       assertEquals(map.get("k3"), "v3");
+       sink.accept(new Pair<String, String>("k4", "v4"));
+       assertEquals(4, map.keySet().size());
+       assertEquals(map.get("k4"), "v4");
+       sink.accept(new Pair<String, String>("k5", "v5"));
+       assertEquals(5, map.keySet().size());
+       assertEquals(map.get("k5"), "v5");
+       sink.close();
+    }
+    
+    class A{
+       String s;
+       public A(String s) {
+          this.s = s;
+       }
+       public int hashCode() {
+          return s.hashCode();
+       }
+       public boolean equals(Object obj) {
+          if (obj == null || !(obj instanceof A)) {
+             return false;
+          }
+          return s.equals(((A) obj).s);
+       }
+    };
+    
+    class B extends A {
+       public B(String s) {
+          super(s);
+       }
+    };
+    
+    public void testCheckedObjectSink() throws Throwable {
+       
+       final HashSet<A> set = new HashSet<A>();
+       final ObjectSink<A> collectionObjectSink = Streams.getCollectionObjectSink(set);
+       final ObjectSink<A> sink = Streams.getCheckedObjectSink(collectionObjectSink, B.class);
+       
+       sink.accept(new B("Instance 1"));
+       sink.accept(new B("Instance 2"));
+       sink.accept(new B("Instance 3"));
+       sink.accept(new B("Instance 4"));
+       sink.accept(new B("Instance 5"));
+       sink.close();
+       
+       assertEquals(5, set.size());
+       assertTrue(set.contains(new B("Instance 1")));
+       assertTrue(set.contains(new B("Instance 2")));
+       assertTrue(set.contains(new B("Instance 3")));
+       assertTrue(set.contains(new B("Instance 4")));
+       assertTrue(set.contains(new B("Instance 5")));
+       
+       try {
+          sink.accept(new A("isn't a B"));
+          fail("sink shouldn't accept an A");
+       } catch (ClassCastException e) {
+         log.info(this + " got expected ClassCastException");
+       } catch (Throwable t) {
+          log.error(this + " expected ClassCastException, got " + t);
+       }
+    }
+    
+   public void testCheckedObjectSinkRealTime() throws Throwable {
+       
+       final HashSet<A> set = new HashSet<A>();
+       final ObjectSink<A> collectionObjectSink = Streams.getCollectionObjectSink(set);
+       final ObjectSink<A> sink = Streams.getCheckedObjectSink(collectionObjectSink, B.class);
+       
+       sink.accept(new B("Instance 1"));
+       assertEquals(1, set.size());
+       assertTrue(set.contains(new B("Instance 1")));
+       sink.accept(new B("Instance 2"));
+       assertEquals(2, set.size());
+       assertTrue(set.contains(new B("Instance 2")));       
+       sink.accept(new B("Instance 3"));
+       assertEquals(3, set.size());
+       assertTrue(set.contains(new B("Instance 3")));
+       sink.accept(new B("Instance 4"));
+       assertEquals(4, set.size());
+       assertTrue(set.contains(new B("Instance 4")));
+       sink.accept(new B("Instance 5"));
+       assertEquals(5, set.size());
+       assertTrue(set.contains(new B("Instance 5")));
+       
+       try {
+          sink.accept(new A("isn't a B"));
+          fail("sink shouldn't accept an A");
+       } catch (ClassCastException e) {
+         log.info(this + " got expected ClassCastException");
+       } catch (Throwable t) {
+          log.error(this + " expected ClassCastException, got " + t);
+       }
+       
+       sink.close();
+    }
+   
+   public void testMapEntryIteratorObjectSource() throws Throwable {
+      Map<String, String> map = new HashMap<String, String>();
+      map.put("1", "a");
+      map.put("2", "b");
+      map.put("3", "c");
+      map.put("4", "d");
+      map.put("5", "e");
+      final ObjectSource<Pair<String, String>> source = Streams.getMapEntryIteratorObjectSource(map.entrySet().iterator());
+      
+      assertTrue(source.hasNext());
+      Pair<String, String> entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertFalse(source.hasNext());
+      assertFalse(source.hasNext()); // also tricky!
+      source.close();
+      assertFalse(source.hasNext()); // also also tricky!
+      assertFalse(source.hasNext()); // also also also tricky!
+      try {
+          source.next();
+//      } catch (EOFException t) {
+      } catch (NoSuchElementException t) {
+          return;
+      }
+      fail("No exception thrown at end of iterator");
+   }
+   
+   public void testMapObjectSource() throws Throwable {
+      Map<String, String> map = new HashMap<String, String>();
+      map.put("1", "a");
+      map.put("2", "b");
+      map.put("3", "c");
+      map.put("4", "d");
+      map.put("5", "e");
+      final ObjectSource<Pair<String, String>> source = Streams.getMapObjectSource(map);
+      
+      assertTrue(source.hasNext());
+      Pair<String, String> entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertTrue(source.hasNext());
+      entry = source.next();
+      assertEquals(map.get(entry.getA()), entry.getB());
+      assertFalse(source.hasNext());
+      assertFalse(source.hasNext()); // also tricky!
+      source.close();
+      assertFalse(source.hasNext()); // also also tricky!
+      assertFalse(source.hasNext()); // also also also tricky!
+      try {
+          source.next();
+//      } catch (EOFException t) {
+      } catch (NoSuchElementException t) {
+          return;
+      }
+      fail("No exception thrown at end of iterator");
+   }
+   
+   public void testGetCollection() throws Throwable {
+      Set<String> set = new HashSet<String>();
+      set.add("1");
+      set.add("2");
+      set.add("3");
+      set.add("4");
+      set.add("5");
+      ObjectSource<String> source = Streams.getCollectionObjectSource(set);
+      source.close();
+      Collection<String> collection = Streams.getCollection(new ArrayList<String>(), source);
+      assertEquals(5, collection.size());
+      assertTrue(collection.contains("1"));
+      assertTrue(collection.contains("2"));
+      assertTrue(collection.contains("3"));
+      assertTrue(collection.contains("4"));
+      assertTrue(collection.contains("5"));
+   }
+   
+   public void testGetMap() throws Throwable {
+      Map<String, String> map = new HashMap<String, String>();
+      map.put("1", "a");
+      map.put("2", "b");
+      map.put("3", "c");
+      map.put("4", "d");
+      map.put("5", "e");
+      ObjectSource<Pair<String, String>> source = Streams.getMapObjectSource(map);
+      source.close();
+      Map<String, String> newMap = Streams.getMap(new TreeMap<String, String>(), source);
+      assertEquals(5, newMap.entrySet().size());
+      assertEquals("a", newMap.get("1"));
+      assertEquals("b", newMap.get("2"));
+      assertEquals("c", newMap.get("3"));
+      assertEquals("d", newMap.get("4"));
+      assertEquals("e", newMap.get("5"));
+   }
+   
+   public void testGetFutureCollection() throws Throwable {
+      Set<String> set = new HashSet<String>();
+      set.add("1");
+      set.add("2");
+      set.add("3");
+      set.add("4");
+      set.add("5");
+      ObjectSource<String> source = Streams.getCollectionObjectSource(set);
+      source.close();
+      Executor executor = new ThreadPoolExecutor(8, 64, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(64));
+      IoFuture<? extends Collection<String>> future = Streams.getFutureCollection(executor, new ArrayList<String>(), source);
+      Collection<String> collection= future.get();
+      assertEquals(5, collection.size());
+      assertTrue(collection.contains("1"));
+      assertTrue(collection.contains("2"));
+      assertTrue(collection.contains("3"));
+      assertTrue(collection.contains("4"));
+      assertTrue(collection.contains("5"));
+   }
+   
+   public void testGetFutureMap() throws Throwable {
+      Map<String, String> map = new HashMap<String, String>();
+      map.put("1", "a");
+      map.put("2", "b");
+      map.put("3", "c");
+      map.put("4", "d");
+      map.put("5", "e");
+      ObjectSource<Pair<String, String>> source = Streams.getMapObjectSource(map);
+      source.close();
+      Executor executor = new ThreadPoolExecutor(8, 64, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(64));
+      IoFuture<? extends Map<String, String>> future = Streams.getFutureMap(executor, new TreeMap<String, String>(), source);
+      Map<String, String> newMap = future.get();
+      assertEquals(5, newMap.entrySet().size());
+      assertEquals("a", newMap.get("1"));
+      assertEquals("b", newMap.get("2"));
+      assertEquals("c", newMap.get("3"));
+      assertEquals("d", newMap.get("4"));
+      assertEquals("e", newMap.get("5"));
+   }
+   
+    public void testEnumerationObjectSource() throws Throwable {
+        final ObjectSource<String> source = Streams.getEnumerationObjectSource(new Vector<String>(Arrays.asList("One", "Two", "Three", "Four", "Five")).elements());
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "One");
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "Two");
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "Three");
+        assertTrue(source.hasNext());
+        assertEquals(source.next(), "Four");
+        assertTrue(source.hasNext());
+        assertTrue(source.hasNext()); // tricky!
+        assertEquals(source.next(), "Five");
+        assertFalse(source.hasNext());
+        assertFalse(source.hasNext()); // also tricky!
+        source.close();
+        assertFalse(source.hasNext()); // also also tricky!
+        assertFalse(source.hasNext()); // also also also tricky!
+        try {
+            source.next();
+        } catch (EOFException t) {
+            return;
+        }
+        fail("No exception thrown at end of iterator");
+    }
+    
+    public void testCopyStream() throws Throwable {
+       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+       Streams.copyStream(new ByteArrayInputStream("This is a test!!!".getBytes()), baos);
+       assertEquals(new String(baos.toByteArray()), "This is a test!!!");
+    }
+    
+    public void testCopyStreamFromByteInput() throws Throwable {
+       ByteInput byteInput = new TestByteInput("This is a test!!!".getBytes());
+       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+       OutputStreamByteOutput outputStreamByteOutput = new OutputStreamByteOutput(baos);
+       Streams.copyStream(byteInput, outputStreamByteOutput);
+       assertEquals(new String(baos.toByteArray()), "This is a test!!!");
+    }
+    
+    static class TestByteInput implements ByteInput {
+       private ByteBufferInput byteBufferInput;
+       
+       public TestByteInput(byte[] bytes) {
+          ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
+          byteBuffer.put(bytes);
+          byteBuffer.flip();
+          byteBufferInput = new ByteBufferInput(byteBuffer);
+       }
+       public int available() throws IOException {
+          return byteBufferInput.available();
+       }
+       public int read() throws IOException {
+          return byteBufferInput.read();
+       }
+       public int read(byte[] b) throws IOException {
+          return byteBufferInput.read(b);
+       }
+       public int read(byte[] b, int off, int len) throws IOException {
+          return byteBufferInput.read(b, off, len);
+       }
+       public long skip(long n) throws IOException {
+          return byteBufferInput.skip(n);
+       }
+       public void close() throws IOException {
+          byteBufferInput.close();
+       }
+    }
+}



More information about the jboss-remoting-commits mailing list