Skip to content

Commit 5117de7

Browse files
authored
Merge pull request #28 from slaskawi/CLOUD-1509/Fix_false_sharing_between_tests
Cloud 1509/fix false sharing between tests
2 parents ca3f975 + b7315bd commit 5117de7

File tree

8 files changed

+47
-52
lines changed

8 files changed

+47
-52
lines changed

common/src/main/java/org/openshift/ping/common/server/AbstractServerFactory.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

common/src/main/java/org/openshift/ping/common/server/JBossServerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author <a href="mailto:[email protected]">Ales Justin</a>
2121
*/
22-
public class JBossServerFactory extends AbstractServerFactory {
22+
public class JBossServerFactory implements ServerFactory {
2323

2424
public boolean isAvailable() {
2525
try {
@@ -29,7 +29,8 @@ public boolean isAvailable() {
2929
}
3030
}
3131

32-
public Server createServer(int port) {
32+
@Override
33+
public Server getServer(int port) {
3334
return new JBossServer(port);
3435
}
3536

common/src/main/java/org/openshift/ping/common/server/JDKServerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author <a href="mailto:[email protected]">Ales Justin</a>
2121
*/
22-
public class JDKServerFactory extends AbstractServerFactory {
22+
public class JDKServerFactory implements ServerFactory {
2323

2424
public boolean isAvailable() {
2525
try {
@@ -29,7 +29,8 @@ public boolean isAvailable() {
2929
}
3030
}
3131

32-
public Server createServer(int port) {
32+
@Override
33+
public Server getServer(int port) {
3334
return new JDKServer(port);
3435
}
3536

common/src/main/java/org/openshift/ping/common/server/UndertowServerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author <a href="mailto:[email protected]">Ales Justin</a>
2121
*/
22-
public class UndertowServerFactory extends AbstractServerFactory {
22+
public class UndertowServerFactory implements ServerFactory {
2323

2424
public boolean isAvailable() {
2525
try {
@@ -29,7 +29,8 @@ public boolean isAvailable() {
2929
}
3030
}
3131

32-
public Server createServer(int port) {
32+
@Override
33+
public Server getServer(int port) {
3334
return new UndertowServer(port);
3435
}
3536

kube/src/test/java/org/openshift/ping/kube/test/PingTestBase.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public abstract class PingTestBase extends TestBase {
4141
if (CompatibilityUtils.isJGroups4()) {
4242
waitForViewMethod = Util.class.getMethod("waitUntilAllChannelsHaveSameView", long.class, long.class, JChannel[].class);
4343
} else {
44-
waitForViewMethod = Util.class.getMethod("waitUntilAllChannelsHaveSameSize", long.class, long.class, Channel[].class);
44+
Method m;
45+
try {
46+
m = Util.class.getMethod("waitUntilAllChannelsHaveSameSize", long.class, long.class, Channel[].class);
47+
} catch (NoSuchMethodException e) {
48+
m = Util.class.getMethod("waitUntilAllChannelsHaveSameView", long.class, long.class, Channel[].class);
49+
}
50+
waitForViewMethod = m;
4551
}
4652
} catch (NoSuchMethodException e) {
4753
throw new CompatibilityException("Could not find proper 'waitUntilAllChannelsHaveSame*' method.", e);

kube/src/test/java/org/openshift/ping/kube/test/ServerTestBase.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.DataOutputStream;
2121
import java.lang.reflect.Constructor;
22+
import java.lang.reflect.Method;
2223
import java.net.HttpURLConnection;
2324
import java.net.URL;
2425
import java.util.Arrays;
@@ -75,11 +76,10 @@ public void testResponse() throws Exception {
7576
Address local_addr = pinger.getLocalAddress();
7677
PhysicalAddress physical_addr = (PhysicalAddress) pinger
7778
.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
78-
PingHeader hdr = new TestPingHeader();
7979
PingData data = createPingData(local_addr, physical_addr);
80+
final PingHeader hdr = getPingHeader(data);
8081
Message msg = new Message(null).setFlag(Message.Flag.DONT_BUNDLE)
8182
.putHeader(pinger.getId(), hdr).setBuffer(streamableToBuffer(data));
82-
8383
URL url = new URL("http://localhost:8888");
8484
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
8585
conn.addRequestProperty(Server.CLUSTER_NAME, TestBase.CLUSTER_NAME);
@@ -93,6 +93,34 @@ public void testResponse() throws Exception {
9393
Assert.assertEquals(200, conn.getResponseCode());
9494
}
9595

96+
private static Buffer streamableToBuffer(Streamable obj) {
97+
final ByteArrayOutputStream out_stream = new ByteArrayOutputStream(1024);
98+
DataOutputStream out = new DataOutputStream(out_stream);
99+
try {
100+
Util.writeStreamable(obj, out);
101+
return new Buffer(out_stream.toByteArray());
102+
} catch (Exception ex) {
103+
return null;
104+
}
105+
}
106+
107+
private PingHeader getPingHeader(PingData data) {
108+
try {
109+
if(CompatibilityUtils.isJGroups4()) {
110+
Constructor<PingHeader> constructor = PingHeader.class.getConstructor(null);
111+
PingHeader header = constructor.newInstance(null);
112+
Method clusterName = header.getClass().getMethod("clusterName", String.class);
113+
clusterName.invoke(header, TestBase.CLUSTER_NAME);
114+
return header;
115+
} else {
116+
Constructor<PingHeader> constructor = PingHeader.class.getConstructor(byte.class, PingData.class, String.class);
117+
return constructor.newInstance(PingHeader.GET_MBRS_RSP, data, TestBase.CLUSTER_NAME);
118+
}
119+
} catch (Exception e) {
120+
throw new CompatibilityException("Could not find or invoke proper 'PingHeader' constructor");
121+
}
122+
}
123+
96124
/*
97125
* Handled via reflection because of JGroups 3/4 incompatibility.
98126
*/
@@ -112,17 +140,6 @@ private PingData createPingData(Address local_addr, PhysicalAddress physical_add
112140
}
113141
}
114142

115-
private static Buffer streamableToBuffer(Streamable obj) {
116-
final ByteArrayOutputStream out_stream = new ByteArrayOutputStream(512);
117-
DataOutputStream out = new DataOutputStream(out_stream);
118-
try {
119-
Util.writeStreamable(obj, out);
120-
return new Buffer(out_stream.toByteArray());
121-
} catch (Exception ex) {
122-
return null;
123-
}
124-
}
125-
126143
private static final class TestKubePing extends KubePing {
127144
static {
128145
ClassConfigurator.addProtocol(JGROUPS_KUBE_PING_ID, TestKubePing.class);
@@ -137,11 +154,4 @@ protected Client getClient() {
137154
return new TestClient();
138155
}
139156
}
140-
141-
private static final class TestPingHeader extends PingHeader {
142-
private TestPingHeader() {
143-
cluster_name = TestBase.CLUSTER_NAME;
144-
type = PingHeader.GET_MBRS_REQ;
145-
}
146-
}
147157
}

kube/src/test/java/org/openshift/ping/kube/test/SimplePingTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818

1919
import org.jgroups.protocols.FILE_PING;
2020
import org.jgroups.stack.Protocol;
21-
import org.junit.Ignore;
2221

2322
/**
2423
* A parallel test to ZK tests.
2524
* Just so we know tests are fine.
2625
*
2726
* @author <a href="mailto:[email protected]">Ales Justin</a>
2827
*/
29-
@Ignore("To be clarified with Bela")
3028
public class SimplePingTest extends PingTestBase {
3129

3230
protected Protocol createPing() {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
</activation>
142142
<properties>
143143
<!-- Impl -->
144-
<version.jgroups>[3.2.6.Final,4.0.1.Final]</version.jgroups>
144+
<version.jgroups>3.2.6.Final</version.jgroups>
145145
<version.dmr>1.2.0.Final</version.dmr>
146146
<!-- Build -->
147147
<version.org.wildfly>8.2.1.Final</version.org.wildfly>

0 commit comments

Comments
 (0)