Skip to content

Commit f8e291e

Browse files
committed
Fixed INJECT_VIEWTest by picking unique member names
1 parent 0857708 commit f8e291e

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

src/org/jgroups/protocols/INJECT_VIEW.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public synchronized void injectView(String newView) {
3838
String[] perNode = newView.split(NODE_VIEWS_SEPARATOR);
3939
String thisNodeAddress = getProtocolStack().getChannel().getAddressAsString();
4040

41-
for( String nodeView : perNode ){
41+
for(String nodeView: perNode) {
4242
if( nodeView.startsWith(thisNodeAddress) ) {
4343
log.info("[channel: %s] Injecting a new view: %s", thisNodeAddress, nodeView);
4444

@@ -48,7 +48,7 @@ public synchronized void injectView(String newView) {
4848
for( String nodeName : nodeView.split(VIEW_SEPARATOR)[1].split(NAMES_SEPARATOR) ){
4949
for( Map.Entry<Address, String> entry : NameCache.getContents().entrySet() ) {
5050
if( nodeName.equals(entry.getValue()) ){
51-
log.debug("[channel: %s] Found name: <%s> for address: <%s>", entry.getValue(), entry.getKey().toString());
51+
log.debug("[channel: %s] Found name: <%s> for address: <%s>", nodeName, entry.getValue(), entry.getKey().toString());
5252
nodes.add( entry.getKey() );
5353
break;
5454
}
@@ -58,8 +58,9 @@ public synchronized void injectView(String newView) {
5858
View view = new View( nodes.get(0), viewId, nodes);
5959

6060
GMS gms = getProtocolStack().findProtocol(GMS.class);
61+
log.info("[channel: %s] Injecting view %s", gms.addr(), view);
6162
gms.installView(view);
62-
log.info("[channel: %s] Injection finished of view: %s", thisNodeAddress, nodeView);
63+
log.info("[channel: %s] Injection finished of view: %s", thisNodeAddress, view);
6364
}
6465
}
6566
}

src/org/jgroups/stack/ProtocolStack.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ public void setup(List<ProtocolConfiguration> configs, ProtocolHook afterCreatio
448448

449449
/**
450450
* Adds a protocol at the tail of the protocol list
451-
* @param prot
452-
* @return
453451
* @since 2.11
454452
*/
455453
public ProtocolStack addProtocol(Protocol prot) {

tests/junit-functional/org/jgroups/protocols/INJECT_VIEWTest.java

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import org.jgroups.util.Util;
1010
import org.testng.annotations.Test;
1111

12-
import java.util.*;
12+
import java.util.Arrays;
13+
import java.util.HashMap;
14+
import java.util.Map;
1315
import java.util.concurrent.TimeoutException;
1416

1517
/**
@@ -41,18 +43,17 @@ protected static Protocol[] modify(Protocol[] retval) {
4143
public void testInjectView() throws Exception {
4244
JChannel[] channels=null;
4345
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");
4549
print(channels);
4650
View view=channels[channels.length -1].getView();
4751
assert view.size() == channels.length : "view is " + view;
4852

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}
5354
System.out.println("\ninjecting views: "+injectionViewString);
5455
for(JChannel channel: channels)
55-
channel.getProtocolStack().addProtocol( new INJECT_VIEW());
56+
channel.getProtocolStack().addProtocol( new INJECT_VIEW().level("trace"));
5657
for (JChannel channel: channels) {
5758
INJECT_VIEW iv = channel.getProtocolStack().findProtocol(INJECT_VIEW.class);
5859
iv.injectView(injectionViewString);
@@ -61,22 +62,21 @@ public void testInjectView() throws Exception {
6162
System.out.println("\nInjected views: "+injectionViewString);
6263
print(channels);
6364
System.out.println("\nchecking views: ");
64-
checkViews(channels, "A", "A", "B");
65-
System.out.println("\nA is OK");
66-
checkViews(channels, "B", "B", "C");
67-
System.out.println("\nB is OK");
68-
checkViews(channels, "C", "C");
69-
System.out.println("\nC is OK");
65+
checkViews(channels, "AX", "AX", "BX");
66+
System.out.println("\nAX is OK");
67+
checkViews(channels, "BX", "BX", "CX");
68+
System.out.println("\nBX is OK");
69+
checkViews(channels, "CX", "CX");
70+
System.out.println("\nCX is OK");
7071

7172
System.out.println("\ndigests:");
7273
printDigests(channels);
7374

74-
Address leader=determineLeader(channels, "A", "B", "C");
75+
Address leader=determineLeader(channels, "AX", "BX", "CX");
7576
long end_time=System.currentTimeMillis() + 30000;
7677
do {
7778
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");
8080
if(allChannelsHaveViewOf(channels, channels.length))
8181
break;
8282
}
@@ -127,17 +127,14 @@ protected static void disableTracing(JChannel ... channels) {
127127

128128
private static JChannel[] create(String cluster_name, String ... names) throws Exception {
129129
JChannel[] retval=new JChannel[names.length];
130-
131130
for(int i=0; i < retval.length; i++) {
132131
JChannel ch;
133132
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]);
137134
retval[i]=ch;
138135
ch.connect(cluster_name);
139136
if(i == 0)
140-
Util.sleep(3000);
137+
Util.sleep(1000);
141138
}
142139
return retval;
143140
}
@@ -167,7 +164,7 @@ private static void checkViews(JChannel[] channels, String channel_name, String
167164
JChannel ch=findChannel(channel_name, channels);
168165
View view=ch.getView();
169166
Util.waitUntil(4000, 200, () -> view.size() == members.length,
170-
() -> "view is " + view + ", members: " + Arrays.toString(members));
167+
() -> "view is " + view + ", expected: " + Arrays.toString(members));
171168
for(String member: members) {
172169
Address addr=findAddress(member, channels);
173170
assert view.getMembers().contains(addr) : "view " + view + " does not contain " + addr;
@@ -206,23 +203,9 @@ private static View findView(String tmp, JChannel[] channels) {
206203
return null;
207204
}
208205

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-
222206
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());
226209
}
227210

228211
private static void printDigests(JChannel[] channels) {

0 commit comments

Comments
 (0)