Skip to content

Commit

Permalink
7539: JDP Tests failing in VPN environments
Browse files Browse the repository at this point in the history
Reviewed-by: clanger, hirt
  • Loading branch information
parttimenerd authored and thegreystone committed Jan 24, 2022
1 parent 7037e74 commit f3ca1b1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 7 deletions.
13 changes: 9 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fi
JETTY_PID=""
BASEDIR=""
JMC_DIR=""
JVM_ARGUMENTS=""

function err_report() {
err_log "$(date +%T) ${PROGNAME}: Error on line $1"
Expand Down Expand Up @@ -86,6 +87,7 @@ function printHelp() {
printf " \t%s\t%s\n" "--installCore" "to install JMC core"
printf " \t%s\t%s\n" "--packageJmc" "to package JMC"
printf " \t%s\t%s\n" "--packageAgent" "to package Agent"
printf " \t%s\t%s\n" "--skipJDPMulticastTests" "skip multicast related tests"
printf " \t%s\t%s\n" "--clean" "to run maven clean"
printf " \t%s\t%s\n" "--run" "to run JMC, once it is packaged"
printf " \t%s\t%s\n" "--runAgentExample" "to run Agent 'InstrumentMe' example, once it is packaged"
Expand All @@ -103,15 +105,15 @@ function runTests() {
local timestamp=$1
startJetty $timestamp
echo "${timestamp} running tests"
mvn verify
mvn ${JVM_ARGUMENTS} verify
}

function runUiTests() {
local timestamp=$1
startJetty $timestamp
installCore $timestamp
echo "$(date +%T) running UI tests"
mvn verify -P uitests
mvn ${JVM_ARGUMENTS} verify -P uitests
}

function packageJmc() {
Expand All @@ -121,7 +123,7 @@ function packageJmc() {
local packageLog="${BASEDIR}/build_${timestamp}.4.package.log"

echo "$(date +%T) packaging jmc - logging output to ${packageLog}"
mvn package --log-file "${packageLog}"
mvn ${JVM_ARGUMENTS} package --log-file "${packageLog}"

if [[ "${OSTYPE}" =~ "linux"* ]]; then
echo "You can now run jmc by calling \"${PROGNAME} --run\" or \"${BASEDIR}/products/org.openjdk.jmc/linux/gtk/${ARCH}/JDK\ Mission\ Control/jmc\""
Expand All @@ -142,7 +144,7 @@ function packageAgent() {
}

echo "$(date +%T) packaging jmc agent - logging output to ${packageLog}"
mvn package --log-file "${packageLog}"
mvn ${JVM_ARGUMENTS} package --log-file "${packageLog}"

popd 1> /dev/null || {
err_log "could not go to project root directory"
Expand Down Expand Up @@ -294,6 +296,9 @@ function parseArgs() {
--runAgentConverterExample)
runAgentByClass "org.openjdk.jmc.agent.converters.test.InstrumentMeConverter"
;;
--skipJDPMulticastTests)
JVM_ARGUMENTS="${JVM_ARGUMENTS} -DskipJDPMulticastTests=true"
;;
*)
err_log "unknown arguments: $@"
printHelp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -41,6 +41,7 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -62,6 +63,7 @@ public void setUp() throws Exception {

@Test
public void testJDPClient() throws Exception {
Assume.assumeTrue(TestToolkit.areBroadcastingTestsEnabled());
JDPClient client = createDefaultClient();
JDPServer server = createDefaultServer();
client.start();
Expand All @@ -83,6 +85,7 @@ public void testJDPClient() throws Exception {

@Test
public void testChangePacket() throws Exception {
Assume.assumeTrue(TestToolkit.areBroadcastingTestsEnabled());
JDPClient client = createDefaultClient();
JDPServer server = createDefaultServer();
client.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.openjdk.jmc.jdp.common.Configuration;
Expand All @@ -58,6 +59,7 @@ public void setUp() throws Exception {

@Test
public void testJDPClient() throws Exception {
Assume.assumeTrue(TestToolkit.areBroadcastingTestsEnabled());
JDPClient client = createDefaultClient();
JDPServer server = TestToolkit.createDefaultJMXJDPServer(discoverableID);
TestToolkit.printServerSettings(server);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -32,9 +32,12 @@
*/
package org.openjdk.jmc.jdp.client;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.logging.Level;
Expand Down Expand Up @@ -148,4 +151,65 @@ private static byte[] toBytes(String[] tmp) {
}
return bytes;
}

/**
* See https://bugs.openjdk.java.net/browse/JMC-7539
*/
public static boolean areBroadcastingTestsEnabled() {
if (Boolean.getBoolean("skipJDPMulticastTests")) {
JDPClientTest.LOGGER.log(Level.INFO, "Broadcasting related tests are disabled");
return false;
}
if (!isBroadcastingPossible()) {
String os = System.getProperty("os.name").toLowerCase();
String helpMessage = ", you could try ";
String address = TEST_MULTICAST_ADDRESS.getCanonicalHostName();
if (os.startsWith("mac") || os.startsWith("darwin")) {
helpMessage += String.format("'sudo route add -host %s -interface en0'", address);
} else if (os.startsWith("linux")) {
helpMessage += String.format("'sudo ip route add %s dev eth0'", address);
} else if (os.startsWith("win")) {
helpMessage += String.format("'route add %s <gateway>' in a shell with administrator permissions",
address);
} else {
helpMessage = "";
}
JDPClientTest.LOGGER.log(Level.WARNING, "Broadcasting does not seem to be possible.\n"
+ "This is usually related to VPN. There are three possible ways to remedy this:\n"
+ " 1. Try to configure your VPN, or perhaps turn it off.\n"
+ " 2. Add a proper route for local multicast" + helpMessage + ".\n"
+ " 3. If the two above really can't be made to work, use -DskipJDPMulticastTests=true (with Java or maven)\n"
+ " or --skipJDPMulticastTests (as first argument of the build script)");
}
return true;
}

private static boolean isBroadcastingPossible() {
InetAddress multiCastAddress = TEST_MULTICAST_ADDRESS;
int multiCastPort = 7711;
Thread thread = new Thread(() -> {
try (MulticastSocket ssocket = new MulticastSocket(multiCastPort)) {
ssocket.setTimeToLive(1);
ssocket.joinGroup(multiCastAddress);
final DatagramPacket dp = new DatagramPacket(new byte[] {1}, 1, multiCastAddress, multiCastPort);
while (true) {
ssocket.send(dp);
Thread.sleep(10);
}
} catch (InterruptedException | IOException e) {
}
});
thread.start();
try (MulticastSocket socket = new MulticastSocket(multiCastPort)) {
socket.joinGroup(multiCastAddress);
byte[] buffer = new byte[4096];
socket.setSoTimeout(300);
socket.receive(new DatagramPacket(buffer, buffer.length));
return true;
} catch (IOException e) {
} finally {
thread.interrupt();
}
return false;
}
}

0 comments on commit f3ca1b1

Please sign in to comment.