Package org.jgroups.util

Examples of org.jgroups.util.BlockingInputStream


        getStateFromApplication(requester, bos, false);
    }

    protected Tuple<InputStream,Object> createStreamToProvider(final Address provider, final StateHeader hdr) {
        Util.close(input_stream);
        input_stream=new BlockingInputStream(buffer_size);
        return new Tuple<InputStream,Object>(input_stream, null);
    }
View Full Code Here


    }

   
    protected void createStreamToProvider(final Address provider, final StateHeader hdr) {
        Util.close(input_stream);
        input_stream=new BlockingInputStream(buffer_size);

        // use another thread to read state because the state requester has to receive state chunks from the state provider
        Thread t=getThreadFactory().newThread(new Runnable() {
            public void run() {
                setStateInApplication(provider, input_stream, hdr.getDigest());
View Full Code Here

@Test(groups=Global.FUNCTIONAL,sequential=false)
public class BlockingInputStreamTest {

   
    public void testCreation() throws IOException {
        BlockingInputStream in=new BlockingInputStream(2000);
        System.out.println("in = " + in);
        assert in.available() == 0 && in.capacity() == 2000;

        in.write(new byte[]{'b', 'e', 'l', 'a'});
        System.out.println("in = " + in);
        assert in.available() == 4 && in.capacity() == 2000;
    }
View Full Code Here

        assert in.available() == 4 && in.capacity() == 2000;
    }


    public void testRead() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        byte[] input={'B', 'e', 'l', 'a'};
        in.write(input);
        in.close();

        assert in.available() == 4;
        for(int i=0; i < input.length; i++) {
            int b=in.read();
            assert b == input[i];
        }
        int b=in.read();
        assert b == -1;
    }
View Full Code Here

        assert b == -1;
    }


    public void testBlockingReadAndClose() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        final CountDownLatch latch=new CountDownLatch(1);
        byte[] buf=new byte[100];
       
        new Closer(latch, in, 1000L).start(); // closes input stream after 1 sec
        latch.countDown();
        int num=in.read(buf, 0, buf.length);
        assert num == -1 : " expected -1 (EOF) but got " + num;
    }
View Full Code Here

        assert num == -1 : " expected -1 (EOF) but got " + num;
    }

   
    public void testBlockingWriteAndClose() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(3);
        final CountDownLatch latch=new CountDownLatch(1);
        byte[] buf={'B', 'e', 'l', 'a'};

        new Closer(latch, in, 1000L).start(); // closes input stream after 1 sec
        latch.countDown();
        in.write(buf, 0, buf.length);
    }
View Full Code Here

        in.write(buf, 0, buf.length);
    }


    public void testReadOnClosedInputStream() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        in.close();
        byte[] buf=new byte[100];
        int num=in.read(buf, 0, buf.length);
        assert num == -1 : " expected -1 (EOF) but got " + num;
    }
View Full Code Here

        assert num == -1 : " expected -1 (EOF) but got " + num;
    }

   
    public void testWriteCloseRead() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        for(int i=1; i <= 5; i++) {
            byte[] buf=("Hello world " + i).getBytes();
            in.write(buf);
        }
        in.close();

        int size=in.available();
        byte[] buf=new byte[100];
        int num=in.read(buf);
        assert num == size;
    }
View Full Code Here

        assert num == size;
    }


    public void testWriteCloseRead2() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(100);
        StringBuilder sb=new StringBuilder();
        for(int i=1; i <=10; i++)
            sb.append("Hello world " + i);
        byte[] buffer=sb.toString().getBytes();
        new Writer(in, buffer).start();
        Util.sleep(500);

        byte[] buf=new byte[200];
        int num=in.read(buf);
        assert num == buffer.length;
    }
View Full Code Here

        int num=in.read(buf);
        assert num == buffer.length;
    }

    public void testWriteCloseRead3() throws IOException {
        final BlockingInputStream in=new BlockingInputStream(300);
        StringBuilder sb=new StringBuilder();
        for(int i=1; i <=10; i++)
            sb.append("Hello world " + i);
        byte[] buffer=sb.toString().getBytes();
        new Writer(in, buffer).execute(); // don't use a separate thread

        byte[] buf=new byte[200];
        int num=in.read(buf);
        assert num == buffer.length;
    }
View Full Code Here

TOP

Related Classes of org.jgroups.util.BlockingInputStream

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.