sizetest.java

来自「JGRoups源码」· Java 代码 · 共 553 行 · 第 1/2 页

JAVA
553 行
字号
        rsp=new JoinRsp();        _testSize(rsp);        rsp=new JoinRsp(v, d);        _testSize(rsp);        rsp=new JoinRsp("this is a failure");        _testSize(rsp);    }    public void testGmsHeader() throws Exception {        IpAddress addr=new IpAddress("127.0.0.1", 5555);        GMS.GmsHeader hdr=new GMS.GmsHeader(GMS.GmsHeader.JOIN_REQ, addr);        _testSize(hdr);        Vector members=new Vector();        members.add(addr);        members.add(addr);        View v=new View(addr, 33, members);        hdr=new GMS.GmsHeader(GMS.GmsHeader.JOIN_RSP, v);        _testSize(hdr);    }    public void testFCHeader() throws Exception {        FC.FcHeader hdr=new FC.FcHeader(FC.FcHeader.REPLENISH);        _testSize(hdr);    }    public void testFragHeader() throws Exception {        FragHeader hdr=new FragHeader(322649, 1, 10);        _testSize(hdr);    }    public void testCompressHeader() throws Exception {        COMPRESS.CompressHeader hdr=new COMPRESS.CompressHeader(2002);        _testSize(hdr);    }    public void testStateHeader() throws Exception {        IpAddress addr=new IpAddress("127.0.0.1", 5555);        STATE_TRANSFER.StateHeader hdr;        hdr=new STATE_TRANSFER.StateHeader(STATE_TRANSFER.StateHeader.STATE_REQ, addr, 322649, null);        _testSize(hdr);        hdr=new STATE_TRANSFER.StateHeader(STATE_TRANSFER.StateHeader.STATE_REQ, addr, 322649, null, "my_state");        _testSize(hdr);        Digest digest=new Digest(2);        digest.add(addr, 100, 200, 205);        digest.add(new IpAddress(2314), 102, 104, 105);        hdr=new STATE_TRANSFER.StateHeader(STATE_TRANSFER.StateHeader.STATE_RSP, addr, 322649, digest);        _testSize(hdr);        hdr=new STATE_TRANSFER.StateHeader(STATE_TRANSFER.StateHeader.STATE_RSP, addr, 322649, digest, "my_state");        _testSize(hdr);    }    public void testEncryptHeader() throws Exception {        ENCRYPT.EncryptHeader hdr=new ENCRYPT.EncryptHeader((short)1, null);        _testSize(hdr);        hdr=new ENCRYPT.EncryptHeader((short)2, "Hello world");        _testSize(hdr);    }    public void testIpAddress() throws Exception {        IpAddress addr=new IpAddress();        _testSize(addr);    }    public void testIpAddress1() throws Exception {        IpAddress addr=new IpAddress("127.0.0.1", 5555);        _testSize(addr);    }    public void testIpAddress2() throws Exception {        IpAddress addr=new IpAddress(3456);        _testSize(addr);    }    public void testIpAddress3() throws Exception {        IpAddress addr=new IpAddress(5555, false);        _testSize(addr);    }    public void testIpAddressWithAdditionalData() throws Exception {        IpAddress addr=new IpAddress(5555, false);        addr.setAdditionalData("bela".getBytes());        _testSize(addr);    }    public void testRequestCorrelatorHeader() throws Exception {        RequestCorrelator.Header hdr;        hdr=new RequestCorrelator.Header(RequestCorrelator.Header.REQ, 322649, false, "HelloWorld");        _testSize(hdr);        hdr=new RequestCorrelator.Header(RequestCorrelator.Header.RSP, 322649, true, "bla");        java.util.List l=new LinkedList();        l.add(new IpAddress(1111));        l.add(new IpAddress(2222));        hdr.dest_mbrs=l;        hdr.callStack=new Stack();        hdr.callStack.push(new IpAddress(2222));        hdr.callStack.push(new IpAddress(3333));        _testSize(hdr);        hdr=new RequestCorrelator.Header(RequestCorrelator.Header.RSP, 322649, true, "bla");        hdr.callStack=new Stack();        hdr.callStack.push(new IpAddress(2222));        hdr.callStack.push(new IpAddress(3333));        ByteArrayOutputStream output=new ByteArrayOutputStream();        DataOutputStream out=new DataOutputStream(output);        hdr.writeTo(out);        out.flush();        byte[] buf=output.toByteArray();        out.close();        ByteArrayInputStream input=new ByteArrayInputStream(buf);        DataInputStream in=new DataInputStream(input);        hdr=new RequestCorrelator.Header();        hdr.readFrom(in);        System.out.println("call stack is " + hdr.callStack);        Address tmp=(Address)hdr.callStack.pop();        assertEquals(tmp, new IpAddress(3333));        tmp=(Address)hdr.callStack.pop();        assertEquals(tmp, new IpAddress(2222));        assertEquals(322649, hdr.id);        assertTrue(hdr.rsp_expected);        assertEquals("bla", hdr.corrName);        assertEquals(hdr.type, RequestCorrelator.Header.RSP);    }    public void testServiceInfo() throws Exception {        ServiceInfo si=new ServiceInfo();        _testSize(si);        si=new ServiceInfo(ServiceInfo.STATE_REQ, null, null, null);        _testSize(si);        si=new ServiceInfo(ServiceInfo.STATE_REQ, "bla", null, null);        _testSize(si);        si=new ServiceInfo(ServiceInfo.STATE_REQ, null, new IpAddress(3333), null);        _testSize(si);        si=new ServiceInfo(ServiceInfo.STATE_REQ, null, null, new byte[]{'b', 'e', 'l', 'a'});        _testSize(si);        si=new ServiceInfo(ServiceInfo.STATE_REQ, "bla", new IpAddress(3333), new byte[]{'b', 'e', 'l', 'a'});        _testSize(si);    }    public void testMuxHeader() throws Exception {        MuxHeader hdr=new MuxHeader();        _testSize(hdr);        hdr=new MuxHeader("bla");        _testSize(hdr);        ServiceInfo si=new ServiceInfo();        hdr=new MuxHeader(si);        _testSize(hdr);        si=new ServiceInfo(ServiceInfo.STATE_REQ, null, null, null);        _testSize(new MuxHeader(si));        si=new ServiceInfo(ServiceInfo.STATE_REQ, "bla", null, null);        _testSize(new MuxHeader(si));        si=new ServiceInfo(ServiceInfo.STATE_REQ, null, new IpAddress(3333), null);        _testSize(new MuxHeader(si));        si=new ServiceInfo(ServiceInfo.STATE_REQ, null, null, new byte[]{'b', 'e', 'l', 'a'});        _testSize(new MuxHeader(si));        si=new ServiceInfo(ServiceInfo.STATE_REQ, "bla", new IpAddress(3333), new byte[]{'b', 'e', 'l', 'a'});        _testSize(new MuxHeader(si));    }    private void _testSize(Header hdr) throws Exception {        long size=hdr.size();        byte[] serialized_form=Util.streamableToByteBuffer((Streamable)hdr);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(VIEW_SYNC.ViewSyncHeader hdr) throws Exception {        long size=hdr.size();        byte[] serialized_form=Util.streamableToByteBuffer(hdr);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);        VIEW_SYNC.ViewSyncHeader hdr2=(VIEW_SYNC.ViewSyncHeader)Util.streamableFromByteBuffer(VIEW_SYNC.ViewSyncHeader.class, serialized_form);        int my_type=hdr.getType(), other_type=hdr2.getType();        View my_view=hdr.getView(), other_view=hdr2.getView();        System.out.println("my_type=" + my_type + ", other_type=" + other_type);        System.out.println("my_view=" + my_view + ", other_view=" + other_view);        assertEquals(my_type, other_type);        assertEquals(my_view, other_view);    }     private void _testSize(Address addr) throws Exception {        long size=addr.size();        byte[] serialized_form=Util.streamableToByteBuffer(addr);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(ViewId vid) throws Exception {        long size=vid.serializedSize();        byte[] serialized_form=Util.streamableToByteBuffer(vid);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(View v) throws Exception {        long size=v.serializedSize();        byte[] serialized_form=Util.streamableToByteBuffer(v);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(Collection coll) throws Exception {        long size=Util.size(coll);        byte[] serialized_form=Util.collectionToByteBuffer(coll);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(JoinRsp rsp) throws Exception {        long size=rsp.serializedSize();        byte[] serialized_form=Util.streamableToByteBuffer(rsp);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(ServiceInfo si) throws Exception {        long size=si.size();        byte[] serialized_form=Util.streamableToByteBuffer(si);        System.out.println("size=" + size + ", serialized size=" + serialized_form.length);        assertEquals(serialized_form.length, size);    }    private void _testSize(MuxHeader hdr) throws Exception {         long size=hdr.size();         byte[] serialized_form=Util.streamableToByteBuffer(hdr);         System.out.println("size=" + size + ", serialized size=" + serialized_form.length);         assertEquals(serialized_form.length, size);     }    public static Test suite() {        return new TestSuite(SizeTest.class);    }    public static void main(String[] args) {        junit.textui.TestRunner.run(suite());    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?