Skip to content

Commit

Permalink
[EJBCLIENT-356] fix the test case (wildfly#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaxwell authored Sep 30, 2020
1 parent f0b3b75 commit fb47fbe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.net.InetAddress;
Expand All @@ -38,7 +39,7 @@
*/
public class NetworkBlackHoleInvocationTestCase {
private static final Logger logger = Logger.getLogger(NetworkBlackHoleInvocationTestCase.class);
private static final String PROPERTIES_FILE = "jboss-ejb-client.properties";
private static final String PROPERTIES_FILE = "broken-server-jboss-ejb-client.properties";

private DummyServer server;
private boolean serverStarted = false;
Expand Down Expand Up @@ -101,8 +102,16 @@ public void afterTest() {
*/
@Test
public void testTakingDownServerDoesNotBreakClients() throws Exception {

// broken-server-jboss-ejb-client.properties will have the ejb-client with 2 nodes on ports 6999 and 7099
// it will succesfully invoke the ejb and then it will kill the 7099 port and try to invoke again
// the expected behavior is that it will not wait more than org.jboss.ejb.client.discovery.additional-node-timeout once it has a connection to 6999 before invoking the ejb
System.setProperty("org.jboss.ejb.client.discovery.timeout", "10");
System.setProperty("org.jboss.ejb.client.discovery.additional-node-timeout","2");

// This test will fail if org.jboss.ejb.client.discovery.additional-node-timeout is not set
// assertInvocationTimeLessThan checks that the org.jboss.ejb.client.discovery.additional-node-timeout is effective
// if org.jboss.ejb.client.discovery.additional-node-timeout is not effective it will timeout once it reaches the value of org.jboss.ejb.client.discovery.timeout
System.setProperty("org.jboss.ejb.client.discovery.additional-node-timeout", "2");

try (DummyServer server2 = new DummyServer("localhost", 7099, "test2")) {
server2.start();
Expand All @@ -118,18 +127,32 @@ public void testTakingDownServerDoesNotBreakClients() throws Exception {
logger.info("Invoking on proxy...");
// Invoke on the proxy. This should fail in 10 seconds or else it'll hang.
final String message = "hello!";

long invocationStart = System.currentTimeMillis();
String echo = proxy.echo(message);
assertInvocationTimeLessThan("org.jboss.ejb.client.discovery.additional-node-timeout ineffective", 3000, invocationStart);
Assert.assertEquals(message, echo);
server2.hardKill();

final Echo proxy2 = EJBClient.createProxy(statelessEJBLocator);
Assert.assertNotNull("Received a null proxy", proxy2);
logger.info("Created proxy for Echo: " + proxy2.toString());

//this is a network black hole
//it emulates what happens if the server just disappears, and connect attempts hang
//instead of being immediately rejected (e.g. a firewall dropping packets)
try (ServerSocket s = new ServerSocket(7099, 100, InetAddress.getByName("localhost"))) {
echo = proxy.echo(message);
invocationStart = System.currentTimeMillis();
echo = proxy2.echo(message);
assertInvocationTimeLessThan("org.jboss.ejb.client.discovery.additional-node-timeout ineffective", 3000, invocationStart);
Assert.assertEquals(message, echo);

}

}
}

private static void assertInvocationTimeLessThan(String message, long maximumInvocationTimeMs, long invocationStart) {
long invocationTime = System.currentTimeMillis() - invocationStart;
if(invocationTime > maximumInvocationTimeMs)
Assert.fail(String.format("%s: invocation time: %d > maximum expected invocation time: %d", message, invocationTime, maximumInvocationTimeMs));
}
}
6 changes: 4 additions & 2 deletions src/test/resources/broken-server-jboss-ejb-client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=one
remote.connections=one,two

# connection to a node at protocol://host:port
remote.connection.one.host=localhost
remote.connection.one.port=6999
remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.one.username=test
remote.connection.one.password=test
remote.connection.one.protocol=remote
remote.connection.two.host=localhost
remote.connection.two.port=6998
remote.connection.two.port=7099
remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.two.username=test
remote.connection.two.password=test
remote.connection.two.protocol=remote

0 comments on commit fb47fbe

Please sign in to comment.