1   package jgroup.relacs.types;
2   
3   import java.net.InetAddress;
4   
5   import jgroup.core.EndPoint;
6   import jgroup.core.MemberId;
7   import jgroup.core.View;
8   import junit.framework.TestCase;
9   
10  public class ViewImplTest extends TestCase
11  {
12  
13    private View v1, v2, v3, v4, v5, v6;
14    private MemberId[] m1, m2, m3, m4;
15  
16    public ViewImplTest(String arg0)
17    {
18      super(arg0);
19    }
20  
21    protected void setUp() throws Exception
22    {
23      super.setUp();
24      EndPoint[] endpoints = new EndPointImpl[6];
25      endpoints[0] = new EndPointImpl(InetAddress.getByName("ba3.ux.uis.no"), 2121);
26      endpoints[1] = new EndPointImpl(InetAddress.getByName("ba4.ux.uis.no"), 2121);
27      endpoints[2] = new EndPointImpl(InetAddress.getByName("jo10.ux.uis.no"), 2121);
28      endpoints[3] = new EndPointImpl(InetAddress.getByName("wolfpack01.item.ntnu.no"), 2121);
29      endpoints[4] = new EndPointImpl(InetAddress.getByName("wolfpack02.item.ntnu.no"), 2121);
30      endpoints[5] = new EndPointImpl(InetAddress.getByName("wolfpack03.item.ntnu.no"), 2121);
31  
32      m1 = new MemberIdImpl[3];
33      m1[0] = new MemberIdImpl(endpoints[0], 0, endpoints[0], 1);
34      m1[1] = new MemberIdImpl(endpoints[1], 0, endpoints[1], 1);
35      m1[2] = new MemberIdImpl(endpoints[2], 0, endpoints[2], 1);
36      m2 = new MemberIdImpl[3];
37      m2[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
38      m2[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
39      m2[2] = new MemberIdImpl(endpoints[5], 0, endpoints[5], 1);
40      m3 = new MemberIdImpl[2];
41      m3[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
42      m3[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
43      m4 = new MemberIdImpl[4];
44      m4[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
45      m4[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
46      m4[2] = new MemberIdImpl(endpoints[5], 0, endpoints[5], 1);
47      m4[3] = new MemberIdImpl(endpoints[1], 0, endpoints[1], 1);
48      v1 = new ViewImpl(0, 0, 0, m1);
49      v2 = new ViewImpl(0, 1, 0, m2);
50      v3 = new ViewImpl(0, 2, 0, m3);
51      v4 = new ViewImpl(0, 3, 0, m4);
52      v5 = new ViewImpl(0, 4, 0, m1);
53      v6 = new ViewImpl(0, 5, 0, m2);
54    }
55  
56    /*
57     * Test method for 'jgroup.relacs.types.ViewImpl.commonMembers(MemberId[])'
58     */
59    public final void testCommonMembersMemberIdArray()
60    {
61      // TODO Auto-generated method stub
62  
63    }
64  
65    /*
66     * Test method for 'jgroup.relacs.types.ViewImpl.commonMembers(View)'
67     */
68    public final void testCommonMembersView()
69    {
70      MemberId [] common = v1.commonMembers(v4);
71      assertTrue(common.length == 1);
72      assertTrue(common[0].equals(m1[1]));
73      assertTrue(common[0].equals(m4[3]));
74      assertFalse(common[0].equals(m1[2]));
75  
76      common = v2.commonMembers(v3);
77      assertTrue(common.length == 2);
78      assertTrue(common[0].equals(m2[0]));
79      assertTrue(common[0].equals(m3[0]));
80      assertTrue(common[1].equals(m2[1]));
81      assertTrue(common[1].equals(m3[1]));
82      assertFalse(common[0].equals(m2[2]));
83      assertFalse(common[1].equals(m2[2]));
84  
85      common = v3.commonMembers(v2);
86      for (MemberId id : common) {
87        System.out.println(id);
88      }
89      assertTrue(common.length == 2);
90      assertTrue(common[0].equals(m2[0]));
91      assertTrue(common[0].equals(m3[0]));
92      assertTrue(common[1].equals(m2[1]));
93      assertTrue(common[1].equals(m3[1]));
94      assertFalse(common[0].equals(m2[2]));
95      assertFalse(common[1].equals(m2[2]));
96    }
97  
98    /*
99     * Test method for 'jgroup.relacs.types.ViewImpl.newMembers(View)'
100    */
101   public final void testNewMembers()
102   {
103     // TODO Auto-generated method stub
104 
105   }
106 
107   /*
108    * Test method for 'jgroup.relacs.types.ViewImpl.oldMembers(View)'
109    */
110   public final void testOldMembers()
111   {
112     // TODO Auto-generated method stub
113 
114   }
115 
116   /*
117    * Test method for 'jgroup.relacs.types.ViewImpl.contains(MemberId)'
118    */
119   public final void testContains()
120   {
121     // TODO Auto-generated method stub
122 
123   }
124 
125   /*
126    * Test method for 'jgroup.relacs.types.ViewImpl.containsAll(View)'
127    */
128   public final void testContainsAll()
129   {
130     // TODO Auto-generated method stub
131 
132   }
133 
134   /*
135    * Test method for 'jgroup.relacs.types.ViewImpl.hasSameMembers(View)'
136    */
137   public final void testHasSameMembers()
138   {
139     assertTrue(v1.hasSameMembers(v1));
140     assertTrue(v1.hasSameMembers(v5));
141     assertTrue(v2.hasSameMembers(v6));
142     assertFalse(v1.hasSameMembers(v2));
143     assertFalse(v3.hasSameMembers(v4));
144     assertFalse(v4.hasSameMembers(v3));
145   }
146 
147   /*
148    * Test method for 'jgroup.relacs.types.ViewImpl.getMemberPosition(MemberId)'
149    */
150   public final void testGetMemberPosition()
151   {
152     assertTrue(v1.getMemberPosition(m1[0]) == 0);
153     assertTrue(v1.getMemberPosition(m1[1]) == 1);
154     assertTrue(v1.getMemberPosition(m1[2]) == 2);
155 
156     assertTrue(v2.getMemberPosition(m2[0]) == 0);
157     assertTrue(v2.getMemberPosition(m2[1]) == 1);
158     assertTrue(v2.getMemberPosition(m2[2]) == 2);
159 
160     assertTrue(v3.getMemberPosition(m3[0]) == 0);
161     assertTrue(v3.getMemberPosition(m3[1]) == 1);
162 
163     assertTrue(v4.getMemberPosition(m4[0]) == 0);
164     assertTrue(v4.getMemberPosition(m4[1]) == 1);
165     assertTrue(v4.getMemberPosition(m4[2]) == 2);
166     assertTrue(v4.getMemberPosition(m4[3]) == 3);
167 
168     assertFalse(v4.getMemberPosition(m4[3]) == 0);
169     assertFalse(v4.getMemberPosition(m4[3]) == 1);
170     assertFalse(v4.getMemberPosition(m4[3]) == 2);
171 
172     assertFalse(v3.getMemberPosition(m3[1]) == 0);
173     assertFalse(v3.getMemberPosition(m3[0]) == 1);
174 
175     assertFalse(v2.getMemberPosition(m1[0]) == 0);
176     assertFalse(v2.getMemberPosition(m1[0]) == 1);
177     assertFalse(v2.getMemberPosition(m1[0]) == 2);
178 
179     // Test that a negative value is returned for members not in the view
180     assertTrue(v1.getMemberPosition(m2[0]) < 0);
181     assertTrue(v1.getMemberPosition(m2[1]) < 0);
182     assertTrue(v1.getMemberPosition(m2[2]) < 0);
183 
184     assertTrue(v2.getMemberPosition(m1[0]) < 0);
185     assertTrue(v2.getMemberPosition(m1[1]) < 0);
186     assertTrue(v2.getMemberPosition(m1[2]) < 0);
187 
188     assertTrue(v3.getMemberPosition(m1[0]) < 0);
189     assertTrue(v3.getMemberPosition(m1[1]) < 0);
190     assertTrue(v3.getMemberPosition(m1[2]) < 0);
191 
192     assertTrue(v4.getMemberPosition(m1[0]) < 0);
193     assertTrue(v4.getMemberPosition(m1[1]) == 3);
194     assertTrue(v4.getMemberPosition(m1[2]) < 0);
195 
196     assertTrue(v4.getMemberPosition(m2[0]) == 0);
197     assertTrue(v4.getMemberPosition(m2[1]) == 1);
198     assertTrue(v4.getMemberPosition(m2[2]) == 2);
199   }
200 
201 } // END ViewImplTest