1 package jgroup.util.log;
2
3 import static jgroup.util.log.ConnectionPatternEvent.Type.Merge;
4 import static jgroup.util.log.ConnectionPatternEvent.Type.Partition;
5
6 import java.util.Set;
7
8 import jgroup.relacs.config.Domain;
9 import jgroup.relacs.config.DomainSet;
10 import junit.framework.TestCase;
11
12 public class ConnectionPatternEventTest extends TestCase
13 {
14
15
16 private Domain x, y, z;
17 private ConnectionPatternEvent[] cp;
18
19 protected void setUp() throws Exception
20 {
21 super.setUp();
22 x = new Domain("ux.his.no", "226.1.2.5", 43322, -1);
23 y = new Domain("cs.unibo.it", "226.1.3.5", 43322, -1);
24 z = new Domain("item.ntnu.no", "226.1.4.5", 43322, -1);
25
26 cp = new ConnectionPatternEvent[5];
27
28 cp[0] = new ConnectionPatternEvent();
29 cp[0].addEvent(Merge, x, y);
30 cp[0].addEvent(Merge, x, z);
31 cp[0].addEvent(Merge, y, z);
32
33
34 cp[1] = new ConnectionPatternEvent();
35 cp[1].addEvent(Partition, x, y);
36 cp[1].addEvent(Partition, x, z);
37 cp[1].addEvent(Partition, y, z);
38
39
40 cp[2] = new ConnectionPatternEvent();
41 cp[2].addEvent(Merge, x, y);
42 cp[2].addEvent(Partition, x, z);
43 cp[2].addEvent(Partition, y, z);
44
45
46 cp[3] = new ConnectionPatternEvent();
47 cp[3].addEvent(Partition, x, y);
48 cp[3].addEvent(Partition, x, z);
49 cp[3].addEvent(Merge, y, z);
50
51
52 cp[4] = new ConnectionPatternEvent();
53 cp[4].addEvent(Partition, x, y);
54 cp[4].addEvent(Merge, x, z);
55 cp[4].addEvent(Partition, y, z);
56 }
57
58
59
60
61 public void testContainsPartition()
62 {
63 assertFalse(cp[0].containsPartition());
64 assertTrue(cp[1].containsPartition());
65 assertTrue(cp[2].containsPartition());
66 assertTrue(cp[3].containsPartition());
67 assertTrue(cp[4].containsPartition());
68 }
69
70
71
72
73 public void testPartitionCount()
74 {
75 assertFalse(cp[0].partitionCount() > 1);
76 assertTrue(cp[0].partitionCount() == 1);
77 assertTrue(cp[1].partitionCount() == 3);
78 assertTrue(cp[2].partitionCount() == 2);
79 assertTrue(cp[3].partitionCount() == 2);
80 assertTrue(cp[4].partitionCount() == 2);
81 }
82
83
84
85
86 public void testGetPartitions()
87 {
88 Set<DomainSet> partitions = null;
89 partitions = cp[0].getPartitions();
90 System.out.println("xyz : " + partitions);
91 assertTrue(partitions.size() == 1);
92
93 partitions = cp[1].getPartitions();
94 System.out.println("x|y|z: " + partitions);
95 assertTrue(partitions.size() == 3);
96
97 partitions = cp[2].getPartitions();
98 System.out.println("xy|z : " + partitions);
99 assertTrue(partitions.size() == 2);
100
101 partitions = cp[3].getPartitions();
102 System.out.println("x|yz : " + partitions);
103 assertTrue(partitions.size() == 2);
104
105 partitions = cp[4].getPartitions();
106 System.out.println("xz|y: " + partitions);
107 assertTrue(partitions.size() == 2);
108 }
109
110 }