1   package jgroup.relacs.types;
2   
3   import java.net.InetAddress;
4   
5   import jgroup.core.EndPoint;
6   import jgroup.core.MemberId;
7   import junit.framework.TestCase;
8   
9   public class MemberIdImplTest extends TestCase
10  {
11  
12    private MemberId[] m1, m2, m3, m4;
13  
14    protected void setUp() throws Exception
15    {
16      super.setUp();
17      EndPoint[] endpoints = new EndPointImpl[6];
18      endpoints[0] = new EndPointImpl(InetAddress.getByName("ba3.ux.uis.no"), 2121);
19      endpoints[1] = new EndPointImpl(InetAddress.getByName("ba4.ux.uis.no"), 2121);
20      endpoints[2] = new EndPointImpl(InetAddress.getByName("jo10.ux.uis.no"), 2121);
21      endpoints[3] = new EndPointImpl(InetAddress.getByName("wolfpack01.item.ntnu.no"), 2121);
22      endpoints[4] = new EndPointImpl(InetAddress.getByName("wolfpack02.item.ntnu.no"), 2121);
23      endpoints[5] = new EndPointImpl(InetAddress.getByName("wolfpack03.item.ntnu.no"), 2121);
24  
25      m1 = new MemberIdImpl[3];
26      m1[0] = new MemberIdImpl(endpoints[0], 0, endpoints[0], 1);
27      m1[1] = new MemberIdImpl(endpoints[1], 0, endpoints[1], 1);
28      m1[2] = new MemberIdImpl(endpoints[2], 0, endpoints[2], 1);
29      m2 = new MemberIdImpl[3];
30      m2[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
31      m2[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
32      m2[2] = new MemberIdImpl(endpoints[5], 0, endpoints[5], 1);
33      m3 = new MemberIdImpl[2];
34      m3[0] = new MemberIdImpl(endpoints[3], 1, endpoints[3], 1);
35      m3[1] = new MemberIdImpl(endpoints[4], 1, endpoints[4], 1);
36      m4 = new MemberIdImpl[4];
37      m4[0] = new MemberIdImpl(endpoints[3], 2, endpoints[3], 1);
38      m4[1] = new MemberIdImpl(endpoints[4], 2, endpoints[4], 1);
39      m4[2] = new MemberIdImpl(endpoints[5], 1, endpoints[5], 1);
40      m4[3] = new MemberIdImpl(endpoints[1], 1, endpoints[1], 1);
41    }
42  
43    /*
44     * Test method for 'jgroup.relacs.types.MemberIdImpl.isNewer(MemberId)'
45     */
46    public void testIsNewer()
47    {
48      assertFalse(m1[0].isNewer(null));
49      assertTrue(m3[0].isNewer(m2[0]));
50      assertTrue(m4[0].isNewer(m2[0]));
51      assertTrue(m4[0].isNewer(m3[0]));
52      assertFalse(m2[0].isNewer(m3[0]));
53      assertFalse(m2[0].isNewer(m4[0]));
54      assertFalse(m3[0].isNewer(m4[0]));
55  
56      // different endpoint (or same endpoint with same incarnation) ==> false
57      assertFalse(m1[0].isNewer(m1[0]));
58      assertFalse(m1[0].isNewer(m1[1]));
59      assertFalse(m1[0].isNewer(m1[2]));
60      assertFalse(m1[1].isNewer(m1[0]));
61      assertFalse(m1[1].isNewer(m1[1]));
62      assertFalse(m1[1].isNewer(m1[2]));
63      assertFalse(m1[2].isNewer(m1[0]));
64      assertFalse(m1[2].isNewer(m1[1]));
65      assertFalse(m1[2].isNewer(m1[2]));
66    }
67  
68    /*
69     * Test method for 'jgroup.relacs.types.MemberIdImpl.isNeighbour(MemberId)'
70     */
71    public void testIsNeighbour()
72    {
73      assertFalse(m1[0].isNeighbour(null));
74      assertTrue(m1[0].isNeighbour(m1[0]));
75      assertFalse(m2[0].isNeighbour(m3[0]));
76      assertFalse(m2[0].isNeighbour(m4[0]));
77      assertFalse(m2[0].isNeighbour(m2[1]));
78    }
79  
80    /*
81     * Test method for 'jgroup.relacs.types.MemberIdImpl.compareTo(MemberId)'
82     */
83    public void testCompareTo()
84    {
85      int cmp = m1[0].compareTo(m1[1]);
86      System.out.println("cmp=" + cmp);
87    }
88  
89  }