/** * Returns an empty UnboundedFifoBuffer with a small capacity. * * @return an empty UnboundedFifoBuffer */ public Collection makeCollection() { return new UnboundedFifoBuffer(5); }
/** * Tests that the constructor correctly throws an exception. */ public void testConstructorException2() { try { new UnboundedFifoBuffer(-20); } catch (IllegalArgumentException ex) { return; } fail(); }
/** * Tests that the constructor correctly throws an exception. */ public void testConstructorException1() { try { new UnboundedFifoBuffer(0); } catch (IllegalArgumentException ex) { return; } fail(); }
public Object makeObject() { return BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); }
public Collection makeCollection() { return UnmodifiableBuffer.decorate(new UnboundedFifoBuffer()); }
public Collection makeCollection() { return SynchronizedBuffer.decorate(new UnboundedFifoBuffer()); }
public Collection makeFullCollection() { Buffer buffer = new UnboundedFifoBuffer(); buffer.addAll(Arrays.asList(getFullElements())); return SynchronizedBuffer.decorate(buffer); }
public void testAddAllToEmptyBufferExceedMaxSizeNoTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); try { bounded.addAll(Collections.nCopies(2, "test")); fail(); } catch (BufferOverflowException e) { } }
public Collection makeFullCollection() { Buffer buffer = new UnboundedFifoBuffer(); buffer.addAll(Arrays.asList(getFullElements())); return UnmodifiableBuffer.decorate(buffer); }
public void testAddAllToFullBufferNoTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); bounded.add( "Hello" ); try { bounded.addAll(Collections.singleton("World")); fail(); } catch (BufferOverflowException e) { } }
public void testAddToFullBufferNoTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); bounded.add( "Hello" ); try { bounded.add("World"); fail(); } catch (BufferOverflowException e) { } }
public void testInternalStateIteratorRemove2() { UnboundedFifoBuffer test = new UnboundedFifoBuffer(4); test.add("A"); test.add("B"); test.add("C"); Iterator it = test.iterator(); it.next(); it.next(); it.remove(); assertEquals(5, test.buffer.length); assertEquals(0, test.head); assertEquals(2, test.tail); test.add("D"); assertEquals(5, test.buffer.length); assertEquals(0, test.head); assertEquals(3, test.tail); }
public void testInternalStateIteratorRemoveWithTailAtEnd2() { UnboundedFifoBuffer test = new UnboundedFifoBuffer(3); test.add("A"); test.add("B"); test.add("C"); test.remove("A"); test.add("D"); assertEquals(4, test.buffer.length); assertEquals(1, test.head); assertEquals(0, test.tail); Iterator it = test.iterator(); assertEquals("B", it.next()); assertEquals("C", it.next()); it.remove(); assertEquals(4, test.buffer.length); assertEquals(1, test.head); assertEquals(3, test.tail); }
public void testAddAllToFullBufferRemoveViaIterator() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500); bounded.add( "Hello" ); bounded.add( "World" ); new DelayedIteratorRemove( bounded, 200, 2 ).start(); bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) ); assertEquals( 2, bounded.size() ); assertEquals( "Foo", bounded.remove() ); assertEquals( "Bar", bounded.remove() ); }
public void testInternalStateIteratorRemoveWithTailAtEnd1() { UnboundedFifoBuffer test = new UnboundedFifoBuffer(3); test.add("A"); test.add("B"); test.add("C"); test.remove("A"); test.add("D"); assertEquals(4, test.buffer.length); assertEquals(1, test.head); assertEquals(0, test.tail); Iterator it = test.iterator(); assertEquals("B", it.next()); it.remove(); assertEquals(4, test.buffer.length); assertEquals(2, test.head); assertEquals(0, test.tail); }
public void testAddToFullBufferRemoveViaIterator() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500); bounded.add( "Hello" ); new DelayedIteratorRemove( bounded, 200 ).start(); bounded.add( "World" ); assertEquals( 1, bounded.size() ); assertEquals( "World", bounded.get() ); }
public void testAddAllToFullBufferWithTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500); bounded.add( "Hello" ); bounded.add( "World" ); new DelayedRemove( bounded, 200, 2 ).start(); bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) ); assertEquals( 2, bounded.size() ); assertEquals( "Foo", bounded.get() ); try { bounded.add( "!" ); fail(); } catch( BufferOverflowException e ) { } }
public void testAddToFullBufferWithTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500); bounded.add( "Hello" ); new DelayedRemove( bounded, 200 ).start(); bounded.add( "World" ); assertEquals( 1, bounded.size() ); assertEquals( "World", bounded.get() ); try { bounded.add( "!" ); fail(); } catch( BufferOverflowException e ) { } }
public void testInternalStateRemove2() { UnboundedFifoBuffer test = new UnboundedFifoBuffer(4); test.add("A"); test.add("B"); test.add("C"); assertEquals(5, test.buffer.length); assertEquals(0, test.head); assertEquals(3, test.tail); test.remove("B"); assertEquals(5, test.buffer.length); assertEquals(0, test.head); assertEquals(2, test.tail); test.add("D"); assertEquals(5, test.buffer.length); assertEquals(0, test.head); assertEquals(3, test.tail); }
public void testInternalStateRemove1() { UnboundedFifoBuffer test = new UnboundedFifoBuffer(4); test.add("A"); test.add("B"); test.add("C"); assertEquals(5, test.buffer.length); assertEquals(0, test.head); assertEquals(3, test.tail); test.remove("A"); assertEquals(5, test.buffer.length); assertEquals(1, test.head); assertEquals(3, test.tail); test.add("D"); assertEquals(5, test.buffer.length); assertEquals(1, test.head); assertEquals(4, test.tail); }