Package org.jgroups.util

Examples of org.jgroups.util.Queue


public class QueueTest {



    public static void testQueue() throws QueueClosedException {
        final Queue queue=new Queue();
        queue.add("Q1");
        queue.add("Q2");
        queue.add("Q3");

        assert queue.peek().equals("Q1");
        assert queue.remove().equals("Q1");

        assert queue.peek().equals("Q2");
        assert queue.remove().equals("Q2");
        queue.add("Q5");

        queue.close(true);

        try {
            queue.add("Q6");
            assert false : "should not get here";
        }
        catch(org.jgroups.util.QueueClosedException qc) {
        }

        int size=queue.size();
        queue.removeElement("Q5");
        assert queue.size() == size -1;
        assert queue.peek().equals("Q3");
        assert queue.remove().equals("Q3");
        assert queue.closed();
    }
View Full Code Here


    }


    @Test(expectedExceptions=QueueClosedException.class)
    public static void testCloseWithoutFlush() throws QueueClosedException {
        final Queue queue=new Queue();
        queue.close(false);
        queue.remove();
    }
View Full Code Here

    }


    @Test(expectedExceptions=QueueClosedException.class)
    public static void testCloseWithFlush() throws QueueClosedException {
        final Queue queue=new Queue();
        queue.close(true);
        queue.remove();
    }
View Full Code Here

    }


    @Test(expectedExceptions=QueueClosedException.class)
    public static void testCloseWithFlush2() throws QueueClosedException {
        final Queue queue=new Queue();
        queue.add(new Integer(1));
        queue.add(new Integer(2));
        queue.add(new Integer(3));
        queue.close(true);
        for(int i=1; i <= 3; i++) {
            Object obj=queue.remove();
            assert obj != null;
            assert new Integer(i).equals(obj);
        }
        queue.remove();
    }
View Full Code Here

    }



    public static void testValues() throws QueueClosedException {
        final Queue queue=new Queue();
        queue.add(new Integer(1));
        queue.add(new Integer(3));
        queue.add(new Integer(99));
        queue.add(new Integer(8));
        System.out.println("queue: " + Util.dumpQueue(queue));
        int size=queue.size();
        assert size == 4;
        LinkedList values=queue.values();
        assert values.size() == size;
    }
View Full Code Here


    public static void testLargeInsertion() throws QueueClosedException {
        String element="MyElement";
        long start, stop;
        final Queue queue=new Queue();

        System.out.println("Inserting 100000 elements");
        start=System.currentTimeMillis();
        for(int i=0; i < 100000; i++)
            queue.add(element);
        stop=System.currentTimeMillis();
        System.out.println("Took " + (stop - start) + " msecs");

        System.out.println("Removing 100000 elements");
        start=System.currentTimeMillis();
        while(queue.size() > 0)
            queue.remove();
        stop=System.currentTimeMillis();
        System.out.println("Took " + (stop - start) + " msecs");
    }
View Full Code Here

    }



    public static void testEmptyQueue() {
        final Queue queue=new Queue();
        assert queue.getFirst() == null;
        assert queue.getLast() == null;
    }
View Full Code Here

        assert queue.getLast() == null;
    }


    public static void testAddAll() throws QueueClosedException {
        final Queue queue=new Queue();
        List<String> l=new ArrayList<String>();
        l.add("one");
        l.add("two");
        l.add("three");
        queue.addAll(l);
        System.out.println("queue is " + queue);
        assert queue.size() == 3;
        assert queue.remove().equals("one");
        assert queue.size() == 2;
        assert queue.remove().equals("two");
        assert queue.size() == 1;
        assert queue.remove().equals("three");
        assert queue.size() == 0;
    }
View Full Code Here

        assert queue.size() == 0;
    }


    public static void testInsertionAndRemoval() throws Exception {
        final Queue queue=new Queue();
        String s1="Q1", s2="Q2";

        queue.add(s1);
        assert queue.getFirst() != null;
        assert queue.getLast() != null;
        assert queue.getLast().equals(queue.getFirst());

        queue.add(s2);
        assert queue.getFirst() != queue.getLast();

        Object o1=queue.peek();
        Object o2=queue.getFirst();

        System.out.println("o1=" + o1 + ", o2=" + o2 + ", o1.equals(o2)=" + o1.equals(o2));

        assert queue.getFirst().equals(queue.peek());
        queue.remove();

        assert queue.size() == 1;
        assert queue.getLast().equals(queue.getFirst());
        queue.remove();

        assert queue.size() == 0;
        assert queue.getFirst() == null;
        assert queue.getLast() == null;
    }
View Full Code Here

    }



    public static void testWaitUntilClosed() {
        final Queue queue=new Queue();
        queue.close(true);
        queue.waitUntilClosed(0);
        assert queue.size() == 0;
    }
View Full Code Here

TOP

Related Classes of org.jgroups.util.Queue

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.