Package org.jgroups.util

Examples of org.jgroups.util.MutableDigest


    public void testMerge() {
        Map<Address, Digest.Entry> map=new HashMap<Address, Digest.Entry>();
        map.put(a1, new Digest.Entry(3, 499, 502));
        map.put(a2, new Digest.Entry(20, 26, 27));
        map.put(a3, new Digest.Entry(21, 26, 35));
        MutableDigest digest=new MutableDigest(map);

        System.out.println("d: " + d);
        System.out.println("digest: " + digest);
       
        digest.merge(d);
        System.out.println("merged digest: " + digest);

        Assert.assertEquals(3, d.size());
        Assert.assertEquals(3, digest.size());

        Assert.assertEquals(3, digest.lowSeqnoAt(a1));
        Assert.assertEquals(500, digest.highestDeliveredSeqnoAt(a1));
        Assert.assertEquals(502, digest.highestReceivedSeqnoAt(a1));

        Assert.assertEquals(20, digest.lowSeqnoAt(a2));
        Assert.assertEquals(26, digest.highestDeliveredSeqnoAt(a2));
        Assert.assertEquals(27, digest.highestReceivedSeqnoAt(a2));

        Assert.assertEquals(20, digest.lowSeqnoAt(a3));
        Assert.assertEquals(26, digest.highestDeliveredSeqnoAt(a3));
        Assert.assertEquals(35, digest.highestReceivedSeqnoAt(a3));
    }
View Full Code Here


        Assert.assertEquals(35, digest.highestReceivedSeqnoAt(a3));
    }


    public void testNonConflictingMerge() {
        MutableDigest cons_d=new  MutableDigest(5);
        Address ip1=Util.createRandomAddress(), ip2=Util.createRandomAddress();

        cons_d.add(ip1, 1, 10, 10);
        cons_d.add(ip2, 2, 20, 20);
        // System.out.println("\ncons_d before: " + cons_d);
        cons_d.merge(d);

        Assert.assertEquals(5, cons_d.size());
        //System.out.println("\ncons_d after: " + cons_d);
        Assert.assertEquals(1, cons_d.lowSeqnoAt(ip1));
        Assert.assertEquals(2, cons_d.lowSeqnoAt(ip2));
        Assert.assertEquals(4, cons_d.lowSeqnoAt(a1));
        Assert.assertEquals(25, cons_d.lowSeqnoAt(a2));
        Assert.assertEquals(20, cons_d.lowSeqnoAt(a3));

        Assert.assertEquals(10, cons_d.highestDeliveredSeqnoAt(ip1));
        Assert.assertEquals(20, cons_d.highestDeliveredSeqnoAt(ip2));
        Assert.assertEquals(500, cons_d.highestDeliveredSeqnoAt(a1));
        Assert.assertEquals(26, cons_d.highestDeliveredSeqnoAt(a2));
        Assert.assertEquals(25, cons_d.highestDeliveredSeqnoAt(a3));

        Assert.assertEquals(10, cons_d.highestReceivedSeqnoAt(ip1));
        Assert.assertEquals(20, cons_d.highestReceivedSeqnoAt(ip2));
        Assert.assertEquals(501, cons_d.highestReceivedSeqnoAt(a1));
        Assert.assertEquals(26, cons_d.highestReceivedSeqnoAt(a2));
        Assert.assertEquals(33, cons_d.highestReceivedSeqnoAt(a3));
    }
View Full Code Here

    }



    public void testConflictingMerge() {
        MutableDigest new_d=new MutableDigest(2);
        new_d.add(a1, 5, 450, 501);
        new_d.add(a3, 18, 28, 35);
        //System.out.println("\nd before: " + d);
        //System.out.println("new_: " + new_d);
        md.merge(new_d);

        Assert.assertEquals(3, md.size());
View Full Code Here

        assert d.sameSenders(d2);
    }


    public void testSameSendersNotIdentical() {
        MutableDigest tmp=new MutableDigest(3);
        tmp.add(a1, 4, 500, 501);
        tmp.add(a3, 20, 25, 33);
        tmp.add(a2, 25, 26, 26);
        assert md.sameSenders(tmp);
        assert d.sameSenders(tmp);
    }
View Full Code Here

        assert d.sameSenders(tmp);
    }


    public void testSameSendersNotSameLength() {
        md=new MutableDigest(3);
        md.add(a1, 4, 500, 501);
        md.add(a2, 25, 26, 26);
        assert !(d.sameSenders(md));
    }
View Full Code Here

        // start the simulators
        for(int i=0; i < NUM_PEERS; i++)
            simulators[i].start();

        MutableDigest digest=new MutableDigest(NUM_PEERS);
        for(Address addr: addresses)
            digest.add(new Digest(addr, 0, 0));
        for(int i=0; i < NUM_PEERS; i++) {
            layers[i].down(new Event(Event.SET_DIGEST, digest));
        }

    }
View Full Code Here

            // in the digest returned to the client, so the client will *not* be able to ask for retransmission
            // of those messages if he misses them           
            if(hasJoiningMembers) {
                gms.getDownProtocol().down(new Event(Event.SUSPEND_STABLE, MAX_SUSPEND_TIMEOUT));
                Digest tmp=gms.getDigest(); // get existing digest
                MutableDigest join_digest=null;
                if(tmp == null){
                    log.error("received null digest from GET_DIGEST: will cause JOIN to fail");
                }
                else {
                    // create a new digest, which contains the new member
                    join_digest=new MutableDigest(tmp.size() + new_mbrs.size());
                    join_digest.add(tmp); // add the existing digest to the new one
                    for(Address member:new_mbrs)
                        join_digest.add(member, 0, 0); // ... and add the new members. their first seqno will be 1
                }
                join_rsp=new JoinRsp(new_view, join_digest != null? join_digest.copy() : null);
            }

            sendLeaveResponses(leaving_mbrs); // no-op if no leaving members                           
            gms.castViewChangeWithDest(new_view, null,join_rsp,new_mbrs);                     
        }
View Full Code Here

    /**
     * Merge all digests into one. For each sender, the new value is min(low_seqno), max(high_seqno),
     * max(high_seqno_seen). This method has a lock on merge_rsps
     */
    private Digest consolidateDigests(Vector<MergeData> merge_rsps, int num_mbrs) {              
        MutableDigest retval=new MutableDigest(num_mbrs);

        for(MergeData data:merge_rsps) {           
            Digest tmp_digest=data.getDigest();
            if(tmp_digest == null) {
                if(log.isErrorEnabled()) log.error("tmp_digest == null; skipping");
                continue;
            }
            retval.merge(tmp_digest);
        }
        return retval.copy();
    }
View Full Code Here

                    if(log.isWarnEnabled())
                        log.warn("digest response has no senders: digest=" + rsp.getDigest());
                    rsp=null; // just skip the response we guess
                    continue;
                }
                MutableDigest tmp_digest=new MutableDigest(rsp.getDigest());
                tmp_view=rsp.getView();
                if(tmp_view == null) {
                    if(log.isErrorEnabled())
                        log.error("JoinRsp has a null view, skipping it");
                    rsp=null;
                }
                else {
                    if(!tmp_digest.contains(gms.local_addr)) {
                        throw new IllegalStateException("digest returned from " + coord + " with JOIN_RSP does not contain myself (" +
                                gms.local_addr + "): join response: " + rsp);
                    }
                    tmp_digest.incrementHighestDeliveredSeqno(coord); // see DESIGN for details
                    tmp_digest.seal();
                    gms.setDigest(tmp_digest);

                    if(log.isDebugEnabled())
                        log.debug("[" + gms.local_addr + "]: JoinRsp=" + tmp_view + " [size=" + tmp_view.size() + "]\n\n");
View Full Code Here

                        if(log.isWarnEnabled())
                            log.warn("digest response has no senders: digest=" + rsp.getDigest());
                        rsp=null; // just skip the response we guess
                        continue;
                    }
                    MutableDigest tmp_digest=new MutableDigest(rsp.getDigest());
                    tmp_view=rsp.getView();
                    if(tmp_view == null) {
                        if(log.isErrorEnabled())
                            log.error("JoinRsp has a null view, skipping it");
                        rsp=null;
                    }
                    else {
                        if(!tmp_digest.contains(gms.local_addr)) {
                            throw new IllegalStateException("digest returned from " + coord + " with JOIN_RSP does not contain myself (" +
                                    gms.local_addr + "): join response: " + rsp);
                        }
                        tmp_digest.incrementHighestDeliveredSeqno(coord); // see DESIGN for details
                        tmp_digest.seal();
                        gms.setDigest(tmp_digest);

                        if(log.isDebugEnabled())
                            log.debug("[" + gms.local_addr + "]: JoinRsp=" + tmp_view + " [size=" + tmp_view.size() + "]\n\n");
View Full Code Here

TOP

Related Classes of org.jgroups.util.MutableDigest

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.