1 package jgroup.groovy.experiment.util;
2
3 import static jgroup.util.log.ConnectionPatternEvent.Type.Merge;
4 import static jgroup.util.log.ConnectionPatternEvent.Type.Partition;
5
6 import java.net.InetAddress;
7
8 import jgroup.core.EndPoint;
9 import jgroup.core.MemberId;
10 import jgroup.core.View;
11 import jgroup.groovy.experiment.util.PMStateMachine.State;
12 import jgroup.relacs.config.AppConfig;
13 import jgroup.relacs.config.Domain;
14 import jgroup.relacs.config.DomainSet;
15 import jgroup.relacs.config.Host;
16 import jgroup.relacs.types.EndPointImpl;
17 import jgroup.relacs.types.MemberIdImpl;
18 import jgroup.relacs.types.ViewImpl;
19 import jgroup.util.log.ConnectionPatternEvent;
20 import jgroup.util.log.ViewEvent;
21 import junit.framework.TestCase;
22
23 public class PMStateMachineTest extends TestCase
24 {
25
26
27 private Domain x, y, z;
28 private PMStateMachine pmstatemachine;
29 private View v1, v2, v3, v4, v5, v6;
30 private MemberId[] m1, m2, m3, m4;
31 private ConnectionPatternEvent[] cp;
32 private ViewEvent ve1, ve2, ve3, ve4, ve5, ve6;
33
34 protected void setUp() throws Exception
35 {
36 super.setUp();
37 AppConfig.addApplication("RM", "classname", "args", 2, false);
38 x = new Domain("ux.his.no", "226.1.2.5", 43322, -1);
39 y = new Domain("cs.unibo.it", "226.1.3.5", 43322, -1);
40 z = new Domain("item.ntnu.no", "226.1.4.5", 43322, -1);
41 DomainSet domainSet = new DomainSet();
42 domainSet.addDomain(x);
43 domainSet.addDomain(y);
44 domainSet.addDomain(z);
45 pmstatemachine = new PMStateMachine(2, domainSet);
46
47 cp = new ConnectionPatternEvent[5];
48
49 cp[0] = new ConnectionPatternEvent();
50 cp[0].addEvent(Merge, x, y);
51 cp[0].addEvent(Merge, x, z);
52 cp[0].addEvent(Merge, y, z);
53
54
55 cp[1] = new ConnectionPatternEvent();
56 cp[1].addEvent(Partition, x, y);
57 cp[1].addEvent(Partition, x, z);
58 cp[1].addEvent(Partition, y, z);
59
60
61 cp[2] = new ConnectionPatternEvent();
62 cp[2].addEvent(Merge, x, y);
63 cp[2].addEvent(Partition, x, z);
64 cp[2].addEvent(Partition, y, z);
65
66
67 cp[3] = new ConnectionPatternEvent();
68 cp[3].addEvent(Partition, x, y);
69 cp[3].addEvent(Partition, x, z);
70 cp[3].addEvent(Merge, y, z);
71
72
73 cp[4] = new ConnectionPatternEvent();
74 cp[4].addEvent(Partition, x, y);
75 cp[4].addEvent(Merge, x, z);
76 cp[4].addEvent(Partition, y, z);
77
78 EndPoint[] endpoints = new EndPointImpl[6];
79 endpoints[0] = new EndPointImpl(InetAddress.getByName("ba3.ux.uis.no"), 2121);
80 endpoints[1] = new EndPointImpl(InetAddress.getByName("ba4.ux.uis.no"), 2121);
81 endpoints[2] = new EndPointImpl(InetAddress.getByName("bogi.ux.his.no"), 2121);
82 endpoints[3] = new EndPointImpl(InetAddress.getByName("wolfpack01.item.ntnu.no"), 2121);
83 endpoints[4] = new EndPointImpl(InetAddress.getByName("wolfpack02.item.ntnu.no"), 2121);
84 endpoints[5] = new EndPointImpl(InetAddress.getByName("wolfpack03.item.ntnu.no"), 2121);
85 x.addHost(new Host("bogi", x, 2121));
86 System.out.println(x.getHostSet());
87
88 m1 = new MemberIdImpl[3];
89 m1[0] = new MemberIdImpl(endpoints[0], 0, endpoints[0], 1);
90 m1[1] = new MemberIdImpl(endpoints[1], 0, endpoints[1], 1);
91 m1[2] = new MemberIdImpl(endpoints[2], 0, endpoints[2], 1);
92 m2 = new MemberIdImpl[3];
93 m2[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
94 m2[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
95 m2[2] = new MemberIdImpl(endpoints[5], 0, endpoints[5], 1);
96 m3 = new MemberIdImpl[2];
97 m3[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
98 m3[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
99 m4 = new MemberIdImpl[4];
100 m4[0] = new MemberIdImpl(endpoints[3], 0, endpoints[3], 1);
101 m4[1] = new MemberIdImpl(endpoints[4], 0, endpoints[4], 1);
102 m4[2] = new MemberIdImpl(endpoints[5], 0, endpoints[5], 1);
103 m4[3] = new MemberIdImpl(endpoints[1], 0, endpoints[1], 1);
104 v1 = new ViewImpl(2, 0, 0, m1);
105 v2 = new ViewImpl(2, 1, 0, m2);
106 v3 = new ViewImpl(2, 2, 0, m3);
107 v4 = new ViewImpl(2, 3, 0, m4);
108 v5 = new ViewImpl(2, 4, 0, m1);
109 v6 = new ViewImpl(2, 5, 0, m2);
110 ve1 = new ViewEvent(ViewEvent.Type.ARM, v1);
111 ve2 = new ViewEvent(ViewEvent.Type.ARM, v2);
112 ve3 = new ViewEvent(ViewEvent.Type.ARM, v3);
113 ve4 = new ViewEvent(ViewEvent.Type.ARM, v4);
114 ve5 = new ViewEvent(ViewEvent.Type.ARM, v5);
115 ve6 = new ViewEvent(ViewEvent.Type.ARM, v6);
116 }
117
118
119
120
121 public void testGetState()
122 {
123 pmstatemachine.saveState(cp[0]);
124 State xyz = pmstatemachine.getCurrentState();
125 pmstatemachine.saveState(ve1);
126 pmstatemachine.saveState(cp[1]);
127 State x_y_z = pmstatemachine.getCurrentState();
128 pmstatemachine.saveState(cp[2]);
129 State xy_z = pmstatemachine.getCurrentState();
130 pmstatemachine.saveState(cp[3]);
131 State x_yz = pmstatemachine.getCurrentState();
132 pmstatemachine.saveState(cp[4]);
133 State xz_y = pmstatemachine.getCurrentState();
134 System.out.println(xyz);
135 System.out.println(x_y_z);
136 System.out.println(xy_z);
137 System.out.println(x_yz);
138 System.out.println(xz_y);
139 }
140
141 }