Author: david.lloyd(a)jboss.com
Date: 2008-07-03 19:31:26 -0400 (Thu, 03 Jul 2008)
New Revision: 4352
Added:
remoting3/trunk/api/src/test/
remoting3/trunk/api/src/test/java/
remoting3/trunk/api/src/test/java/org/
remoting3/trunk/api/src/test/java/org/jboss/
remoting3/trunk/api/src/test/java/org/jboss/cx/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java
Log:
Add some tests to the api module, plus extra test support
Added:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
===================================================================
---
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
(rev 0)
+++
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,93 @@
+/*
+ * 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.cx.remoting.spi.marshal;
+
+import junit.framework.TestCase;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Arrays;
+
+/**
+ *
+ */
+public final class ObjectResolverTestCase extends TestCase {
+ public static final class ThingOne {
+
+ }
+
+ public static final class ThingTwo {
+
+ }
+
+ public static final class ResolverOne implements ObjectResolver {
+
+ private static final long serialVersionUID = 6121192940632885123L;
+
+ public Object writeReplace(final Object original) throws IOException {
+ if (original instanceof ThingOne) {
+ return "ThingOne";
+ } else {
+ return original;
+ }
+ }
+
+ public Object readResolve(final Object original) throws IOException {
+ if (original instanceof String &&
"ThingOne".equals(original)) {
+ return new ThingOne();
+ } else {
+ return original;
+ }
+ }
+ }
+
+ public static final class ResolverTwo implements ObjectResolver {
+
+ private static final long serialVersionUID = 7833685858039930273L;
+
+ public Object writeReplace(final Object original) throws IOException {
+ if (original instanceof ThingTwo) {
+ return "ThingTwo";
+ } else {
+ return original;
+ }
+ }
+
+ public Object readResolve(final Object original) throws IOException {
+ if (original instanceof String &&
"ThingTwo".equals(original)) {
+ return new ThingTwo();
+ } else {
+ return original;
+ }
+ }
+ }
+
+ public void testCompositeResolver() throws Throwable {
+ final CompositeObjectResolver compositeObjectResolver = new
CompositeObjectResolver(Arrays.asList(new ResolverOne(), new ResolverTwo()));
+ assertEquals(compositeObjectResolver.writeReplace("Test"),
"Test");
+ assertEquals(compositeObjectResolver.writeReplace(new ThingOne()),
"ThingOne");
+ assertEquals(compositeObjectResolver.writeReplace(new ThingTwo()),
"ThingTwo");
+ assertEquals(compositeObjectResolver.readResolve("Test"),
"Test");
+ assertTrue(compositeObjectResolver.readResolve("ThingOne") instanceof
ThingOne);
+ assertTrue(compositeObjectResolver.readResolve("ThingTwo") instanceof
ThingTwo);
+ }
+}
Added:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
===================================================================
---
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
(rev 0)
+++
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,84 @@
+/*
+ * 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.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import java.util.Arrays;
+import java.nio.ByteBuffer;
+import org.jboss.cx.remoting.test.support.TestByteBufferAllocator;
+
+/**
+ *
+ */
+public final class ByteBufferInputStreamTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestByteBufferAllocator allocator = new TestByteBufferAllocator(3);
+ final ByteBufferInputStream stream = new
ByteBufferInputStream(Streams.<ByteBuffer>getIteratorObjectSource(Arrays.<ByteBuffer>asList(
+ ByteBuffer.wrap(new byte[] { 5, 100, 30, 12, -60, 25 }),
+ ByteBuffer.wrap(new byte[] { 15 }),
+ ByteBuffer.wrap(new byte[] { }),
+ ByteBuffer.wrap(new byte[] { 100, 0, 0, -128, 127, 0 })).iterator()),
allocator);
+ assertEquals(5, stream.read());
+ assertEquals(100, stream.read());
+ assertEquals(30, stream.read());
+ assertEquals(12, stream.read());
+ assertEquals(-60 & 0xff, stream.read());
+ assertEquals(25, stream.read());
+ assertEquals(15, stream.read());
+ assertEquals(100, stream.read());
+ assertEquals(0, stream.read());
+ assertEquals(0, stream.read());
+ assertEquals(-128 & 0xff, stream.read());
+ assertEquals(127, stream.read());
+ assertEquals(0, stream.read());
+ assertEquals(-1, stream.read());
+ assertEquals(-1, stream.read());
+ // I fed it four buffers, so there should be -4
+ allocator.check(-4);
+ }
+
+ public void testArrayRead() throws Throwable {
+ final TestByteBufferAllocator allocator = new TestByteBufferAllocator(3);
+ final ByteBufferInputStream stream = new
ByteBufferInputStream(Streams.<ByteBuffer>getIteratorObjectSource(Arrays.<ByteBuffer>asList(
+ ByteBuffer.wrap(new byte[] { 5, 100, 30, 12, -60, 25 }),
+ ByteBuffer.wrap(new byte[] { 15 }),
+ ByteBuffer.wrap(new byte[] { }),
+ ByteBuffer.wrap(new byte[] { 100, 0, 0, -128, 127, 0 })).iterator()),
allocator);
+ assertEquals(5, stream.read());
+ assertEquals(100, stream.read());
+ assertEquals(30, stream.read());
+ byte[] bytes = new byte[5];
+ assertEquals(5, stream.read(bytes));
+ assertTrue(Arrays.equals(new byte[] { 12, -60, 25, 15, 100 }, bytes));
+ assertEquals(0, stream.read());
+ bytes = new byte[15];
+ Arrays.fill(bytes, (byte) 7);
+ assertEquals(3, stream.read(bytes, 4, 3));
+ assertTrue(Arrays.equals(new byte[] { 7, 7, 7, 7, 0, -128, 127, 7, 7, 7, 7, 7, 7,
7, 7 }, bytes));
+ assertEquals(0, stream.read());
+ assertEquals(-1, stream.read());
+ assertEquals(-1, stream.read());
+ // I fed it four buffers, so there should be -4
+ allocator.check(-4);
+ }
+}
Added:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
===================================================================
---
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
(rev 0)
+++
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,74 @@
+/*
+ * 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.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import org.jboss.cx.remoting.test.support.TestByteBufferAllocator;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public final class ByteBufferOutputStreamTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestByteBufferAllocator allocator = new TestByteBufferAllocator(4);
+ final List<ByteBuffer> list = new ArrayList<ByteBuffer>();
+ final ObjectSink<ByteBuffer> sink = Streams.getCollectionObjectSink(list);
+ final ByteBufferOutputStream stream = new ByteBufferOutputStream(sink,
allocator);
+ stream.write(new byte[] { 6, 1, 5, 2, 4, 3, 2, 4, 1, 5, 0, 6 });
+ stream.write(new byte[0]);
+ stream.write(new byte[] { 4, 5, 6, 45, -20, 0, 0, 1, 12, 13, 19, 34 }, 3, 7);
+ stream.write(new byte[] { 45, -20, 0, 0, 1, 12, 13 }, 4, 0);
+ stream.write(0);
+ stream.write(10);
+ stream.flush();
+ stream.close();
+ final ByteBufferInputStream inputStream = new
ByteBufferInputStream(Streams.getIteratorObjectSource(list.iterator()), allocator);
+ assertEquals(6, inputStream.read());
+ assertEquals(1, inputStream.read());
+ assertEquals(5, inputStream.read());
+ assertEquals(2, inputStream.read());
+ assertEquals(4, inputStream.read());
+ assertEquals(3, inputStream.read());
+ assertEquals(2, inputStream.read());
+ assertEquals(4, inputStream.read());
+ assertEquals(1, inputStream.read());
+ assertEquals(5, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(6, inputStream.read());
+ assertEquals(45, inputStream.read());
+ assertEquals(-20 & 0xff, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(1, inputStream.read());
+ assertEquals(12, inputStream.read());
+ assertEquals(13, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(10, inputStream.read());
+ assertEquals(-1, inputStream.read());
+ inputStream.close();
+ allocator.check(0);
+ }
+}
Added:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
===================================================================
---
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
(rev 0)
+++
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,52 @@
+/*
+ * 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.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import org.jboss.cx.remoting.test.support.TestCharBufferAllocator;
+import java.util.Arrays;
+import java.nio.CharBuffer;
+
+/**
+ *
+ */
+public final class CharBufferReaderTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestCharBufferAllocator allocator = new TestCharBufferAllocator(10);
+ final ObjectSource<CharBuffer> source =
Streams.getIteratorObjectSource(Arrays.asList(
+ CharBuffer.wrap("The quick brown "),
+ CharBuffer.wrap("fox j"),
+ CharBuffer.wrap("u"),
+ CharBuffer.allocate(0),
+ CharBuffer.wrap("mps over the la"),
+ CharBuffer.wrap("zy dogs.")
+ ).iterator());
+ CharBufferReader reader = new CharBufferReader(source, allocator);
+ String s = "The quick brown fox jumps over the lazy dogs.";
+ for (int i = 0; i < s.length(); i ++) {
+ assertEquals(s.charAt(i), reader.read());
+ }
+ assertEquals(-1, reader.read());
+ allocator.check(-6);
+ }
+}
Added:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
===================================================================
---
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
(rev 0)
+++
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,59 @@
+/*
+ * 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.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.List;
+import java.nio.CharBuffer;
+import org.jboss.cx.remoting.test.support.TestCharBufferAllocator;
+
+/**
+ *
+ */
+public final class CharBufferWriterTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestCharBufferAllocator allocator = new TestCharBufferAllocator(7);
+ final List<CharBuffer> list = new ArrayList<CharBuffer>();
+ final ObjectSink<CharBuffer> sink = Streams.getCollectionObjectSink(list);
+ final CharBufferWriter writer = new CharBufferWriter(sink, allocator);
+ writer.append("Th");
+ writer.append("blah e qui blah", 5, 10);
+ writer.append('c');
+ writer.write('k');
+ writer.write(new char[] { ' ', 'b', 'r' });
+ writer.write(new char[] { 'x', 'x', 'o', 'w',
'n', ' ', 'x' }, 2, 4);
+ writer.write("fox jumps");
+ writer.write("blah over the lazy dogs. blah", 4, 20);
+ writer.flush();
+ writer.close();
+ final ObjectSource<CharBuffer> source =
Streams.getIteratorObjectSource(list.iterator());
+ CharBufferReader reader = new CharBufferReader(source, allocator);
+ String s = "The quick brown fox jumps over the lazy dogs.";
+ for (int i = 0; i < s.length(); i ++) {
+ assertEquals("position = " + i, (char)s.charAt(i),
(char)reader.read());
+ }
+ assertEquals(-1, reader.read());
+ allocator.check(0);
+ }
+}
Added:
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
(rev 0)
+++
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,105 @@
+/*
+ * 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.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.util.Vector;
+import java.io.EOFException;
+
+/**
+ *
+ */
+public final class StreamsTestCase extends TestCase {
+ 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/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java
===================================================================
---
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java
(rev 0)
+++
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,58 @@
+/*
+ * 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.cx.remoting.test.support;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.xnio.BufferAllocator;
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public final class TestByteBufferAllocator implements BufferAllocator<ByteBuffer>
{
+
+ private final AtomicInteger count = new AtomicInteger();
+ private final int size;
+
+ public TestByteBufferAllocator(final int size) {
+ this.size = size;
+ }
+
+ public ByteBuffer allocate() {
+ final ByteBuffer buffer = ByteBuffer.allocate(size);
+ count.incrementAndGet();
+ return buffer;
+ }
+
+ public void free(final ByteBuffer buffer) {
+ if (buffer == null) {
+ throw new NullPointerException("buffer is null");
+ }
+ count.decrementAndGet();
+ }
+
+ public void check(int expectCount) {
+ TestCase.assertEquals(expectCount, count.get());
+ }
+}
Added:
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java
===================================================================
---
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java
(rev 0)
+++
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java 2008-07-03
23:31:26 UTC (rev 4352)
@@ -0,0 +1,58 @@
+/*
+ * 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.cx.remoting.test.support;
+
+import java.nio.CharBuffer;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.xnio.BufferAllocator;
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public final class TestCharBufferAllocator implements BufferAllocator<CharBuffer>
{
+
+ private final AtomicInteger count = new AtomicInteger();
+ private final int size;
+
+ public TestCharBufferAllocator(final int size) {
+ this.size = size;
+ }
+
+ public CharBuffer allocate() {
+ final CharBuffer buffer = CharBuffer.allocate(size);
+ count.incrementAndGet();
+ return buffer;
+ }
+
+ public void free(final CharBuffer buffer) {
+ if (buffer == null) {
+ throw new NullPointerException("buffer is null");
+ }
+ count.decrementAndGet();
+ }
+
+ public void check(int expectCount) {
+ TestCase.assertEquals(expectCount, count.get());
+ }
+}
\ No newline at end of file