-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARTEMIS-4081 Comparing upgrades against fresh instances and some adju…
…stments
- Loading branch information
1 parent
3040336
commit 03dec4e
Showing
29 changed files
with
398 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
artemis-cli/src/main/java/org/apache/activemq/artemis/util/JVMArgumentParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.activemq.artemis.util; | ||
|
||
import java.util.Map; | ||
|
||
public class JVMArgumentParser { | ||
|
||
public static void parseOriginalArgs(String prefix, String endOfLine, String originalLine, String[] keepingPrefixes, Map<String, String> originalArgs) { | ||
originalLine = originalLine.trim(); | ||
String line = originalLine.substring(prefix.length(), originalLine.length() - endOfLine.length()); | ||
String[] split = line.split(" "); | ||
for (String s : split) { | ||
for (String k : keepingPrefixes) { | ||
if (s.startsWith(k)) { | ||
originalArgs.put(k, s); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static String parseNewLine(String prefix, String endOfLine, String newLine, String[] keepingPrefixes, Map<String, String> originalArgs) { | ||
String spacesBeginning = newLine.substring(0, newLine.indexOf(prefix)); | ||
newLine = newLine.trim(); | ||
StringBuffer output = new StringBuffer(); | ||
String line = newLine.substring(prefix.length(), newLine.length() - endOfLine.length()); | ||
String[] split = line.split(" "); | ||
for (String s : split) { | ||
for (String k : keepingPrefixes) { | ||
if (s.startsWith(k)) { | ||
String value = originalArgs.get(k); | ||
if (value != null) { | ||
s = value; | ||
} | ||
break; | ||
} | ||
} | ||
output.append(s); | ||
output.append(" "); | ||
} | ||
|
||
return spacesBeginning + prefix + output + endOfLine; | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
artemis-cli/src/test/java/org/apache/activemq/artemis/util/JVMArgumentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.activemq.artemis.util; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class JVMArgumentTest { | ||
|
||
@Test | ||
public void testArgumentsWindows() { | ||
String arguments = "IF \"%JAVA_ARGS%\"==\"\" (set JAVA_ARGS= -must-go -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms333M -Xmx77G -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.role=amq -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE%)"; | ||
|
||
String prefix = "IF \"%JAVA_ARGS%\"==\"\" (set JAVA_ARGS= "; | ||
|
||
String[] fixedArguments = new String[]{"-Xmx", "-Xms"}; | ||
|
||
HashMap<String, String> usedArgs = new HashMap<>(); | ||
JVMArgumentParser.parseOriginalArgs(prefix, "\"", arguments, fixedArguments, usedArgs); | ||
Assert.assertEquals(2, usedArgs.size()); | ||
Assert.assertEquals("-Xmx77G", usedArgs.get("-Xmx")); | ||
Assert.assertEquals("-Xms333M", usedArgs.get("-Xms")); | ||
|
||
String newLine = "IF \"%JAVA_ARGS%\"==\"\" (set JAVA_ARGS= -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx1G -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.role=amq -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE%)"; | ||
|
||
String resultLine = JVMArgumentParser.parseNewLine(prefix, "\"", newLine, fixedArguments, usedArgs); | ||
|
||
System.out.println("output::" + resultLine); | ||
|
||
Assert.assertFalse(resultLine.contains("-must-go")); | ||
Assert.assertTrue(resultLine.contains("-Xmx77G")); | ||
Assert.assertTrue(resultLine.contains("-Xms333M")); | ||
Assert.assertFalse(resultLine.contains("-Xmx1G")); | ||
Assert.assertFalse(resultLine.contains("-Xmx512M")); | ||
} | ||
|
||
|
||
@Test | ||
public void testArgumentsLinux() { | ||
String arguments = " JAVA_ARGS=\"-must-go -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms333M -Xmx77G -Dhawtio.disableProxy=true -Dhawtio.realm=activemq -Dhawtio.offline=true -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=${ARTEMIS_INSTANCE_ETC_URI}jolokia-access.xml \""; | ||
|
||
String prefix = "JAVA_ARGS="; | ||
|
||
String[] fixedArguments = new String[]{"-Xmx", "-Xms"}; | ||
|
||
HashMap<String, String> usedArgs = new HashMap<>(); | ||
JVMArgumentParser.parseOriginalArgs(prefix, "\"", arguments, fixedArguments, usedArgs); | ||
Assert.assertEquals(2, usedArgs.size()); | ||
Assert.assertEquals("-Xmx77G", usedArgs.get("-Xmx")); | ||
Assert.assertEquals("-Xms333M", usedArgs.get("-Xms")); | ||
|
||
String newLine = " JAVA_ARGS= -XX:AutoBoxCacheMax=20000 -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx1G -Djava.security.auth.login.config=%ARTEMIS_ETC_DIR%\\login.config -Dhawtio.disableProxy=true -Dhawtio.offline=true -Dhawtio.realm=activemq -Dhawtio.role=amq -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%\\jolokia-access.xml -Dartemis.instance=%ARTEMIS_INSTANCE%)"; | ||
|
||
String resultLine = JVMArgumentParser.parseNewLine(prefix, "\"", newLine, fixedArguments, usedArgs); | ||
|
||
System.out.println("output::" + resultLine); | ||
|
||
Assert.assertFalse(resultLine.contains("-must-go")); | ||
Assert.assertTrue(resultLine.contains("-Xmx77G")); | ||
Assert.assertTrue(resultLine.contains("-Xms333M")); | ||
Assert.assertFalse(resultLine.contains("-Xmx1G")); | ||
Assert.assertFalse(resultLine.contains("-Xmx512M")); | ||
|
||
Assert.assertTrue(resultLine.startsWith(" ")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.