9
9
import org .jgroups .util .Util ;
10
10
import org .testng .annotations .Test ;
11
11
12
- import java .util .*;
12
+ import java .util .Arrays ;
13
+ import java .util .HashMap ;
14
+ import java .util .Map ;
13
15
import java .util .concurrent .TimeoutException ;
14
16
15
17
/**
@@ -41,18 +43,17 @@ protected static Protocol[] modify(Protocol[] retval) {
41
43
public void testInjectView () throws Exception {
42
44
JChannel [] channels =null ;
43
45
try {
44
- channels =create ( "testInjectView" , "A" , "B" , "C" );
46
+ // the names needs to be unique: INJECT_VIEW uses lookup by string, and this might return an address
47
+ // associated with a different test running concurrently in the test suite. See the javadoc of this class
48
+ channels =create ( "testInjectView" , "AX" , "BX" , "CX" );
45
49
print (channels );
46
50
View view =channels [channels .length -1 ].getView ();
47
51
assert view .size () == channels .length : "view is " + view ;
48
52
49
- String injectionViewString = String .format ("%s=%s/%s;%s=%s/%s;%s=%s" ,
50
- "A" ,"A" ,"B" ,
51
- "B" ,"B" ,"C" ,
52
- "C" ,"C" );
53
+ String injectionViewString = "AX=AX/BX;BX=BX/CX;CX=CX" ; // AX: {AX,BX} BX: {BX,CX} CX: {CX}
53
54
System .out .println ("\n injecting views: " +injectionViewString );
54
55
for (JChannel channel : channels )
55
- channel .getProtocolStack ().addProtocol ( new INJECT_VIEW ());
56
+ channel .getProtocolStack ().addProtocol ( new INJECT_VIEW (). level ( "trace" ) );
56
57
for (JChannel channel : channels ) {
57
58
INJECT_VIEW iv = channel .getProtocolStack ().findProtocol (INJECT_VIEW .class );
58
59
iv .injectView (injectionViewString );
@@ -61,22 +62,21 @@ public void testInjectView() throws Exception {
61
62
System .out .println ("\n Injected views: " +injectionViewString );
62
63
print (channels );
63
64
System .out .println ("\n checking views: " );
64
- checkViews (channels , "A " , "A " , "B " );
65
- System .out .println ("\n A is OK" );
66
- checkViews (channels , "B " , "B " , "C " );
67
- System .out .println ("\n B is OK" );
68
- checkViews (channels , "C " , "C " );
69
- System .out .println ("\n C is OK" );
65
+ checkViews (channels , "AX " , "AX " , "BX " );
66
+ System .out .println ("\n AX is OK" );
67
+ checkViews (channels , "BX " , "BX " , "CX " );
68
+ System .out .println ("\n BX is OK" );
69
+ checkViews (channels , "CX " , "CX " );
70
+ System .out .println ("\n CX is OK" );
70
71
71
72
System .out .println ("\n digests:" );
72
73
printDigests (channels );
73
74
74
- Address leader =determineLeader (channels , "A " , "B " , "C " );
75
+ Address leader =determineLeader (channels , "AX " , "BX " , "CX " );
75
76
long end_time =System .currentTimeMillis () + 30000 ;
76
77
do {
77
78
System .out .println ("\n ==== injecting merge events into " + leader + " ====" );
78
- injectMergeEvent (channels , leader , "A" , "B" , "C" );
79
- Util .sleep (1000 );
79
+ injectMergeEvent (channels , leader , "AX" , "BX" , "CX" );
80
80
if (allChannelsHaveViewOf (channels , channels .length ))
81
81
break ;
82
82
}
@@ -127,17 +127,14 @@ protected static void disableTracing(JChannel ... channels) {
127
127
128
128
private static JChannel [] create (String cluster_name , String ... names ) throws Exception {
129
129
JChannel [] retval =new JChannel [names .length ];
130
-
131
130
for (int i =0 ; i < retval .length ; i ++) {
132
131
JChannel ch ;
133
132
Protocol [] props =getProps ();
134
- ch =new JChannel (props );
135
- // ((MyChannel)ch).setId(i+1);
136
- ch .setName (names [i ]);
133
+ ch =new JChannel (props ).name (names [i ]);
137
134
retval [i ]=ch ;
138
135
ch .connect (cluster_name );
139
136
if (i == 0 )
140
- Util .sleep (3000 );
137
+ Util .sleep (1000 );
141
138
}
142
139
return retval ;
143
140
}
@@ -167,7 +164,7 @@ private static void checkViews(JChannel[] channels, String channel_name, String
167
164
JChannel ch =findChannel (channel_name , channels );
168
165
View view =ch .getView ();
169
166
Util .waitUntil (4000 , 200 , () -> view .size () == members .length ,
170
- () -> "view is " + view + ", members : " + Arrays .toString (members ));
167
+ () -> "view is " + view + ", expected : " + Arrays .toString (members ));
171
168
for (String member : members ) {
172
169
Address addr =findAddress (member , channels );
173
170
assert view .getMembers ().contains (addr ) : "view " + view + " does not contain " + addr ;
@@ -206,23 +203,9 @@ private static View findView(String tmp, JChannel[] channels) {
206
203
return null ;
207
204
}
208
205
209
- private static void applyViews (List <View > views , JChannel [] channels ) {
210
- for (View view : views ) {
211
- Collection <Address > members =view .getMembers ();
212
- for (JChannel ch : channels ) {
213
- Address addr =ch .getAddress ();
214
- if (members .contains (addr )) {
215
- GMS gms =ch .getProtocolStack ().findProtocol (GMS .class );
216
- gms .installView (view );
217
- }
218
- }
219
- }
220
- }
221
-
222
206
private static void print (JChannel [] channels ) {
223
- for (JChannel ch : channels ) {
224
- System .out .println (ch .getName () + ": " + ch .getView ());
225
- }
207
+ for (JChannel ch : channels )
208
+ System .out .printf ("%s: %s\n " , ch .name (), ch .view ());
226
209
}
227
210
228
211
private static void printDigests (JChannel [] channels ) {
0 commit comments