Package org.jgroups.util

Examples of org.jgroups.util.Queue


        assert queue.size() == 0;
    }


    public static void testWaitUntilClosed2() {
        final Queue queue=new Queue();
        queue.close(true);
        try {
            queue.peek();
            assert false : "peek() should throw a QueueClosedException";
        }
        catch(QueueClosedException e) {
            assert e != null;
        }
        assert queue.size() == 0;
    }
View Full Code Here


        assert queue.size() == 0;
    }


    public static void testWaitUntilClosed3() throws QueueClosedException {
        final Queue queue=new Queue();
        queue.add("one");
        queue.close(true);
        Object obj=queue.peek();
        assert obj.equals("one");
        assert queue.size() == 1;
        queue.remove();
        try {
            queue.peek();
            assert false : "peek() should throw a QueueClosedException";
        }
        catch(QueueClosedException e) {
            assert e != null;
        }
        assert queue.size() == 0;
    }
View Full Code Here

        assert queue.size() == 0;
    }


    public static void testWaitUntilClosed4() throws QueueClosedException {
        final Queue queue=new Queue();
        for(int i=0; i < 10; i++)
            queue.add(new Integer(i));
        new Thread() {
            public void run() {
                while(!queue.closed()) {
                    try {
                        System.out.println("-- removed " + queue.remove());
                        Util.sleep(200);
                    }
                    catch(QueueClosedException e) {
                        break;
                    }
                }
            }
        }.start();
        queue.close(true);
        queue.waitUntilClosed(0);
        assert queue.size() == 0;
    }
View Full Code Here

    }



    public static void testWaitUntilClosed5() throws QueueClosedException {
        final Queue queue=new Queue();
        for(int i=0; i < 10; i++)
            queue.add(new Integer(i));
        new Thread() {
            public void run() {
                while(!queue.closed()) {
                    try {
                        System.out.println("-- removed " + queue.remove());
                        Util.sleep(200);
                    }
                    catch(QueueClosedException e) {
                        System.out.println("-- queue is closed, cannot remove element");
                        break;
                    }
                }
            }
        }.start();

        Util.sleep(600);
        queue.close(false);
        queue.waitUntilClosed(0);
        assert queue.size() > 0;
    }
View Full Code Here




    public static void testRemoveElementNoElement() {
        final Queue queue=new Queue();
        String s1="Q1";

        try {
            queue.removeElement(s1);
            assert !(queue.closed());
            assert queue.size() == 0;
        }
        catch(QueueClosedException ex) {
            assert false : ex.toString();
        }
    }
View Full Code Here

    }



    public static void testRemoveElementOneElement() {
        final Queue queue=new Queue();
        String s1="Q1";

        try {
            queue.add(s1);
            queue.removeElement(s1);
            assert queue.size() == 0;
            assert queue.getFirst() == null;
            assert queue.getLast() == null;
        }
        catch(QueueClosedException ex) {
            assert false : ex.toString();
        }
    }
View Full Code Here

    }


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

        try {
            queue.add(s1);
            queue.add(s2);
            queue.removeElement(s1);
            assert queue.size() == 1;
            assert queue.getFirst().equals(s2);
            assert queue.getLast().equals(s2);
            assert queue.getFirst().equals(queue.getLast());
        }
        catch(QueueClosedException ex) {
            assert false : ex.toString();
        }
    }
View Full Code Here

    }


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

        try {
            queue.add(s1);
            queue.add(s2);
            queue.removeElement(s2);
            assert queue.size() == 1;
            assert queue.getFirst().equals(s1);
            assert queue.getLast().equals(s1);
            assert queue.getFirst().equals(queue.getLast());
        }
        catch(QueueClosedException ex) {
            assert false : ex.toString();
        }
    }
View Full Code Here

    }


    public static void testRemoveElementThreeElementsFirstFound() {
        String s1="Q1", s2="Q2", s3="Q3";
        final Queue queue=new Queue();

        try {
            queue.add(s1);
            queue.add(s2);
            queue.add(s3);
            queue.removeElement(s1);
            assert queue.size() == 2;
            assert queue.getFirst().equals(s2);
            assert queue.getLast().equals(s3);
        }
        catch(QueueClosedException ex) {
            assert false : ex.toString();
        }
    }
View Full Code Here

    }


    public static void testRemoveElementThreeElementsSecondFound() {
        String s1="Q1", s2="Q2", s3="Q3";
        final Queue queue=new Queue();

        try {
            queue.add(s1);
            queue.add(s2);
            queue.add(s3);
            queue.removeElement(s2);
            assert queue.size() == 2;
            assert queue.getFirst().equals(s1);
            assert queue.getLast().equals(s3);
        }
        catch(QueueClosedException ex) {
            assert false : ex.toString();
        }
    }
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.