Package org.apache.commons.collections15.buffer

Examples of org.apache.commons.collections15.buffer.SynchronizedBuffer


     * complete. The remaining thread should complete after the
     * addition of a second singleton.
     */
    public void testBlockedRemoveWithAddAll1() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();
       
        // run methods will remove and compare -- must wait for addAll
        Thread thread1 = new ReadThread(blockingBuffer, obj, null, "remove");
        Thread thread2 = new ReadThread(blockingBuffer, obj, null, "remove");
        thread1.start();
        thread2.start();
       
        // give hungry read threads ample time to hang
        delay();

        blockingBuffer.addAll(Collections.singleton(obj));
       
        // allow notified threads to complete
        delay();
       
        // There should be one thread waiting.
        assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive());

        blockingBuffer.addAll(Collections.singleton(obj));
       
        // allow notified thread to complete
        delay();

        // There should not be any threads waiting.
View Full Code Here


     * threads should complete. Each thread should have read a
     * different object.
     */
    public void testBlockedRemoveWithAddAll2() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj1 = new Object();
        Object obj2 = new Object();

        Set objs = Collections.synchronizedSet(new HashSet());
        objs.add(obj1);
        objs.add(obj2);

        // run methods will remove and compare -- must wait for addAll
        Thread thread1 = new ReadThread(blockingBuffer, objs, "remove");
        Thread thread2 = new ReadThread(blockingBuffer, objs, "remove");
        thread1.start();
        thread2.start();
       
        // give hungry read threads ample time to hang
        delay();

        blockingBuffer.addAll(objs);
       
        // allow notified threads to complete
        delay();

        assertEquals("Both objects were removed", 0, objs.size());
View Full Code Here

    /**
     * Tests interrupted remove.
     */
    public void testInterruptedRemove() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();
       
        // spawn a read thread to wait on the empty buffer
        ArrayList exceptionList = new ArrayList();
        Thread thread = new ReadThread(blockingBuffer, obj, exceptionList, "remove");
View Full Code Here

    public Collection makeCollection() {
        return UnmodifiableBuffer.decorate(new UnboundedFifoBuffer());
    }

    public Collection makeFullCollection() {
        Buffer buffer = new UnboundedFifoBuffer();
        buffer.addAll(Arrays.asList(getFullElements()));
        return UnmodifiableBuffer.decorate(buffer);
    }
View Full Code Here

        return false;
    }

    public void testBufferRemove() {
        resetEmpty();
        Buffer buffer = (Buffer) collection;
        try {
            buffer.remove();
            fail();
        } catch (UnsupportedOperationException ex) {
        }
    }
View Full Code Here

    public void testCircularFifoBufferCircular() {
        List list = new ArrayList();
        list.add("A");
        list.add("B");
        list.add("C");
        Buffer buf = new CircularFifoBuffer(list);

        assertEquals(true, buf.contains("A"));
        assertEquals(true, buf.contains("B"));
        assertEquals(true, buf.contains("C"));

        buf.add("D");

        assertEquals(false, buf.contains("A"));
        assertEquals(true, buf.contains("B"));
        assertEquals(true, buf.contains("C"));
        assertEquals(true, buf.contains("D"));

        assertEquals("B", buf.get());
        assertEquals("B", buf.remove());
        assertEquals("C", buf.remove());
        assertEquals("D", buf.remove());
    }
View Full Code Here

    }

    //----------------------------------------------------------------------- 
    public void testBufferEmpty() {
        resetEmpty();
        Buffer buffer = (Buffer) collection;

        assertEquals(0, buffer.size());
        assertEquals(true, buffer.isEmpty());
        try {
            buffer.get();
            fail();
        } catch (BufferUnderflowException ex) {
        }

        try {
            buffer.remove();
            fail();
        } catch (BufferUnderflowException ex) {
        }
    }
View Full Code Here

    public Collection makeCollection() {
        return SynchronizedBuffer.decorate(new UnboundedFifoBuffer());
    }

    public Collection makeFullCollection() {
        Buffer buffer = new UnboundedFifoBuffer();
        buffer.addAll(Arrays.asList(getFullElements()));
        return SynchronizedBuffer.decorate(buffer);
    }
View Full Code Here

    public Buffer makeTestBuffer() {
        return decorateBuffer(new ArrayStack(), testPredicate);
    }

    public void testGet() {
        Buffer buffer = makeTestBuffer();
        try {
            Object o = buffer.get();
            fail("Expecting BufferUnderflowException");
        } catch (BufferUnderflowException ex) {
            // expected
        }
        buffer.add("one");
        buffer.add("two");
        buffer.add("three");
        assertEquals("Buffer get", buffer.get(), "three");
    }
View Full Code Here

        buffer.add("three");
        assertEquals("Buffer get", buffer.get(), "three");
    }

    public void testRemove() {
        Buffer buffer = makeTestBuffer();
        buffer.add("one");
        assertEquals("Buffer get", buffer.remove(), "one");
        try {
            buffer.remove();
            fail("Expecting BufferUnderflowException");
        } catch (BufferUnderflowException ex) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.collections15.buffer.SynchronizedBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.