work, work.

This commit is contained in:
Arjen Poutsma
2015-06-30 13:45:54 +02:00
parent 342299abf6
commit c552aaa6f1
20 changed files with 1036 additions and 420 deletions

View File

@@ -16,15 +16,10 @@
package org.springframework.rx.io;
import java.io.EOFException;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Before;
import org.junit.Test;
import org.springframework.rx.util.BlockingByteBufQueue;
import org.springframework.rx.util.BlockingByteBufQueuePublisher;
import org.springframework.rx.util.BlockingSignalQueue;
import static org.junit.Assert.*;
@@ -33,25 +28,22 @@ import static org.junit.Assert.*;
*/
public class ByteBufPublisherInputStreamTests {
private BlockingByteBufQueue queue;
private BlockingSignalQueue<byte[]> queue;
private ByteBufPublisherInputStream is;
private ByteArrayPublisherInputStream is;
@Before
public void setUp() throws Exception {
queue = new BlockingByteBufQueue();
is = new ByteBufPublisherInputStream(queue);
queue = new BlockingSignalQueue<byte[]>();
is = new ByteArrayPublisherInputStream(queue);
}
@Test
public void readSingleByte() throws Exception {
ByteBuf abc = Unpooled.copiedBuffer(new byte[]{'a', 'b', 'c'});
ByteBuf def = Unpooled.copiedBuffer(new byte[]{'d', 'e', 'f'});
queue.putBuffer(abc);
queue.putBuffer(def);
queue.putSignal(new byte[]{'a', 'b', 'c'});
queue.putSignal(new byte[]{'d', 'e', 'f'});
queue.complete();
@@ -75,11 +67,8 @@ public class ByteBufPublisherInputStreamTests {
@Test
public void readBytes() throws Exception {
ByteBuf abc = Unpooled.copiedBuffer(new byte[]{'a', 'b', 'c'});
ByteBuf def = Unpooled.copiedBuffer(new byte[]{'d', 'e', 'f'});
queue.putBuffer(abc);
queue.putBuffer(def);
queue.putSignal(new byte[]{'a', 'b', 'c'});
queue.putSignal(new byte[]{'d', 'e', 'f'});
queue.complete();
byte[] buf = new byte[2];

View File

@@ -33,14 +33,14 @@ import org.reactivestreams.Subscription;
*/
public class BlockingByteBufQueuePublisherTests {
private BlockingByteBufQueue queue;
private BlockingSignalQueue queue;
private BlockingByteBufQueuePublisher publisher;
private BlockingSignalQueuePublisher publisher;
@Before
public void setUp() throws Exception {
queue = new BlockingByteBufQueue();
publisher = new BlockingByteBufQueuePublisher(queue);
queue = new BlockingSignalQueue();
publisher = new BlockingSignalQueuePublisher(queue);
}
@Test
@@ -48,8 +48,8 @@ public class BlockingByteBufQueuePublisherTests {
ByteBuf abc = Unpooled.copiedBuffer(new byte[]{'a', 'b', 'c'});
ByteBuf def = Unpooled.copiedBuffer(new byte[]{'d', 'e', 'f'});
queue.putBuffer(abc);
queue.putBuffer(def);
queue.putSignal(abc);
queue.putSignal(def);
queue.complete();
final AtomicBoolean complete = new AtomicBoolean(false);
@@ -90,8 +90,8 @@ public class BlockingByteBufQueuePublisherTests {
ByteBuf abc = Unpooled.copiedBuffer(new byte[]{'a', 'b', 'c'});
ByteBuf def = Unpooled.copiedBuffer(new byte[]{'d', 'e', 'f'});
queue.putBuffer(abc);
queue.putBuffer(def);
queue.putSignal(abc);
queue.putSignal(def);
queue.complete();
final AtomicBoolean complete = new AtomicBoolean(false);

View File

@@ -27,11 +27,11 @@ import org.junit.Test;
*/
public class BlockingByteBufQueueTests {
private BlockingByteBufQueue queue;
private BlockingSignalQueue queue;
@Before
public void setUp() throws Exception {
queue = new BlockingByteBufQueue();
queue = new BlockingSignalQueue();
}
@Test
@@ -39,41 +39,37 @@ public class BlockingByteBufQueueTests {
ByteBuf abc = Unpooled.copiedBuffer(new byte[]{'a', 'b', 'c'});
ByteBuf def = Unpooled.copiedBuffer(new byte[]{'d', 'e', 'f'});
queue.putBuffer(abc);
queue.putBuffer(def);
queue.putSignal(abc);
queue.putSignal(def);
queue.complete();
assertTrue(queue.isHeadBuffer());
assertTrue(queue.isHeadSignal());
assertFalse(queue.isHeadError());
assertSame(abc, queue.pollBuffer());
assertSame(abc, queue.pollSignal());
assertTrue(queue.isHeadBuffer());
assertTrue(queue.isHeadSignal());
assertFalse(queue.isHeadError());
assertSame(def, queue.pollBuffer());
assertSame(def, queue.pollSignal());
assertTrue(queue.isComplete());
}
@Test
public void empty() throws Exception {
assertNull(queue.pollBuffer());
}
@Test
public void error() throws Exception {
ByteBuf abc = Unpooled.copiedBuffer(new byte[]{'a', 'b', 'c'});
Throwable error = new IllegalStateException();
queue.putBuffer(abc);
queue.putSignal(abc);
queue.putError(error);
queue.complete();
assertTrue(queue.isHeadBuffer());
assertTrue(queue.isHeadSignal());
assertFalse(queue.isHeadError());
assertSame(abc, queue.pollBuffer());
assertSame(abc, queue.pollSignal());
assertTrue(queue.isHeadError());
assertFalse(queue.isHeadBuffer());
assertFalse(queue.isHeadSignal());
assertSame(error, queue.pollError());
assertTrue(queue.isComplete());