From c82ac631b8a49136c597724432b9a80c42bfe6cc Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Tue, 18 Apr 2017 12:43:58 -0400 Subject: [PATCH] NO-JIRA fixing NettySecurityClientTest --- .../core/remoting/impl/netty/Epoll.java | 20 +++++++++++++------ .../integration/client/JournalCrashTest.java | 2 +- .../cluster/RealNodeManagerTest.java | 2 +- .../security/NettySecurityClientTest.java | 3 +-- .../integration/security/SimpleClient.java | 5 ++++- .../restricted-security-client.policy | 3 +++ .../artemis/tests/util/SpawnedVMSupport.java | 14 ++++++++----- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/Epoll.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/Epoll.java index 96af01722d..40612d40f6 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/Epoll.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/Epoll.java @@ -18,20 +18,28 @@ package org.apache.activemq.artemis.core.remoting.impl.netty; import org.apache.activemq.artemis.utils.Env; +import org.jboss.logging.Logger; /** * Tells if {@code netty-transport-native-epoll} is supported. */ public final class Epoll { - private static final boolean IS_AVAILABLE_EPOLL; + private static final Logger logger = Logger.getLogger(Epoll.class); + private static final boolean IS_AVAILABLE_EPOLL = isIsAvailableEpoll(); - static { - if (Env.is64BitJvm() && Env.isLinuxOs()) { - IS_AVAILABLE_EPOLL = io.netty.channel.epoll.Epoll.isAvailable(); - } else { - IS_AVAILABLE_EPOLL = false; + private static boolean isIsAvailableEpoll() { + try { + if (Env.is64BitJvm() && Env.isLinuxOs()) { + return io.netty.channel.epoll.Epoll.isAvailable(); + } else { + return false; + } + } catch (Throwable e) { + logger.warn(e.getMessage(), e); + return false; } + } private Epoll() { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java index 88bfd7a7ce..49453d3d37 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java @@ -164,7 +164,7 @@ public class JournalCrashTest extends ActiveMQTestBase { */ private void runExternalProcess(final String tempDir, final int start, final int end) throws Exception { System.err.println("running external process..."); - Process process = SpawnedVMSupport.spawnVM(this.getClass().getCanonicalName(), "-Xms128m", "-Xmx128m", new String[]{}, true, true, tempDir, Integer.toString(start), Integer.toString(end)); + Process process = SpawnedVMSupport.spawnVM(this.getClass().getCanonicalName(), "-Xms128m", "-Xmx128m", new String[]{}, true, true, true, tempDir, Integer.toString(start), Integer.toString(end)); Assert.assertEquals(100, process.waitFor()); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java index 34849321d7..1a49f94fcf 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java @@ -45,7 +45,7 @@ public class RealNodeManagerTest extends NodeManagerTest { public void performWork(NodeManagerAction... actions) throws Exception { List processes = new ArrayList<>(); for (NodeManagerAction action : actions) { - Process p = SpawnedVMSupport.spawnVM(NodeManagerAction.class.getName(), "-Xms512m", "-Xmx512m", new String[0], true, true, action.getWork()); + Process p = SpawnedVMSupport.spawnVM(NodeManagerAction.class.getName(), "-Xms512m", "-Xmx512m", new String[0], true, true, true, action.getWork()); processes.add(p); } for (Process process : processes) { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/NettySecurityClientTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/NettySecurityClientTest.java index 8c876b23a9..a908f79a58 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/NettySecurityClientTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/NettySecurityClientTest.java @@ -66,14 +66,13 @@ public class NettySecurityClientTest extends ActiveMQTestBase { // spawn a JVM that creates a client with a security manager which sends and receives a // test message - Process p = SpawnedVMSupport.spawnVM(SimpleClient.class.getName(), "-Xms512m", "-Xmx512m", vmargs, false, true, new String[]{NETTY_CONNECTOR_FACTORY}); + Process p = SpawnedVMSupport.spawnVM(SimpleClient.class.getName(), "-Xms512m", "-Xmx512m", vmargs, true, true, false, new String[]{NETTY_CONNECTOR_FACTORY}); InputStreamReader isr = new InputStreamReader(p.getInputStream()); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { - //System.out.println(line); line = line.replace('|', '\n'); if (line.startsWith("Listening")) { continue; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/SimpleClient.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/SimpleClient.java index 0dd9eb6d35..65c980b534 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/SimpleClient.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/SimpleClient.java @@ -37,12 +37,14 @@ final class SimpleClient { if (args.length != 1) { throw new Exception("require 1 argument: connector factory class name"); } + + System.out.println("I'm here"); String connectorFactoryClassName = args[0]; String queueName = RandomUtil.randomString(); String messageText = RandomUtil.randomString(); - ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(connectorFactoryClassName)); + ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(connectorFactoryClassName)).setReconnectAttempts(1).setInitialConnectAttempts(1); try { ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(false, true, true); @@ -77,6 +79,7 @@ final class SimpleClient { locator.close(); } } catch (Throwable t) { + t.printStackTrace(System.out); String allStack = t.getMessage() + "|"; StackTraceElement[] stackTrace = t.getStackTrace(); diff --git a/tests/integration-tests/src/test/resources/restricted-security-client.policy b/tests/integration-tests/src/test/resources/restricted-security-client.policy index ecd4081c39..4b5d5d753c 100644 --- a/tests/integration-tests/src/test/resources/restricted-security-client.policy +++ b/tests/integration-tests/src/test/resources/restricted-security-client.policy @@ -29,6 +29,9 @@ grant { permission java.util.PropertyPermission "activemq.artemis.client.global.thread.pool.max.size", "read"; permission java.util.PropertyPermission "activemq.artemis.client.global.scheduled.thread.pool.core.size", "read"; permission java.util.PropertyPermission "io.netty.eventLoopThreads", "read"; + permission java.util.PropertyPermission "io.netty.maxThreadLocalCharBufferSize", "read"; + permission java.util.PropertyPermission "io.netty.batch.bytes", "read"; + permission java.util.PropertyPermission "com.ibm.vm.bitmode", "read"; permission java.util.PropertyPermission "io.netty.noUnsafe", "read"; permission java.util.PropertyPermission "io.netty.tryUnsafe", "read"; permission java.util.PropertyPermission "org.jboss.netty.tryUnsafe", "read"; diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java index 1ed0e73f4c..c1153bc25f 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java @@ -57,7 +57,7 @@ public final class SpawnedVMSupport { final String[] vmargs, final boolean logOutput, final String... args) throws Exception { - return SpawnedVMSupport.spawnVM(className, "-Xms512m", "-Xmx512m", vmargs, logOutput, true, args); + return SpawnedVMSupport.spawnVM(className, "-Xms512m", "-Xmx512m", vmargs, logOutput, true, true, args); } public static Process spawnVMWithLogMacher(String wordMatch, @@ -66,7 +66,7 @@ public final class SpawnedVMSupport { final String[] vmargs, final boolean logOutput, final String... args) throws Exception { - return SpawnedVMSupport.spawnVM(wordMatch, runnable, className, "-Xms512m", "-Xmx512m", vmargs, logOutput, true, args); + return SpawnedVMSupport.spawnVM(wordMatch, runnable, className, "-Xms512m", "-Xmx512m", vmargs, logOutput, true, true, args); } public static Process spawnVM(final String className, @@ -75,8 +75,9 @@ public final class SpawnedVMSupport { final String[] vmargs, final boolean logOutput, final boolean logErrorOutput, + final boolean useLogging, final String... args) throws Exception { - return spawnVM(null, null, className, memoryArg1, memoryArg2, vmargs, logOutput, logErrorOutput, args); + return spawnVM(null, null, className, memoryArg1, memoryArg2, vmargs, logOutput, logErrorOutput, useLogging, args); } public static Process spawnVM(final String wordMatch, @@ -87,6 +88,7 @@ public final class SpawnedVMSupport { final String[] vmargs, final boolean logOutput, final boolean logErrorOutput, + final boolean useLogging, final String... args) throws Exception { ProcessBuilder builder = new ProcessBuilder(); final String javaPath = Paths.get(System.getProperty("java.home"), "bin", "java").toAbsolutePath().toString(); @@ -102,8 +104,10 @@ public final class SpawnedVMSupport { } // The logs will be huge if you don't set this - commandList.add("-Djava.util.logging.manager=org.jboss.logmanager.LogManager"); - commandList.add("-Dlogging.configuration=file:../config/logging.properties"); + if (useLogging) { + commandList.add("-Djava.util.logging.manager=org.jboss.logmanager.LogManager"); + commandList.add("-Dlogging.configuration=file:../config/logging.properties"); + } commandList.add("-Djava.io.tmpdir=" + System.getProperty("java.io.tmpdir", "./tmp")); commandList.add("-Djava.library.path=" + System.getProperty("java.library.path", "./native/bin"));