提交 803dc1c5 编写于 作者: A asaha

Merge

......@@ -34,6 +34,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.KeyEvent;
import java.util.Locale;
/**
* Translates NSEvents/NPCocoaEvents into AWT events.
......@@ -171,6 +172,16 @@ final class CPlatformResponder {
}
}
// If Pinyin Simplified input method is selected, CAPS_LOCK key is supposed to switch
// input to latin letters.
// It is necessary to use testCharIgnoringModifiers instead of testChar for event
// generation in such case to avoid uppercase letters in text components.
LWCToolkit lwcToolkit = (LWCToolkit)Toolkit.getDefaultToolkit();
if (lwcToolkit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK) &&
Locale.SIMPLIFIED_CHINESE.equals(lwcToolkit.getDefaultKeyboardLocale())) {
testChar = testCharIgnoringModifiers;
}
jkeyCode = out[0];
jkeyLocation = out[1];
jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
......
......@@ -536,8 +536,10 @@ AWT_ASSERT_APPKIT_THREAD;
}
-(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint {
if ((codePoint >= 0x3000) && (codePoint <= 0x303F)) {
// Code point is in 'CJK Symbols and Punctuation' Unicode block.
if (((codePoint >= 0x3000) && (codePoint <= 0x303F)) ||
((codePoint >= 0xFF00) && (codePoint <= 0xFFEF))) {
// Code point is in 'CJK Symbols and Punctuation' or
// 'Halfwidth and Fullwidth Forms' Unicode block.
return YES;
}
return NO;
......
......@@ -71,6 +71,17 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi {
initialize(1024, null);
}
private static void checkKeySize(int keysize)
throws InvalidParameterException {
if ((keysize < 512) || (keysize > 2048) || ((keysize & 0x3F) != 0)) {
throw new InvalidParameterException(
"DH key size must be multiple of 64, and can only range " +
"from 512 to 2048 (inclusive). " +
"The specific key size " + keysize + " is not supported");
}
}
/**
* Initializes this key pair generator for a certain keysize and source of
* randomness.
......@@ -80,12 +91,8 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi {
* @param random the source of randomness
*/
public void initialize(int keysize, SecureRandom random) {
if ((keysize < 512) || (keysize > 2048) || (keysize % 64 != 0)) {
throw new InvalidParameterException("Keysize must be multiple "
+ "of 64, and can only range "
+ "from 512 to 2048 "
+ "(inclusive)");
}
checkKeySize(keysize);
this.pSize = keysize;
this.lSize = 0;
this.random = random;
......@@ -115,11 +122,10 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi {
params = (DHParameterSpec)algParams;
pSize = params.getP().bitLength();
if ((pSize < 512) || (pSize > 2048) ||
(pSize % 64 != 0)) {
throw new InvalidAlgorithmParameterException
("Prime size must be multiple of 64, and can only range "
+ "from 512 to 2048 (inclusive)");
try {
checkKeySize(pSize);
} catch (InvalidParameterException ipe) {
throw new InvalidAlgorithmParameterException(ipe.getMessage());
}
// exponent size is optional, could be 0
......
......@@ -59,12 +59,13 @@ extends AlgorithmParameterGeneratorSpi {
private SecureRandom random = null;
private static void checkKeySize(int keysize)
throws InvalidAlgorithmParameterException {
if ((keysize != 2048) &&
throws InvalidParameterException {
if ((keysize != 2048) &&
((keysize < 512) || (keysize > 1024) || (keysize % 64 != 0))) {
throw new InvalidAlgorithmParameterException(
"Keysize must be multiple of 64 ranging from "
+ "512 to 1024 (inclusive), or 2048");
throw new InvalidParameterException(
"DH key size must be multiple of 64 and range " +
"from 512 to 1024 (inclusive), or 2048. " +
"The specific key size " + keysize + " is not supported");
}
}
......@@ -78,11 +79,7 @@ extends AlgorithmParameterGeneratorSpi {
*/
protected void engineInit(int keysize, SecureRandom random) {
// Re-uses DSA parameters and thus have the same range
try {
checkKeySize(keysize);
} catch (InvalidAlgorithmParameterException ex) {
throw new InvalidParameterException(ex.getMessage());
}
checkKeySize(keysize);
this.primeSize = keysize;
this.random = random;
}
......@@ -111,7 +108,11 @@ extends AlgorithmParameterGeneratorSpi {
primeSize = dhParamSpec.getPrimeSize();
// Re-uses DSA parameters and thus have the same range
checkKeySize(primeSize);
try {
checkKeySize(primeSize);
} catch (InvalidParameterException ipe) {
throw new InvalidAlgorithmParameterException(ipe.getMessage());
}
exponentSize = dhParamSpec.getExponentSize();
if (exponentSize <= 0) {
......
/*
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......
......@@ -300,7 +300,7 @@ abstract class AbstractLdapNamingEnumeration<T extends NameClassPair>
errEx = e;
}
protected abstract AbstractLdapNamingEnumeration<T> getReferredResults(
protected abstract AbstractLdapNamingEnumeration<? extends NameClassPair> getReferredResults(
LdapReferralContext refCtx) throws NamingException;
/*
......@@ -360,7 +360,7 @@ abstract class AbstractLdapNamingEnumeration<T extends NameClassPair>
* Merge the entries and/or referrals from the supplied enumeration
* with those of the current enumeration.
*/
protected void update(AbstractLdapNamingEnumeration<T> ne) {
protected void update(AbstractLdapNamingEnumeration<? extends NameClassPair> ne) {
// Cleanup previous context first
homeCtx.decEnumCount();
......
/*
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -60,7 +60,6 @@ class DigestClientId extends SimpleClientId {
final private String[] propvals;
final private int myHash;
private int pHash = 0;
DigestClientId(int version, String hostname, int port,
String protocol, Control[] bindCtls, OutputStream trace,
......@@ -78,12 +77,9 @@ class DigestClientId extends SimpleClientId {
propvals = new String[SASL_PROPS.length];
for (int i = 0; i < SASL_PROPS.length; i++) {
propvals[i] = (String) env.get(SASL_PROPS[i]);
if (propvals[i] != null) {
pHash = pHash * 31 + propvals[i].hashCode();
}
}
}
myHash = super.hashCode() + pHash;
myHash = super.hashCode() ^ Arrays.hashCode(propvals);
}
public boolean equals(Object obj) {
......@@ -92,7 +88,6 @@ class DigestClientId extends SimpleClientId {
}
DigestClientId other = (DigestClientId)obj;
return myHash == other.myHash
&& pHash == other.pHash
&& super.equals(obj)
&& Arrays.equals(propvals, other.propvals);
}
......
......@@ -104,9 +104,9 @@ final class LdapBindingEnumeration
}
@Override
protected LdapBindingEnumeration getReferredResults(
protected AbstractLdapNamingEnumeration<? extends NameClassPair> getReferredResults(
LdapReferralContext refCtx) throws NamingException{
// repeat the original operation at the new context
return (LdapBindingEnumeration)refCtx.listBindings(listArg);
return (AbstractLdapNamingEnumeration<? extends NameClassPair>)refCtx.listBindings(listArg);
}
}
......@@ -72,9 +72,9 @@ final class LdapNamingEnumeration
}
@Override
protected LdapNamingEnumeration getReferredResults(
protected AbstractLdapNamingEnumeration<? extends NameClassPair> getReferredResults(
LdapReferralContext refCtx) throws NamingException {
// repeat the original operation at the new context
return (LdapNamingEnumeration)refCtx.list(listArg);
return (AbstractLdapNamingEnumeration<? extends NameClassPair>)refCtx.list(listArg);
}
}
......@@ -199,15 +199,15 @@ final class LdapSearchEnumeration
}
@Override
protected LdapSearchEnumeration getReferredResults(
protected AbstractLdapNamingEnumeration<? extends NameClassPair> getReferredResults(
LdapReferralContext refCtx) throws NamingException {
// repeat the original operation at the new context
return (LdapSearchEnumeration)refCtx.search(
return (AbstractLdapNamingEnumeration<? extends NameClassPair>)refCtx.search(
searchArgs.name, searchArgs.filter, searchArgs.cons);
}
@Override
protected void update(AbstractLdapNamingEnumeration<SearchResult> ne) {
protected void update(AbstractLdapNamingEnumeration<? extends NameClassPair> ne) {
super.update(ne);
// Update search-specific variables
......
/*
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -49,21 +49,23 @@ class SimpleClientId extends ClientId {
socketFactory);
this.username = username;
int pwdHashCode = 0;
if (passwd == null) {
this.passwd = null;
} else if (passwd instanceof String) {
this.passwd = passwd;
} else if (passwd instanceof byte[]) {
this.passwd = ((byte[])passwd).clone();
pwdHashCode = Arrays.hashCode((byte[])passwd);
} else if (passwd instanceof char[]) {
this.passwd = ((char[])passwd).clone();
pwdHashCode = Arrays.hashCode((char[])passwd);
} else {
this.passwd = passwd;
pwdHashCode = passwd.hashCode();
}
myHash = super.hashCode()
+ (username != null ? username.hashCode() : 0)
+ (passwd != null ? passwd.hashCode() : 0);
^ (username != null ? username.hashCode() : 0)
^ pwdHashCode;
}
public boolean equals(Object obj) {
......
......@@ -118,7 +118,11 @@ final public class Pool {
PooledConnectionFactory factory) throws NamingException {
d("get(): ", id);
d("size: ", map.size());
if (debug) {
synchronized (map) {
d("size: ", map.size());
}
}
expungeStaleConnections();
......@@ -141,10 +145,9 @@ final public class Pool {
// Keep the weak reference through the element of a linked list
weakRefs.add(weakRef);
}
d("get(): size after: ", map.size());
}
d("get(): size after: ", map.size());
return conns.get(timeout, factory); // get one connection from list
}
......@@ -209,19 +212,24 @@ final public class Pool {
out.println("maximum pool size: " + maxSize);
out.println("preferred pool size: " + prefSize);
out.println("initial pool size: " + initSize);
out.println("current pool size: " + map.size());
for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
id = entry.getKey();
conns = entry.getValue().getConnections();
out.println(" " + id + ":" + conns.getStats());
synchronized (map) {
out.println("current pool size: " + map.size());
for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
id = entry.getKey();
conns = entry.getValue().getConnections();
out.println(" " + id + ":" + conns.getStats());
}
}
out.println("====== Pool end =====================");
}
public String toString() {
return super.toString() + " " + map.toString();
synchronized (map) {
return super.toString() + " " + map.toString();
}
}
private void d(String msg, int i) {
......
......@@ -1006,6 +1006,8 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
if (e.getStateChange() == ItemEvent.SELECTED) {
JComboBox comboBox = (JComboBox)e.getSource();
setListSelection(comboBox.getSelectedIndex());
} else {
setListSelection(-1);
}
}
......
......@@ -270,10 +270,21 @@ public final class CompositeFont extends Font2D {
if (componentNames[slot] == null) {
componentNames[slot] = name;
} else if (!componentNames[slot].equalsIgnoreCase(name)) {
components[slot] =
(PhysicalFont) fm.findFont2D(componentNames[slot],
style,
/* If a component specifies the file with a bad font,
* the corresponding slot will be initialized by
* default physical font. In such case findFont2D may
* return composite font which cannot be casted to
* physical font.
*/
try {
components[slot] =
(PhysicalFont) fm.findFont2D(componentNames[slot],
style,
FontManager.PHYSICAL_FALLBACK);
} catch (ClassCastException cce) {
/* Assign default physical font to the slot */
components[slot] = fm.getDefaultPhysicalFont();
}
}
}
deferredInitialisation[slot] = false;
......
......@@ -44,7 +44,7 @@ public final class ScriptRunData {
if (cp >= data[cache] && cp < data[cache+2]) {
return data[cache+1];
}
if (cp >= CHAR_START & cp < CHAR_LIMIT) {
if ((cp >= CHAR_START) && (cp < CHAR_LIMIT)) {
int probe = dataPower;
int index = 0;
......
......@@ -525,9 +525,9 @@ public class Config {
String previous = null;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.startsWith("#") || line.isEmpty()) {
if (line.isEmpty() || line.startsWith("#") || line.startsWith(";")) {
// ignore comments and blank line
// Comments start with #.
// Comments start with '#' or ';'
continue;
}
// In practice, a subsection might look like:
......
......@@ -228,29 +228,34 @@ final class P11KeyPairGenerator extends KeyPairGeneratorSpi {
// check native range first
if ((minKeySize != -1) && (keySize < minKeySize)) {
throw new InvalidAlgorithmParameterException(algorithm +
" key must be at least " + minKeySize + " bits");
" key must be at least " + minKeySize + " bits. " +
"The specific key size " + keySize + " is not supported");
}
if ((maxKeySize != -1) && (keySize > maxKeySize)) {
throw new InvalidAlgorithmParameterException(algorithm +
" key must be at most " + maxKeySize + " bits");
" key must be at most " + maxKeySize + " bits. " +
"The specific key size " + keySize + " is not supported");
}
// check our own algorithm-specific limits also
if (algorithm.equals("EC")) {
if (keySize < 112) {
throw new InvalidAlgorithmParameterException
("Key size must be at least 112 bit");
throw new InvalidAlgorithmParameterException(
"EC key size must be at least 112 bit. " +
"The specific key size " + keySize + " is not supported");
}
if (keySize > 2048) {
// sanity check, nobody really wants keys this large
throw new InvalidAlgorithmParameterException
("Key size must be at most 2048 bit");
throw new InvalidAlgorithmParameterException(
"EC key size must be at most 2048 bit. " +
"The specific key size " + keySize + " is not supported");
}
} else {
// RSA, DH, DSA
if (keySize < 512) {
throw new InvalidAlgorithmParameterException
("Key size must be at least 512 bit");
throw new InvalidAlgorithmParameterException(algorithm +
" key size must be at least 512 bit. " +
"The specific key size " + keySize + " is not supported");
}
if (algorithm.equals("RSA")) {
BigInteger tmpExponent = rsaPublicExponent;
......@@ -271,8 +276,10 @@ final class P11KeyPairGenerator extends KeyPairGeneratorSpi {
if (algorithm.equals("DH") && (params != null)) {
// sanity check, nobody really wants keys this large
if (keySize > 64 * 1024) {
throw new InvalidAlgorithmParameterException
("Key size must be at most 65536 bit");
throw new InvalidAlgorithmParameterException(
"DH key size must be at most 65536 bit. " +
"The specific key size " +
keySize + " is not supported");
}
} else {
// this restriction is in the spec for DSA
......@@ -282,7 +289,9 @@ final class P11KeyPairGenerator extends KeyPairGeneratorSpi {
((keySize > 1024) || ((keySize & 0x3f) != 0))) {
throw new InvalidAlgorithmParameterException(algorithm +
" key must be multiples of 64 if less than 1024 bits" +
", or 2048 bits");
", or 2048 bits. " +
"The specific key size " +
keySize + " is not supported");
}
}
}
......
......@@ -137,8 +137,10 @@ final class ServerHandshaker extends Handshaker {
customizedDHKeySize = Integer.parseUnsignedInt(property);
if (customizedDHKeySize < 1024 || customizedDHKeySize > 2048) {
throw new IllegalArgumentException(
"Customized DH key size should be positive integer " +
"between 1024 and 2048 bits, inclusive");
"Unsupported customized DH key size: " +
customizedDHKeySize + ". " +
"The key size can only range from 1024" +
" to 2048 (inclusive)");
}
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException(
......
......@@ -71,11 +71,8 @@ import java.text.MessageFormat;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.file.Files;
import java.io.UnsupportedEncodingException;
import java.nio.charset.UnsupportedCharsetException;
import sun.tools.native2ascii.A2NFilter;
import sun.tools.native2ascii.N2AFilter;
/**
* Main program of the native2ascii
......@@ -94,7 +91,7 @@ public class Main {
/**
* Run the converter
*/
public synchronized boolean convert(String argv[]){
public synchronized boolean convert(String argv[]) {
List<String> v = new ArrayList<>(2);
File outputFile = null;
boolean createOutputFile = false;
......@@ -102,14 +99,14 @@ public class Main {
// Parse arguments
for (int i = 0; i < argv.length; i++) {
if (argv[i].equals("-encoding")) {
if ((i + 1) < argv.length){
if ((i + 1) < argv.length) {
encodingString = argv[++i];
} else {
error(getMsg("err.bad.arg"));
usage();
return false;
}
} else if (argv[i].equals("-reverse")){
} else if (argv[i].equals("-reverse")) {
reverse = true;
} else {
if (v.size() > 1) {
......@@ -119,15 +116,18 @@ public class Main {
v.add(argv[i]);
}
}
if (encodingString == null)
defaultEncoding = Charset.defaultCharset().name();
if (encodingString == null) {
defaultEncoding = Charset.defaultCharset().name();
}
char[] lineBreak = System.getProperty("line.separator").toCharArray();
try {
initializeConverter();
if (v.size() == 1)
if (v.size() == 1) {
inputFileName = v.get(0);
}
if (v.size() == 2) {
inputFileName = v.get(0);
......@@ -137,40 +137,38 @@ public class Main {
if (createOutputFile) {
outputFile = new File(outputFileName);
if (outputFile.exists() && !outputFile.canWrite()) {
throw new Exception(formatMsg("err.cannot.write", outputFileName));
}
if (outputFile.exists() && !outputFile.canWrite()) {
throw new Exception(formatMsg("err.cannot.write", outputFileName));
}
}
if (reverse){
BufferedReader reader = getA2NInput(inputFileName);
Writer osw = getA2NOutput(outputFileName);
String line;
while ((line = reader.readLine()) != null) {
osw.write(line.toCharArray());
osw.write(lineBreak);
if (outputFileName == null) { // flush stdout
osw.flush();
if (reverse) {
try (BufferedReader reader = getA2NInput(inputFileName);
Writer osw = getA2NOutput(outputFileName);) {
String line;
while ((line = reader.readLine()) != null) {
osw.write(line.toCharArray());
osw.write(lineBreak);
if (outputFileName == null) { // flush stdout
osw.flush();
}
}
}
reader.close(); // Close the stream.
osw.close();
} else {
//N2A
String inLine;
BufferedReader in = getN2AInput(inputFileName);
BufferedWriter out = getN2AOutput(outputFileName);
while ((inLine = in.readLine()) != null) {
out.write(inLine.toCharArray());
out.write(lineBreak);
if (outputFileName == null) { // flush stdout
out.flush();
// N2A
try (BufferedReader in = getN2AInput(inputFileName);
BufferedWriter out = getN2AOutput(outputFileName);) {
String inLine;
while ((inLine = in.readLine()) != null) {
out.write(inLine.toCharArray());
out.write(lineBreak);
if (outputFileName == null) { // flush stdout
out.flush();
}
}
}
out.close();
}
// Since we are done rename temporary file to desired output file
if (createOutputFile) {
if (outputFile.exists()) {
......@@ -182,8 +180,7 @@ public class Main {
}
tempFile.renameTo(outputFile);
}
} catch(Exception e){
} catch (Exception e) {
error(e.toString());
return false;
}
......
......@@ -155,6 +155,7 @@ static char* next_arg(char* cmdline, char* arg, jboolean* wildcard) {
}
}
dest += copyCh(ch, dest);
slashes = 0;
break;
default:
......
/*
* Copyright (c) 2003, 2014 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......
/*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -1125,7 +1125,7 @@ WinAccessBridge::getAccessibleContextWithFocus(HWND window, long *vmID, JOBJECT6
PrintDebugString("WinAccessBridge::getAccessibleContextWithFocus(%p, %X, )", window, vmID);
// find vmID, etc. from HWND; ask that VM for the AC w/Focus
HWND pkgVMID = (HWND)ABLongToHandle( pkg->rVMID ) ;
HWND pkgVMID;
if (getAccessibleContextFromHWND(window, (long *)&(pkgVMID), &(pkg->rAccessibleContext)) == TRUE) {
HWND destABWindow = javaVMs->findAccessBridgeWindow((long)pkgVMID); // ineffecient [[[FIXME]]]
if (sendMemoryPackage(buffer, sizeof(buffer), destABWindow) == TRUE) {
......
......@@ -102,7 +102,7 @@ echo "resume 1";
sleep 5 # give time for Client to throw exception
# JVM_PROC should have exited but just in case, include it.
kill -9 $ORB_PROC $JVM_PROC
kill -9 $ORB_PROC $JVM_PROC $SERVER_PROC
grep "ORBUtilSystemException.writeErrorSend" client.$$
result=$?
......
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -150,11 +150,6 @@ public abstract class TestCipher {
}
// Encryption
int PAD_LEN = 0;
if (pad.equalsIgnoreCase("PKCS5Padding")) {
// Need to consider pad bytes
PAD_LEN = 8;
}
byte[] plainText = INPUT_TEXT.clone();
......@@ -162,12 +157,13 @@ public abstract class TestCipher {
byte[] cipherText = ci.doFinal(INPUT_TEXT, ENC_OFFSET, TEXT_LEN);
// Generate cipher and save to same buffer
int offset = ci.update(
int enc_bytes = ci.update(
INPUT_TEXT, ENC_OFFSET, TEXT_LEN, INPUT_TEXT, STORAGE_OFFSET);
ci.doFinal(INPUT_TEXT, offset + STORAGE_OFFSET);
enc_bytes += ci.doFinal(INPUT_TEXT, enc_bytes + STORAGE_OFFSET);
if (!equalsBlock(
INPUT_TEXT, STORAGE_OFFSET, cipherText, 0, cipherText.length)) {
INPUT_TEXT, STORAGE_OFFSET, enc_bytes,
cipherText, 0, cipherText.length)) {
throw new RuntimeException(
"Different ciphers generated with same buffer");
}
......@@ -183,8 +179,8 @@ public abstract class TestCipher {
byte[] recoveredText = ci.doFinal(cipherText, 0, cipherText.length);
if (!equalsBlock(
plainText, ENC_OFFSET, recoveredText, 0,
recoveredText.length)) {
plainText, ENC_OFFSET, TEXT_LEN,
recoveredText, 0, recoveredText.length)) {
throw new RuntimeException(
"Recovered text not same as plain text");
} else {
......@@ -192,13 +188,13 @@ public abstract class TestCipher {
}
// Recover text from cipher and save to same buffer
ci.update(INPUT_TEXT, STORAGE_OFFSET, TEXT_LEN + PAD_LEN, INPUT_TEXT,
ENC_OFFSET);
ci.doFinal(INPUT_TEXT, ENC_OFFSET);
int dec_bytes = ci.update(
INPUT_TEXT, STORAGE_OFFSET, enc_bytes, INPUT_TEXT, ENC_OFFSET);
dec_bytes += ci.doFinal(INPUT_TEXT, dec_bytes + ENC_OFFSET);
if (!equalsBlock(
plainText, ENC_OFFSET, recoveredText, 0,
recoveredText.length)) {
plainText, ENC_OFFSET, TEXT_LEN,
INPUT_TEXT, ENC_OFFSET, dec_bytes)) {
throw new RuntimeException(
"Recovered text not same as plain text with same buffer");
} else {
......@@ -208,9 +204,12 @@ public abstract class TestCipher {
out.println("Test Passed.");
}
private static boolean equalsBlock(byte[] b1, int off1, byte[] b2, int off2,
int len) {
for (int i = off1, j = off2, k = 0; k < len; i++, j++, k++) {
private static boolean equalsBlock(byte[] b1, int off1, int len1,
byte[] b2, int off2, int len2) {
if (len1 != len2) {
return false;
}
for (int i = off1, j = off2, k = 0; k < len1; i++, j++, k++) {
if (b1[i] != b2[j]) {
return false;
}
......
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8158802
* @summary com.sun.jndi.ldap.SimpleClientId produces wrong hash code
* @modules java.naming/com.sun.jndi.ldap
*/
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import javax.naming.ldap.Control;
public class SimpleClientIdHashCode {
public static void main(String[] args) throws Throwable {
Class<?> simpleClientIdClass
= Class.forName("com.sun.jndi.ldap.SimpleClientId");
Constructor<?> init = simpleClientIdClass.getDeclaredConstructor(
int.class, String.class, int.class, String.class,
Control[].class, OutputStream.class, String.class,
String.class, Object.class);
init.setAccessible(true);
Object p1 = new byte[]{66,77};
Object p2 = new char[]{'w','d'};
Object p3 = "word";
test(init, new byte[]{65}, new byte[]{65});
test(init, new char[]{'p'}, new char[]{'p'});
test(init, "pass", "pass");
test(init, p1, p1);
test(init, p2, p2);
test(init, p3, p3);
test(init, null, null);
}
private static void test(Constructor<?> init, Object pass1, Object pass2)
throws Throwable {
Object o1 = init.newInstance(1, "host", 3, "", null, System.out,
null, null, pass1);
Object o2 = init.newInstance(1, "host", 3, "", null, System.out,
null, null, pass2);
if (!o1.equals(o2))
throw new RuntimeException("Objects not equal");
if (o1.hashCode() != o2.hashCode())
throw new RuntimeException("Inconsistent hash codes");
}
}
/*
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class CpuOldTest {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=old */
hprof = new DemoRun("hprof", "cpu=old");
hprof = new DemoRun("hprof", "cpu=old,file=cpuold.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class CpuSamplesTest {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=samples */
hprof = new DemoRun("hprof", "cpu=samples");
hprof = new DemoRun("hprof", "cpu=samples,file=cpusamples.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -39,7 +39,7 @@ public class CpuTimesDefineClassTest {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=times */
hprof = new DemoRun("hprof", "cpu=times");
hprof = new DemoRun("hprof", "cpu=times,file=cputimedefineclass.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class CpuTimesTest {
DemoRun hprof;
/* Run JVMTI hprof agent with cpu=times */
hprof = new DemoRun("hprof", "cpu=times");
hprof = new DemoRun("hprof", "cpu=times,file=cputimes.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class HeapAllTest {
DemoRun hprof;
/* Run JVMTI hprof agent with heap=all */
hprof = new DemoRun("hprof", "heap=all");
hprof = new DemoRun("hprof", "heap=all,file=heapall.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class HeapBinaryFormatTest {
DemoRun hprof;
/* Run JVMTI hprof agent to get binary format dump */
hprof = new DemoRun("hprof", "heap=dump,format=b,logflags=4");
hprof = new DemoRun("hprof", "heap=dump,format=b,logflags=4,file=heapbinaryformat.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class HeapDumpTest {
DemoRun hprof;
/* Run JVMTI hprof agent with heap=dump */
hprof = new DemoRun("hprof", "heap=dump");
hprof = new DemoRun("hprof", "heap=dump,file=heapdump.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,7 @@ public class HeapSitesTest {
DemoRun hprof;
/* Run JVMTI hprof agent with heap=sites */
hprof = new DemoRun("hprof", "heap=sites");
hprof = new DemoRun("hprof", "heap=sites,file=heapsites.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -42,7 +42,7 @@ public class MonitorTest {
DemoRun hprof;
/* Run JVMTI hprof agent with monitor=y */
hprof = new DemoRun("hprof", "monitor=y");
hprof = new DemoRun("hprof", "monitor=y,file=monitor.txt");
hprof.runit(args[0]);
/* Make sure patterns in output look ok */
......
/*
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -39,10 +39,10 @@ public class OptionsTest {
DemoRun hprof;
List<String> options = new LinkedList<String>();
options.add("cpu=samples,depth=0");
options.add("cpu=times,depth=0");
options.add("cpu=old,depth=0");
options.add("depth=0");
options.add("cpu=samples,depth=0,file=options0.txt");
options.add("cpu=times,depth=0,file=options1.txt");
options.add("cpu=old,depth=0,file=options2.txt");
options.add("depth=0,file=options3.txt");
for(String option: options) {
/* Run JVMTI hprof agent with various options */
......
......@@ -40,10 +40,10 @@ public class StackMapTableTest {
DemoRun hprof;
List<String> options = new LinkedList<String>();
options.add("cpu=samples");
options.add("cpu=times");
options.add("heap=sites");
options.add("");
options.add("cpu=samples,file=stackmaptable0.txt");
options.add("cpu=times,file=stackmaptable1.txt");
options.add("heap=sites,file=stackmaptable2.txt");
options.add("file=stackmaptable3.txt");
for(String option: options) {
/* Run JVMTI hprof agent with various options */
......
<!--
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<html>
<body>
Verify that Chinese comma can be entered in JTextField with Pinyin input method (IM).
This test is for OS X only. For other platforms please simply press "Pass".
1. Go to "System Preferences -> Keyboard -> Input Sources" and add "Pinyin – Traditional" or "Pinyin – Simplified" IM from Chinese language group.
2. Set current IM to "Pinyin".
3. Set focus to the text field of the test and press "comma" character on the keyboard.
4. Set current IM to the IM used before "Pinyin" was set.
5. If "," character is displayed in the text area, press "Pass", if "," character is displayed, press "Fail".
<applet code="bug8148984.class" width=400 height=400></applet>
</body>
</html>
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 8148984
* @summary Chinese Comma cannot be entered using Pinyin Input Method on OS X
* @author Dmitry Markov
* @run applet/manual=yesno bug8148984.html
*/
import javax.swing.*;
public class bug8148984 extends JApplet {
@Override
public void init() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel panel = new JPanel();
panel.add(new JLabel("Text field:"));
panel.add(new JTextField(20));
add(panel);
}
});
}
}
<!--
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<html>
<body>
Verify that Caps Lock key works properly with Pinyin input method, (i.e. if
Caps Lock is pressed, input should be swithced to lowercase latin letters).
This test is for OS X only. For other platforms please simply press "Pass".
1. Go to "System Preferences -> Keyboard -> Input Sources" and add "Pinyin – Traditional" or "Pinyin – Simplified" IM from Chinese language group.
2. Set current IM to "Pinyin".
3. Set focus to the text field of the test and press Caps Lock key on the keyboard.
4. Press "a" character on the keyboard
5. If "a" character is displayed in the text field, press "Pass", if "A" character is displayed, press "Fail".
<applet code="bug8154816.class" width=400 height=400></applet>
</body>
</html>
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 8154816
* @summary Caps Lock doesn't work as expected when using Pinyin Simplified input method
* @author Dmitry Markov
* @run applet/manual=yesno bug8154816.html
*/
import javax.swing.*;
public class bug8154816 extends JApplet {
@Override
public void init() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel panel = new JPanel();
panel.add(new JLabel("Text field:"));
panel.add(new JTextField(20));
add(panel);
}
});
}
}
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.ArrayList;
import javax.management.AttributeNotFoundException;
import javax.management.BadAttributeValueExpException;
import javax.management.BadBinaryOpValueExpException;
import javax.management.BadStringOperationException;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.InvalidApplicationException;
import javax.management.InvalidAttributeValueException;
import javax.management.JMException;
import javax.management.JMRuntimeException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.OperationsException;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;
import javax.management.ServiceNotFoundException;
import javax.management.StringValueExp;
import javax.management.modelmbean.InvalidTargetObjectTypeException;
import javax.management.modelmbean.XMLParseException;
import javax.management.monitor.MonitorSettingException;
import javax.management.openmbean.InvalidKeyException;
import javax.management.openmbean.InvalidOpenTypeException;
import javax.management.openmbean.KeyAlreadyExistsException;
import javax.management.openmbean.OpenDataException;
import javax.management.relation.InvalidRelationIdException;
import javax.management.relation.InvalidRelationServiceException;
import javax.management.relation.InvalidRelationTypeException;
import javax.management.relation.InvalidRoleInfoException;
import javax.management.relation.InvalidRoleValueException;
import javax.management.relation.RelationException;
import javax.management.relation.RelationNotFoundException;
import javax.management.relation.RelationServiceNotRegisteredException;
import javax.management.relation.RelationTypeNotFoundException;
import javax.management.relation.RoleInfoNotFoundException;
import javax.management.relation.RoleNotFoundException;
import javax.management.remote.JMXProviderException;
import javax.management.remote.JMXServerErrorException;
/**
* |----- Original Description Coming From Tonga Original Source Code -------|
* | |
* | That class creates an ArrayList and fill it with an instance of each of |
* | the Exception class of the JMX API. |
* | It's dedicated to use by ExceptionTest. |
* |-------------------------------------------------------------------------|
*/
public class ExceptionFactory {
public static final ArrayList<Exception> exceptions =
new ArrayList<Exception>();
static {
String mes = "SQE";
exceptions.add(new AttributeNotFoundException());
exceptions.add(new BadAttributeValueExpException(mes));
exceptions.add(new BadBinaryOpValueExpException(new StringValueExp(mes)));
exceptions.add(new BadStringOperationException(mes));
exceptions.add(new InstanceAlreadyExistsException());
exceptions.add(new InstanceNotFoundException());
exceptions.add(new IntrospectionException());
exceptions.add(new InvalidApplicationException(mes));
exceptions.add(new InvalidAttributeValueException());
exceptions.add(new JMException());
exceptions.add(new JMRuntimeException());
exceptions.add(new ListenerNotFoundException());
exceptions.add(new MalformedObjectNameException());
exceptions.add(new MBeanException(new Exception(mes), mes));
exceptions.add(new MBeanRegistrationException(new Exception(mes), mes));
exceptions.add(new NotCompliantMBeanException());
exceptions.add(new OperationsException());
exceptions.add(new ReflectionException(new Exception(mes), mes));
exceptions.add(new RuntimeErrorException(new Error(mes), mes));
exceptions.add(new RuntimeMBeanException(new RuntimeException(mes), mes));
exceptions.add(new RuntimeOperationsException(new RuntimeException(mes), mes));
exceptions.add(new ServiceNotFoundException());
exceptions.add(new InvalidTargetObjectTypeException());
exceptions.add(new XMLParseException());
exceptions.add(new MonitorSettingException());
exceptions.add(new InvalidKeyException());
exceptions.add(new InvalidOpenTypeException());
exceptions.add(new KeyAlreadyExistsException());
exceptions.add(new OpenDataException());
exceptions.add(new InvalidRelationIdException());
exceptions.add(new InvalidRelationServiceException());
exceptions.add(new InvalidRelationTypeException());
exceptions.add(new InvalidRoleInfoException());
exceptions.add(new InvalidRoleValueException());
exceptions.add(new RelationException());
exceptions.add(new RelationNotFoundException());
exceptions.add(new RelationServiceNotRegisteredException());
exceptions.add(new RelationTypeNotFoundException());
exceptions.add(new RoleInfoNotFoundException());
exceptions.add(new RoleNotFoundException());
exceptions.add(new JMXProviderException());
exceptions.add(new JMXServerErrorException(mes, new Error(mes)));
ExceptionTest.Utils.debug(ExceptionTest.Utils.DEBUG_STANDARD,
"DataFactory::updateMap: Initialized" +
" an ArrayList with the " +
exceptions.size() + " exceptions of the JMX API");
}
}
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058865
* @summary Checks that exceptions are correctly wired (compared to reference).
* @author Olivier Lagneau
* @modules java.management
* @run main/othervm/timeout=300 -DDEBUG_STANDARD ExceptionTest
*/
import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
import java.lang.reflect.Method;
import java.lang.management.ManagementFactory;
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
public class ExceptionTest {
/*
* First Debug properties and arguments are collect in expected
* map (argName, value) format, then calls original test's run method.
*/
public static void main(String args[]) throws Exception {
System.out.println("=================================================");
// Parses parameters
Utils.parseDebugProperties();
Map<String, Object> map = Utils.parseParameters(args) ;
// Run test
ExceptionTest test = new ExceptionTest();
test.run(map);
}
public void run(Map<String, Object> args) {
System.out.println("ExceptionTest::run: Start");
int errorCount = 0;
JMXConnectorServer cs = null;
JMXConnector cc = null;
try {
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
ObjectName objName =
new ObjectName(ExceptionThrower.EXCEPTION_THROWER_NAME);
System.out.println("ExceptionTest::run: Create and register MBean " + objName);
mbsc.createMBean("ExceptionThrower", objName);
System.out.println("---- OK\n");
// ----
System.out.println("ExceptionTest::run: Ask for exception(s)");
Object[] throwExceptionParam = new Object[1];
String[] throwExceptionSig = new String[]{"int"};
for (int i = 0; i < ExceptionFactory.exceptions.size(); i++) {
throwExceptionParam[0] = new Integer(i);
Exception ex =
(Exception)mbsc.invoke(objName,
"throwException", throwExceptionParam, throwExceptionSig);
if ( ! matches(ex, ExceptionFactory.exceptions.get(i)) ) {
errorCount++;
System.out.println("ExceptionTest::run: (ERROR) Received \n["
+ ex + "]\nin place of\n["
+ ExceptionFactory.exceptions.get(i) + "]");
} else {
System.out.println("OK [" + ex + "]");
}
}
System.out.println("---- DONE\n");
} catch (Exception e) {
Utils.printThrowable(e, true);
throw new RuntimeException();
} finally {
try {
// Close JMX Connector Client
cc.close();
// Stop connertor server
cs.stop();
} catch (Exception e) {
Utils.printThrowable(e, true);
throw new RuntimeException(
"Unable to either close connector client or stop connector server");
}
}
if (errorCount == 0) {
System.out.println("ExceptionTest::run: Done without any error");
} else {
System.out.println("ExceptionTest::run: Done with " + errorCount
+ " error(s)");
throw new RuntimeException("errorCount = " + errorCount);
}
System.out.println("ExceptionTest::run: Done");
}
// Check both Exception are identical.
// That means:
// - none is null.
// - they are of the same Class.
// - if their respective messages aren't null they're equal.
// - if the message of one is null the message of the other is null too.
private boolean matches(Exception ex, Exception refex) {
if ( ex == null || refex == null ) {
System.out.println("(ERROR) Called with one or more null parameter; check "
+ ex + " against " + refex);
return false;
}
String exClass = ex.getClass().getName();
String refexClass = refex.getClass().getName();
if ( ! exClass.equals(refexClass) ) {
System.out.println("(ERROR) Class names don't match; check ["
+ exClass + "] against [" + refexClass + "]");
return false;
}
String exMes = ex.getMessage();
String refexMes = refex.getMessage();
if ( exMes != null && refexMes != null ) {
if ( ! exMes.equals(refexMes) ) {
System.out.println("(ERROR) Non null messages don't match; check ["
+ exMes + "] against [" + refexMes + "]");
return false;
}
} else if ( (exMes == null && refexMes != null)
|| (exMes != null && refexMes == null) ) {
System.out.println("(ERROR) Messages don't match; check [" + exMes
+ "] against [" + refexMes + "]");
}
return true;
}
// Utility inner class coming from JMX Tonga test suite.
// Also used by ExceptionFactory.
static class Utils {
// DEBUG is printed depending on the DEBUG and DEBUG_LEVEL JAVA property
static final String DEBUG_HEADER = "[debug] ";
// DEBUG levels
static int selectedDebugLevel = 0;
static final int DEBUG_STANDARD = 1;
static final int DEBUG_VERBOSE = 2; // Mainly used for stress tests
static final int DEBUG_ALL = DEBUG_STANDARD | DEBUG_VERBOSE;
static void parseDebugProperties() {
int level = 0;
Properties p = System.getProperties();
// get selected levels
if (p.getProperty("DEBUG_STANDARD") != null) {
level |= DEBUG_STANDARD;
}
if (p.getProperty("DEBUG_VERBOSE") != null) {
level |= DEBUG_VERBOSE;
}
if (p.getProperty("DEBUG_ALL") != null) {
level |= DEBUG_ALL;
}
selectedDebugLevel = level;
}
/**
* Reproduces the original parsing and collection of test parameters
* from the DTonga JMX test suite.
*
* Collects passed args and returns them in a map(argname, value) structure,
* which will be then propagated as necessary to various called methods.
*/
static Map<String, Object> parseParameters(String args[])
throws Exception {
debug(DEBUG_STANDARD, "TestRoot::parseParameters: Start");
HashMap<String, Object> map = new HashMap<>();
for ( int i = 0; i < args.length; i++ ) {
if ( args[i].trim().startsWith("-") ) {
if ((i+1) < args.length && !args[i+1].startsWith("-") ) {
debug(DEBUG_STANDARD,
"TestRoot::parseParameters: added in map = " +
args[i] +
" with value " +
args[i+1]) ;
map.put(args[i].trim(), args[i+1].trim()) ;
} else if ((i+1) < args.length && args[i+1].startsWith("-") ||
(i+1) == args.length ) {
debug(DEBUG_STANDARD,
"TestRoot::parseParameters: added in map = " +
args[i] +
" with null value") ;
map.put(args[i].trim(), null) ;
} else {
System.out.println(
"TestRoot::parseParameters: (WARNING) not added in map = " +
args[i]) ;
}
}
}
debug(DEBUG_STANDARD, "TestRoot::parseParameters: Done") ;
return map ;
}
/**
* This method is to be used in all tests to print anything
* that is temporary.
* Printing is done only when debug is activated by the property DEBUG.
* Printing depends also on the DEBUG_LEVEL property.
* Here it encapsulates a System.out.println.
*/
static void debug(int level, String line) {
if ((selectedDebugLevel & level) != 0) {
System.out.println(DEBUG_HEADER + line);
}
}
/**
* Do print stack trace when withStack is true.
* Does try to call getTargetException() and getTargetError() then
* print embedded stacks in the case of an Exception wrapping
* another Exception or an Error. Recurse until no more wrapping
* is found.
*/
static void printThrowable(Throwable theThro, boolean withStack) {
try {
if (withStack) {
theThro.printStackTrace(System.out);
}
if (theThro instanceof Exception) {
Exception t = (Exception) theThro;
Method target = null;
String blank = " ";
try {
target = t.getClass().getMethod("getTargetException",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetException method could be there or not
}
System.out.println(blank + t.getClass() + "==>" + t.getMessage());
while (target != null) {
try {
t = (Exception) target.invoke(t,
(java.lang.Object[]) null);
} catch (Exception ee) {
t = null;
}
try {
if (t != null) {
blank = blank + " ";
System.out.println(blank + t.getClass() + "==>" +
t.getMessage());
try {
target =
t.getClass().getMethod("getTargetException",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetException method could be there or not }
}
} else {
target = null;
}
} catch (Exception ee) {
target = null;
}
}
// We may have exceptions wrapping an Error then it is
// getTargetError that is likely to be called
try {
target = ((Exception) theThro).getClass().getMethod("getTargetError",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetError method could be there or not
}
Throwable err = theThro;
while (target != null) {
try {
err = (Error) target.invoke(err,
(java.lang.Object[]) null);
} catch (Exception ee) {
err = null;
}
try {
if (err != null) {
blank = blank + " ";
System.out.println(blank + err.getClass() + "==>" +
err.getMessage());
if (withStack) {
err.printStackTrace(System.out);
}
try {
target = err.getClass().getMethod("getTargetError",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetError method could be there or not
}
} else {
target = null;
}
} catch (Exception ee) {
target = null;
}
}
} else {
System.out.println("Throwable is : " + theThro);
}
} catch (Throwable x) {
System.out.println("Exception : raised in printException : " + x);
}
}
}
}
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This class defines a simple standard MBean.
*/
public class ExceptionThrower implements ExceptionThrowerMBean {
public static final String EXCEPTION_THROWER_NAME
= "sqe:type=ExceptionThrower";
public Exception throwException(int exceptionIndex) {
return ExceptionFactory.exceptions.get(exceptionIndex);
}
}
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This interface defines a simple standard MBean.
*/
public interface ExceptionThrowerMBean {
public Exception throwException(int exceptionIndex);
}
......@@ -27,6 +27,7 @@
* @summary Test that no locks are held when a monitor attribute is sampled
* or notif delivered.
* @author Eamonn McManus
* @library /lib/testlibrary
* @run clean GaugeMonitorDeadlockTest
* @run build GaugeMonitorDeadlockTest
* @run main GaugeMonitorDeadlockTest 1
......@@ -47,6 +48,8 @@ import javax.management.ObjectName;
import javax.management.monitor.GaugeMonitor;
import javax.management.monitor.GaugeMonitorMBean;
import jdk.testlibrary.Utils;
public class GaugeMonitorDeadlockTest {
private static enum When {IN_GET_ATTRIBUTE, IN_NOTIFY};
private static long checkingTime;
......@@ -54,8 +57,7 @@ public class GaugeMonitorDeadlockTest {
public static void main(String[] args) throws Exception {
if (args.length != 1)
throw new Exception("Arg should be test number");
double factor = Double.parseDouble(System.getProperty("test.timeout.factor", "1.0"));
checkingTime = (long)factor*1000;
checkingTime = Utils.adjustTimeout(1000); // default 1s timeout
System.out.println("=== checkingTime = " + checkingTime + "ms");
int testNo = Integer.parseInt(args[0]) - 1;
......@@ -101,11 +103,12 @@ public class GaugeMonitorDeadlockTest {
monitorProxy.setGranularityPeriod(10L); // 10 ms
monitorProxy.setNotifyHigh(true);
monitorProxy.setNotifyLow(true);
monitorProxy.start();
System.out.println("=== Waiting observedProxy.getGetCount() to be "
+ "changed, presumable deadlock if timeout?");
final int initGetCount = observedProxy.getGetCount();
monitorProxy.start();
long checkedTime = System.currentTimeMillis();
long nowTime;
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
......
......@@ -37,7 +37,6 @@
import java.lang.management.ManagementFactory;
import java.util.concurrent.atomic.AtomicInteger;
import javax.management.Attribute;
import javax.management.JMX;
import javax.management.MBeanServer;
import javax.management.Notification;
......@@ -95,9 +94,10 @@ public class StringMonitorDeadlockTest {
monitorProxy.setStringToCompare("old");
monitorProxy.setGranularityPeriod(10L); // 10 ms
monitorProxy.setNotifyDiffer(true);
monitorProxy.start();
final int initGetCount = observedProxy.getGetCount();
monitorProxy.start();
int getCount = initGetCount;
for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds
getCount = observedProxy.getGetCount();
......
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.management.Descriptor;
import javax.management.ImmutableDescriptor;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationEmitter;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
/**
* Class Basic
* Basic Description
*/
public class Basic implements BasicMXBean, NotificationEmitter,
MBeanRegistration {
public static final String EXCEPTION_MESSAGE = "from Basic";
public static final String NOTIFICATION_MESSAGE = "from Basic";
/** Attribute : IntAtt */
private int intAtt = 0;
/** Attribute : IntegerAtt */
private Integer integerAtt = 0;
/** Attribute : BoolAtt */
private boolean boolAtt = false;
/** Attribute : BooleanAtt */
private Boolean booleanAtt = false;
/** Attribute : StringAtt */
private String stringAtt = null;
/** Attribute : DateAtt */
private Date dateAtt = null;
/** Attribute : ObjectNameAtt */
private ObjectName objectNameAtt = null;
/** Attribute : NotifDescriptorAsMapAtt */
private Map<String, String> notifDescriptorAsMapAtt = null;
/** Attribute : NotifDescriptorAtt */
private Descriptor notifDescriptorAtt = null;
/** Attribute : SqeParameter */
private SqeParameter sqeParameterAtt = null;
/* Creates a new instance of Basic */
@SqeDescriptorKey("CONSTRUCTOR Basic")
public Basic() {
}
/* Creates a new instance of Basic */
@SqeDescriptorKey("CONSTRUCTOR Basic")
public Basic(
@SqeDescriptorKey("CONSTRUCTOR PARAMETER SqeParameter") SqeParameter param) {
}
/**
* Get int attribute
*/
public int getIntAtt() {
return intAtt;
}
/**
* Set int attribute
*/
public void setIntAtt(int value) {
intAtt = value;
}
/**
* Get Integer attribute
*/
public Integer getIntegerAtt() {
return integerAtt;
}
/**
* Set Integer attribute
*/
public void setIntegerAtt(Integer value) {
integerAtt = value;
}
/**
* Get boolean attribute
*/
public boolean getBoolAtt() {
return boolAtt;
}
/**
* Set boolean attribute
*/
public void setBoolAtt(boolean value) {
boolAtt = value;
}
/**
* Get Boolean attribute
*/
public Boolean getBooleanAtt() {
return booleanAtt;
}
/**
* Set Boolean attribute
*/
public void setBooleanAtt(Boolean value) {
booleanAtt = value;
}
/**
* Get String attribute
*/
public String getStringAtt() {
return stringAtt;
}
/**
* Set String attribute
*/
public void setStringAtt(String value) {
stringAtt = value;
}
/**
* Get Date attribute
*/
public Date getDateAtt() {
return dateAtt;
}
/**
* Set Date attribute
*/
public void setDateAtt(Date value) {
dateAtt = value;
}
/**
* Get ObjectName attribute
*/
public ObjectName getObjectNameAtt() {
return objectNameAtt;
}
/**
* Set ObjectName attribute
*/
public void setObjectNameAtt(ObjectName value) {
objectNameAtt = value;
}
/**
* Get SqeParameter attribute
*/
public SqeParameter getSqeParameterAtt() throws Exception {
if (sqeParameterAtt == null) {
sqeParameterAtt = new SqeParameter();
sqeParameterAtt.setGlop("INITIALIZED");
}
return sqeParameterAtt;
}
/**
* Set SqeParameter attribute
*/
public void setSqeParameterAtt(SqeParameter value) {
sqeParameterAtt = value;
}
/**
* Get the Descriptor used to build the NotificationInfo
* of emitted notifications.
*/
public Map<String, String> getNotifDescriptorAsMapAtt() {
if (notifDescriptorAsMapAtt == null) {
initNotifDescriptorAtt();
}
return notifDescriptorAsMapAtt;
}
/**
* Set the Descriptor used to build the NotificationInfo
* of emitted notifications.
* <br>A Map<String, Object> would better fit Descriptor needs but then
* it is not convertible according the MXBean specification so the MBean
* registration fails.
* As we plan to test our custom Descriptor finds its way into
* the metadata of emitted notifications, String is good enough.
*/
public void setNotifDescriptorAsMapAtt(Map<String, String> value) {
notifDescriptorAsMapAtt = new HashMap<String, String>(value);
notifDescriptorAtt = new ImmutableDescriptor(value);
}
/**
* Do nothing
*/
public void doNothing() {
// I said NOTHING !
}
/**
* Do take SqeParameter as a parameter
*/
public void doWeird(SqeParameter param) {
}
/**
* Throw an Exception
*/
public void throwException() throws Exception {
throw new Exception(EXCEPTION_MESSAGE);
}
/**
* Throw an Error
*/
public void throwError() {
throw new InternalError(EXCEPTION_MESSAGE);
}
/**
* Reset all attributes
*/
public void reset() {
intAtt = 0;
integerAtt = 0;
boolAtt = false;
booleanAtt = Boolean.FALSE;
stringAtt = null;
dateAtt = null;
objectNameAtt = null;
}
/**
* Returns the weather for the coming days
* @param verbose <code>boolean</code> verbosity
* @throws java.lang.Exception <code>storm</code>
* @return <code>ObjectName</code>
*/
public Weather getWeather(boolean verbose)
throws java.lang.Exception {
return Weather.SUNNY;
}
// Starting here are the 4 methods of MBeanRegistration interface.
// We use that to grab the ObjectName the MBean is registered with.
//
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
// Grab a reference on the MBeanServer we're registered in.
mbs = server;
// Compute the name we're registered with.
if (name != null) {
mbeanName = name;
return name;
} else {
mbeanName =
new ObjectName("sqe:type=" + Basic.class.getName());
return mbeanName;
}
}
public void postRegister(Boolean registrationDone) {
// Do nothing
}
public void preDeregister() throws Exception {
// Do nothing
}
public void postDeregister() {
// Do nothing
}
/**
* Send one Notification of the provided notifType type.
*/
public void sendNotification(String notifType) {
Notification notification = null;
if (notifType.equals(NOTIF_TYPE_0)) {
notification = new Notification(NOTIF_TYPE_0,
mbeanName,
seqNumber,
NOTIFICATION_MESSAGE);
} else if (notifType.equals(NOTIF_TYPE_1)) {
notification = new SqeNotification(NOTIF_TYPE_1,
mbeanName,
seqNumber,
NOTIFICATION_MESSAGE);
}
seqNumber++;
broadcaster.sendNotification(notification);
}
/**
* That method starts a set of threads, each thread sends a given number of
* notifications.
* The number of threads can be set via the attribute numOfNotificationSenders.
* The number of notification sent by each thread can be set via
* the attribute numOfNotificationSenderLoops.
* Depending on the parameter customNotification we send either custom
* notification(s) or MBeanServer registration and unregistration notification(s).
* When customNotification=true the total number of notification(s) sent is
* (numOfNotificationSenders * numOfNotificationSenderLoops). They are
* sequentially of type NOTIF_TYPE_0 then NOTIF_TYPE_1 and so on.
*
* When customNotification=false the total number of notification(s) sent is
* (numOfNotificationSenders * numOfNotificationSenderLoops) registration
* notification(s)
* +
* (numOfNotificationSenders * numOfNotificationSenderLoops) unregistration
* notification(s)
*
* @throws java.lang.Exception
*/
public void sendNotificationWave(boolean customNotification) throws
Exception {
// Build the set of notification sender.
Collection<Callable<Integer>> tasks =
new HashSet<Callable<Integer>>(numOfNotificationSenders);
for (int i = 1; i <= numOfNotificationSenders; i++) {
tasks.add(new NotifSender(numOfNotificationSenderLoops,
customNotification, i));
}
// Start all notification sender in parallel.
ExecutorService execServ = null;
try {
execServ = Executors.newFixedThreadPool(numOfNotificationSenders);
List<Future<Integer>> taskHandlers = execServ.invokeAll(tasks);
checkNotifSenderThreadStatus(taskHandlers);
} finally {
if (!execServ.isShutdown()) {
execServ.shutdown();
}
}
}
public void setNumOfNotificationSenders(int value) {
numOfNotificationSenders = value;
}
public void setNumOfNotificationSenderLoops(int value) {
numOfNotificationSenderLoops = value;
}
/**
* MBean Notification support
* You shouldn't update these methods
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws IllegalArgumentException {
broadcaster.addNotificationListener(listener, filter, handback);
}
public MBeanNotificationInfo[] getNotificationInfo() {
if (notifDescriptorAtt == null) {
initNotifDescriptorAtt();
}
return new MBeanNotificationInfo[]{
new MBeanNotificationInfo(new String[]{
NOTIF_TYPE_0
},
javax.management.Notification.class.getName(),
"Standard JMX Notification",
notifDescriptorAtt),
new MBeanNotificationInfo(new String[]{
NOTIF_TYPE_1
},
SqeNotification.class.getName(),
"SQE Notification",
notifDescriptorAtt)
};
}
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
broadcaster.removeNotificationListener(listener);
}
public void removeNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws ListenerNotFoundException {
broadcaster.removeNotificationListener(listener, filter, handback);
}
// </editor-fold>
private synchronized long getNextSeqNumber() {
return seqNumber++;
}
private void initNotifDescriptorAtt() {
String key = "CRABE";
String value = "TAMBOUR";
notifDescriptorAtt =
new ImmutableDescriptor(new String[]{key + "=" + value});
notifDescriptorAsMapAtt =
new HashMap<String, String>();
notifDescriptorAsMapAtt.put(key, value);
}
private void checkNotifSenderThreadStatus(
List<Future<Integer>> taskHandlers)
throws Exception {
String msgTag = "Basic::checkNotifSenderThreadStatus: ";
// Grab back status of each notification sender.
for (Future<Integer> f : taskHandlers) {
if (f.isCancelled()) {
String message = msgTag +
"---- ERROR : One thread has been cancelled";
System.out.println(message);
throw new RuntimeException(message);
} else {
Integer effectiveNumOfLoops = f.get();
if (effectiveNumOfLoops != numOfNotificationSenderLoops) {
String message = msgTag + "---- ERROR : One thread did " +
effectiveNumOfLoops + " loops in place of " +
numOfNotificationSenderLoops;
System.out.println(message);
throw new RuntimeException(message);
}
}
}
}
//
private int numOfNotificationSenderLoops = 2;
private int numOfNotificationSenders = 13;
private class NotifSender implements Callable<Integer> {
private int cycles;
private boolean customNotification;
private int senderID;
public NotifSender(int cycles, boolean customNotification, int id) {
this.cycles = cycles;
this.customNotification = customNotification;
this.senderID = id;
}
public Integer call() throws Exception {
int callsDone = 0;
try {
for (int i = 1; i <= cycles; i++) {
if (customNotification) {
if (i % 2 == 0) {
sendNotification(NOTIF_TYPE_0);
} else {
sendNotification(NOTIF_TYPE_1);
}
} else {
ObjectName mbeanName = new ObjectName("SQE:type=" +
mbeanClassName + ",senderID=" + senderID);
mbs.createMBean(mbeanClassName, mbeanName);
mbs.unregisterMBean(mbeanName);
}
callsDone++;
}
} catch (Exception e) {
System.out.println("NotifSender::call: (ERROR) Thread [" + senderID +
"] failed after " + callsDone + " cycles");
throw e;
}
return Integer.valueOf(callsDone);
}
}
//
private long seqNumber;
private final NotificationBroadcasterSupport broadcaster =
new NotificationBroadcasterSupport();
private ObjectName mbeanName;
private MBeanServer mbs;
private String mbeanClassName = "Simple";
/**
* Notification types definitions. To use when creating JMX Notifications.
*/
public static final String NOTIF_TYPE_0 =
"sqe.notification.a.type";
public static final String NOTIF_TYPE_1 =
"sqe.notification.b.type";
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.Date;
import java.util.Map;
import javax.management.ObjectName;
/**
* Interface BasicMBean
* Basic Description
*/
@SqeDescriptorKey("INTERFACE BasicMXBean")
public interface BasicMXBean
{
/**
* Get int attribute
*/
@SqeDescriptorKey("ATTRIBUTE intAtt")
public int getIntAtt();
/**
* Set int attribute
*/
@SqeDescriptorKey("ATTRIBUTE intAtt")
public void setIntAtt(int value);
/**
* Get Integer attribute
*/
@SqeDescriptorKey("ATTRIBUTE integerAtt")
public Integer getIntegerAtt();
/**
* Set Integer attribute
*/
@SqeDescriptorKey("ATTRIBUTE integerAtt")
public void setIntegerAtt(Integer value);
/**
* Get boolean attribute
*/
@SqeDescriptorKey("ATTRIBUTE boolAtt")
public boolean getBoolAtt();
/**
* Set boolean attribute
*/
@SqeDescriptorKey("ATTRIBUTE boolAtt")
public void setBoolAtt(boolean value);
/**
* Get Boolean attribute
*/
@SqeDescriptorKey("ATTRIBUTE booleanAtt")
public Boolean getBooleanAtt();
/**
* Set Boolean attribute
*/
@SqeDescriptorKey("ATTRIBUTE booleanAtt")
public void setBooleanAtt(Boolean value);
/**
* Get String attribute
*/
@SqeDescriptorKey("ATTRIBUTE stringAtt")
public String getStringAtt();
/**
* Set String attribute
*/
@SqeDescriptorKey("ATTRIBUTE stringAtt")
public void setStringAtt(String value);
/**
* Get Date attribute
*/
@SqeDescriptorKey("ATTRIBUTE dateAtt")
public Date getDateAtt();
/**
* Set Date attribute
*/
@SqeDescriptorKey("ATTRIBUTE dateAtt")
public void setDateAtt(Date value);
/**
* Get ObjectName attribute
*/
@SqeDescriptorKey("ATTRIBUTE objectNameAtt")
public ObjectName getObjectNameAtt();
/**
* Set ObjectName attribute
*/
@SqeDescriptorKey("ATTRIBUTE objectNameAtt")
public void setObjectNameAtt(ObjectName value);
/**
* Get SqeParameter attribute
*/
@SqeDescriptorKey("ATTRIBUTE sqeParameterAtt")
public SqeParameter getSqeParameterAtt() throws Exception;
/**
* Set SqeParameter attribute
*/
@SqeDescriptorKey("ATTRIBUTE sqeParameterAtt")
public void setSqeParameterAtt(SqeParameter value);
/**
* Set NumOfNotificationSenders attribute
*/
@SqeDescriptorKey("ATTRIBUTE NumOfNotificationSenders")
public void setNumOfNotificationSenders(int value);
/**
* Set NumOfNotificationSenderLoops attribute
*/
@SqeDescriptorKey("ATTRIBUTE NumOfNotificationSenderLoops")
public void setNumOfNotificationSenderLoops(int value);
/**
* do nothing
*
*/
@SqeDescriptorKey("OPERATION doNothing")
public void doNothing();
/**
* Do take SqeParameter as a parameter
*/
@SqeDescriptorKey("OPERATION doWeird")
public void doWeird(@SqeDescriptorKey("METHOD PARAMETER")SqeParameter param);
/**
* throw an Exception
*
*/
@SqeDescriptorKey("OPERATION throwException")
public void throwException() throws Exception;
/**
* throw an Error
*
*/
@SqeDescriptorKey("OPERATION throwError")
public void throwError();
/**
* reset all attributes
*
*/
@SqeDescriptorKey("OPERATION reset")
public void reset();
/**
* returns the weather for the coming days
*
* @param verbose <code>boolean</code> verbosity
* @return <code>ObjectName</code>
*/
@SqeDescriptorKey("OPERATION getWeather")
public Weather getWeather(@SqeDescriptorKey("METHOD PARAMETER")boolean verbose)
throws java.lang.Exception;
public enum Weather {
CLOUDY, SUNNY
}
@SqeDescriptorKey("ATTRIBUTE notifDescriptorAsMapAtt")
public Map<String, String> getNotifDescriptorAsMapAtt();
@SqeDescriptorKey("ATTRIBUTE notifDescriptorAsMapAtt")
public void setNotifDescriptorAsMapAtt(Map<String, String> value);
@SqeDescriptorKey("OPERATION sendNotification")
public void sendNotification(@SqeDescriptorKey("METHOD PARAMETER")String notifType);
@SqeDescriptorKey("OPERATION sendNotificationWave")
public void sendNotificationWave(boolean customNotification) throws Exception;
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058865
* @summary Checks correct exception and error events from NotificationListener
* @author Olivier Lagneau
* @modules java.management
* @library /lib/testlibrary
* @compile Basic.java
* @run main/othervm/timeout=300 -DDEBUG_STANDARD MXBeanExceptionHandlingTest -timeForNotificationInSeconds 3
*/
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.MBeanException;
import javax.management.MBeanServerDelegate;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.RuntimeErrorException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
public class MXBeanExceptionHandlingTest implements NotificationListener {
private static String BASIC_MXBEAN_CLASS_NAME = "Basic";
private long timeForNotificationInSeconds = 3L;
private int numOfNotifications = 2;
private BlockingQueue<Notification> notifList = null;
/*
* First Debug properties and arguments are collect in expected
* map (argName, value) format, then calls original test's run method.
*/
public static void main(String args[]) throws Exception {
System.out.println("=================================================");
// Parses parameters
Utils.parseDebugProperties();
Map<String, Object> map = Utils.parseParameters(args) ;
// Run test
MXBeanExceptionHandlingTest test = new MXBeanExceptionHandlingTest();
test.run(map);
}
protected void parseArgs(Map<String, Object> args) throws Exception {
String arg = null;
// Init timeForNotificationInSeconds
// It is the maximum time in seconds we wait for a notification.
arg = (String)args.get("-timeForNotificationInSeconds") ;
if (arg != null) {
timeForNotificationInSeconds = (new Long(arg)).longValue();
}
}
public void run(Map<String, Object> args) {
System.out.println("MXBeanExceptionHandlingTest::run: Start") ;
int errorCount = 0 ;
try {
parseArgs(args);
notifList = new ArrayBlockingQueue<Notification>(numOfNotifications);
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
System.out.println("Add me as notification listener");
mbsc.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
this, null, null);
System.out.println("---- OK\n") ;
// ----
System.out.println("Create and register the MBean");
ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
System.out.println("---- OK\n") ;
// ----
System.out.println("Call method throwException on our MXBean");
try {
mbsc.invoke(objName, "throwException", null, null);
errorCount++;
System.out.println("(ERROR) Did not get awaited MBeanException") ;
} catch (MBeanException mbe) {
System.out.println("(OK) Got awaited MBeanException") ;
Throwable cause = mbe.getCause();
if ( cause instanceof java.lang.Exception ) {
System.out.println("(OK) Cause is of the right class") ;
String mess = cause.getMessage();
if ( mess.equals(Basic.EXCEPTION_MESSAGE ) ) {
System.out.println("(OK) Cause message is fine") ;
} else {
errorCount++;
System.out.println("(ERROR) Cause has message "
+ cause.getMessage()
+ " as we expect "
+ Basic.EXCEPTION_MESSAGE) ;
}
} else {
errorCount++;
System.out.println("(ERROR) Cause is of class "
+ cause.getClass().getName()
+ " as we expect java.lang.Exception") ;
}
} catch (Exception e) {
errorCount++;
System.out.println("(ERROR) Did not get awaited MBeanException but "
+ e) ;
Utils.printThrowable(e, true);
}
System.out.println("---- DONE\n") ;
// ----
System.out.println("Call method throwError on our MXBean");
try {
mbsc.invoke(objName, "throwError", null, null);
errorCount++;
System.out.println("(ERROR) Did not get awaited RuntimeErrorException") ;
} catch (RuntimeErrorException ree) {
System.out.println("(OK) Got awaited RuntimeErrorException") ;
Throwable cause = ree.getCause();
if ( cause instanceof java.lang.InternalError ) {
System.out.println("(OK) Cause is of the right class") ;
String mess = cause.getMessage();
if ( mess.equals(Basic.EXCEPTION_MESSAGE ) ) {
System.out.println("(OK) Cause message is fine") ;
} else {
errorCount++;
System.out.println("(ERROR) Cause has message "
+ cause.getMessage()
+ " as we expect "
+ Basic.EXCEPTION_MESSAGE) ;
}
} else {
errorCount++;
System.out.println("(ERROR) Cause is of class "
+ cause.getClass().getName()
+ " as we expect java.lang.InternalError") ;
}
} catch (Exception e) {
errorCount++;
System.out.println("(ERROR) Did not get awaited RuntimeErrorException but "
+ e) ;
Utils.printThrowable(e, true);
}
System.out.println("---- DONE\n") ;
// ----
System.out.println("Unregister the MBean");
mbsc.unregisterMBean(objName);
System.out.println("---- OK\n") ;
Thread.sleep(timeForNotificationInSeconds * 1000);
int numOfReceivedNotif = notifList.size();
if ( numOfReceivedNotif == numOfNotifications ) {
System.out.println("(OK) We received "
+ numOfNotifications
+ " Notifications") ;
} else {
errorCount++;
System.out.println("(ERROR) We received "
+ numOfReceivedNotif
+ " Notifications in place of "
+ numOfNotifications) ;
}
} catch(Exception e) {
Utils.printThrowable(e, true) ;
throw new RuntimeException(e);
}
if ( errorCount == 0 ) {
System.out.println("MXBeanExceptionHandlingTest::run: Done without any error") ;
} else {
System.out.println("MXBeanExceptionHandlingTest::run: Done with "
+ errorCount
+ " error(s)") ;
throw new RuntimeException("errorCount = " + errorCount);
}
}
public void handleNotification(Notification notification, Object handback) {
System.out.println("MXBeanExceptionHandlingTest::handleNotification: Received "
+ notification);
notifList.add(notification);
}
}
此差异已折叠。
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058865
* @summary Checks access to test MXBean
* @author Olivier Lagneau
* @modules java.management
* @library /lib/testlibrary
* @compile Basic.java
* @run main/othervm/timeout=300 -DDEBUG_STANDARD MXBeanInteropTest2
*/
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.management.Attribute;
import javax.management.JMX;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanServer;
import java.lang.management.ManagementFactory;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
public class MXBeanInteropTest2 {
private static String BASIC_MXBEAN_CLASS_NAME = "Basic";
/*
* First Debug properties and arguments are collect in expected
* map (argName, value) format, then calls original test's run method.
*/
public static void main(String args[]) throws Exception {
System.out.println("=================================================");
// Parses parameters
Utils.parseDebugProperties();
Map<String, Object> map = Utils.parseParameters(args) ;
// Run test
MXBeanInteropTest2 test = new MXBeanInteropTest2();
test.run(map);
}
public void run(Map<String, Object> args) {
System.out.println("MXBeanInteropTest2::run: Start") ;
int errorCount = 0 ;
try {
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// Prints all MBeans whatever the domain is.
printMBeans(mbsc) ;
// Call test body
errorCount += doBasicMXBeanTest(mbsc) ;
// Terminate the JMX Client
cc.close();
} catch(Exception e) {
Utils.printThrowable(e, true) ;
throw new RuntimeException(e);
}
if ( errorCount == 0 ) {
System.out.println("MXBeanInteropTest2::run: Done without any error") ;
} else {
System.out.println("MXBeanInteropTest2::run: Done with "
+ errorCount
+ " error(s)") ;
throw new RuntimeException("errorCount = " + errorCount);
}
}
/**
* Prints all MBeans whatever the domain is.
*/
private static void printMBeans(MBeanServerConnection mbsc) throws Exception {
Set<ObjectName> set = mbsc.queryNames(null, null);
System.out.println("---- MBeans found :");
for (Iterator<ObjectName> iter = set.iterator(); iter.hasNext(); ) {
System.out.println(iter.next().toString());
}
System.out.println("\n") ;
}
private final int doBasicMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- doBasicMXBeanTest") ;
try {
ObjectName objName =
new ObjectName("sqe:type=BasicMXBean") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
printMBeanInfo(mbInfo);
System.out.println("---- OK\n") ;
System.out.println("getMBeanInfo\t\t"
+ mbInfo);
System.out.println("---- OK\n") ;
System.out.println("Check mxbean field in the MBeanInfo");
String mxbeanField =
(String)mbInfo.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);
if ( mxbeanField == null || ! mxbeanField.equals("true")) {
System.out.println("---- ERROR : Improper mxbean field value "
+ mxbeanField);
errorCount++;
}
System.out.println("---- OK\n") ;
System.out.println("Set attribute ObjectNameAtt");
Attribute att = new Attribute("ObjectNameAtt", objName);
mbsc.setAttribute(objName, att);
ObjectName value =
(ObjectName)mbsc.getAttribute(objName, "ObjectNameAtt");
if ( ! value.equals(objName) ) {
errorCount++;
System.out.println("---- ERROR : setAttribute failed, got "
+ value
+ " while expecting "
+ objName);
}
System.out.println("---- OK\n") ;
System.out.println("Call operation doNothing");
mbsc.invoke(objName, "doNothing", null, null);
System.out.println("---- OK\n") ;
System.out.println("Call operation getWeather");
Object weather = mbsc.invoke(objName,
"getWeather",
new Object[]{Boolean.TRUE},
new String[]{"boolean"});
System.out.println("Weather is " + weather);
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
private void printMBeanInfo(MBeanInfo mbInfo) {
System.out.println("Description " + mbInfo.getDescription());
for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) {
System.out.println("Constructor " + ctor.getName());
}
for (MBeanAttributeInfo att : mbInfo.getAttributes()) {
System.out.println("Attribute " + att.getName()
+ " [" + att.getType() + "]");
}
for (MBeanOperationInfo oper : mbInfo.getOperations()) {
System.out.println("Operation " + oper.getName());
}
for (MBeanNotificationInfo notif : mbInfo.getNotifications()) {
System.out.println("Notification " + notif.getName());
}
}
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058865
* @summary Checks correct collection of MXBean's class after unregistration
* @author Olivier Lagneau
* @modules java.management
* @library /lib/testlibrary
* @run main/othervm/timeout=300 MXBeanLoadingTest1
*/
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Map;
import javax.management.Attribute;
import javax.management.JMX;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MXBean;
import javax.management.ObjectName;
import javax.management.loading.PrivateMLet;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
public class MXBeanLoadingTest1 {
public static void main(String[] args) throws Exception {
MXBeanLoadingTest1 test = new MXBeanLoadingTest1();
test.run((Map<String, Object>)null);
}
public void run(Map<String, Object> args) {
System.out.println("MXBeanLoadingTest1::run: Start") ;
try {
System.out.println("We ensure no reference is retained on MXBean class"
+ " after it is unregistered. We take time to perform"
+ " some little extra check of Descriptors, MBean*Info.");
ClassLoader myClassLoader = MXBeanLoadingTest1.class.getClassLoader();
if (!(myClassLoader instanceof URLClassLoader)) {
String message = "(ERROR) Test's class loader is not " +
"a URLClassLoader";
System.out.println(message);
throw new RuntimeException(message);
}
URLClassLoader myURLClassLoader = (URLClassLoader) myClassLoader;
URL[] urls = myURLClassLoader.getURLs();
PrivateMLet mlet = new PrivateMLet(urls, null, false);
Class<?> shadowClass = mlet.loadClass(TestMXBean.class.getName());
if (shadowClass == TestMXBean.class) {
String message = "(ERROR) MLet got original TestMXBean, not shadow";
System.out.println(message);
throw new RuntimeException(message);
}
shadowClass = null;
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
ObjectName mletName = new ObjectName("x:type=mlet");
mbs.registerMBean(mlet, mletName);
ObjectName testName = new ObjectName("x:type=test");
mbs.createMBean(Test.class.getName(), testName, mletName);
// That test fails because the MXBean instance is accessed via
// a delegate OpenMBean which has
ClassLoader testLoader = mbs.getClassLoaderFor(testName);
if (testLoader != mlet) {
System.out.println("MLet " + mlet);
String message = "(ERROR) MXBean's class loader is not MLet: "
+ testLoader;
System.out.println(message);
throw new RuntimeException(message);
}
testLoader = null;
// Cycle get/set/get of the attribute of type Luis.
// We check the set is effective.
CompositeData cd_B = (CompositeData)mbs.getAttribute(testName, "B");
CompositeType compType_B = cd_B.getCompositeType();
CompositeDataSupport cds_B =
new CompositeDataSupport(compType_B,
new String[]{"something"},
new Object[]{Integer.valueOf(13)});
Attribute myAtt = new Attribute("B", cds_B);
mbs.setAttribute(testName, myAtt);
CompositeData cd_B2 = (CompositeData)mbs.getAttribute(testName, "B");
if ( ((Integer)cd_B2.get("something")).intValue() != 13 ) {
String message = "(ERROR) The setAttribute of att B did not work;"
+ " expect Luis.something = 13 but got "
+ cd_B2.get("something");
System.out.println(message);
throw new RuntimeException(message);
}
MBeanInfo info = mbs.getMBeanInfo(testName);
String mxbeanField =
(String)info.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);
if ( mxbeanField == null || ! mxbeanField.equals("true")) {
String message = "(ERROR) Improper mxbean field value "
+ mxbeanField;
System.out.println(message);
throw new RuntimeException(message);
}
// Check the 2 attributes.
MBeanAttributeInfo[] attrs = info.getAttributes();
if ( attrs.length == 2 ) {
for (MBeanAttributeInfo mbai : attrs) {
String originalTypeFieldValue =
(String)mbai.getDescriptor().getFieldValue(JMX.ORIGINAL_TYPE_FIELD);
OpenType<?> openTypeFieldValue =
(OpenType<?>)mbai.getDescriptor().getFieldValue(JMX.OPEN_TYPE_FIELD);
if ( mbai.getName().equals("A") ) {
if ( !mbai.isReadable() || !mbai.isWritable()
|| mbai.isIs()
|| !mbai.getType().equals("int") ) {
String message = "(ERROR) Unexpected MBeanAttributeInfo for A "
+ mbai;
System.out.println(message);
throw new RuntimeException(message);
}
if ( ! originalTypeFieldValue.equals("int") ) {
String message = "(ERROR) Unexpected originalType in Descriptor for A "
+ originalTypeFieldValue;
System.out.println(message);
throw new RuntimeException(message);
}
if ( ! openTypeFieldValue.equals(SimpleType.INTEGER) ) {
String message = "(ERROR) Unexpected openType in Descriptor for A "
+ originalTypeFieldValue;
System.out.println(message);
throw new RuntimeException(message);
}
} else if ( mbai.getName().equals("B") ) {
if ( !mbai.isReadable() || !mbai.isWritable()
|| mbai.isIs()
|| !mbai.getType().equals("javax.management.openmbean.CompositeData") ) {
String message = "(ERROR) Unexpected MBeanAttributeInfo for B "
+ mbai;
System.out.println(message);
throw new RuntimeException(message);
}
if ( ! originalTypeFieldValue.equals(Luis.class.getName()) ) {
String message = "(ERROR) Unexpected originalType in Descriptor for B "
+ originalTypeFieldValue;
System.out.println(message);
throw new RuntimeException(message);
}
if ( ! openTypeFieldValue.equals(compType_B) ) {
String message = "(ERROR) Unexpected openType in Descriptor for B "
+ compType_B;
System.out.println(message);
throw new RuntimeException(message);
}
} else {
String message = "(ERROR) Unknown attribute name";
System.out.println(message);
throw new RuntimeException(message);
}
}
} else {
String message = "(ERROR) Unexpected MBeanAttributeInfo array"
+ Arrays.deepToString(attrs);
System.out.println(message);
throw new RuntimeException(message);
}
// Check the MXBean operation.
MBeanOperationInfo[] ops = info.getOperations();
// The impact is ACTION_INFO as for a standard MBean it is UNKNOWN,
// logged 6320104.
if (ops.length != 1 || !ops[0].getName().equals("bogus")
|| ops[0].getSignature().length > 0
|| !ops[0].getReturnType().equals("void")) {
String message = "(ERROR) Unexpected MBeanOperationInfo array "
+ Arrays.deepToString(ops);
System.out.println(message);
throw new RuntimeException(message);
}
String originalTypeFieldValue =
(String)ops[0].getDescriptor().getFieldValue(JMX.ORIGINAL_TYPE_FIELD);
OpenType<?> openTypeFieldValue =
(OpenType<?>)ops[0].getDescriptor().getFieldValue(JMX.OPEN_TYPE_FIELD);
if ( ! originalTypeFieldValue.equals("void") ) {
String message = "(ERROR) Unexpected originalType in Descriptor for bogus "
+ originalTypeFieldValue;
System.out.println(message);
throw new RuntimeException(message);
}
if ( ! openTypeFieldValue.equals(SimpleType.VOID) ) {
String message = "(ERROR) Unexpected openType in Descriptor for bogus "
+ originalTypeFieldValue;
System.out.println(message);
throw new RuntimeException(message);
}
// Check there is 2 constructors.
if (info.getConstructors().length != 2) {
String message = "(ERROR) Wrong number of constructors " +
"in introspected bean: " +
Arrays.asList(info.getConstructors());
System.out.println(message);
throw new RuntimeException(message);
}
// Check MXBean class name.
if (!info.getClassName().endsWith("Test")) {
String message = "(ERROR) Wrong info class name: " +
info.getClassName();
System.out.println(message);
throw new RuntimeException(message);
}
mbs.unregisterMBean(testName);
mbs.unregisterMBean(mletName);
WeakReference<PrivateMLet> mletRef =
new WeakReference<PrivateMLet>(mlet);
mlet = null;
System.out.println("MXBean registered and unregistered, waiting for " +
"garbage collector to collect class loader");
for (int i = 0; i < 10000 && mletRef.get() != null; i++) {
System.gc();
Thread.sleep(1);
}
if (mletRef.get() == null)
System.out.println("(OK) class loader was GC'd");
else {
String message = "(ERROR) Class loader was not GC'd";
System.out.println(message);
throw new RuntimeException(message);
}
} catch(Exception e) {
Utils.printThrowable(e, true) ;
throw new RuntimeException(e);
}
System.out.println("MXBeanLoadingTest1::run: Done without any error") ;
}
// I agree the use of the MXBean annotation and the MXBean suffix for the
// interface name are redundant but however harmless.
//
@MXBean(true)
public static interface TestMXBean {
public void bogus();
public int getA();
public void setA(int a);
public Luis getB();
public void setB(Luis mi);
}
public static class Test implements TestMXBean {
private Luis luis = new Luis() ;
public Test() {}
public Test(int x) {}
public void bogus() {}
public int getA() {return 0;}
public void setA(int a) {}
public Luis getB() {return this.luis;}
public void setB(Luis luis) {this.luis = luis;}
}
public static class Luis {
private int something = 0;
public Luis() {}
public int getSomething() {return something;}
public void setSomething(int v) {something = v;}
public void doNothing() {}
}
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058865
* @summary Checks MXBean proper registration both as its implementation class and interface
* @author Olivier Lagneau
* @modules java.management
* @library /lib/testlibrary
* @compile Basic.java
* @run main/othervm/timeout=300 -DDEBUG_STANDARD MXBeanNotifTest -numOfNotifications 239 -timeForNotificationInSeconds 4
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.lang.management.ManagementFactory;
import javax.management.Attribute;
import javax.management.Descriptor;
import javax.management.ImmutableDescriptor;
import javax.management.MBeanServer;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
public class MXBeanNotifTest implements NotificationListener {
private static String BASIC_MXBEAN_CLASS_NAME = "Basic";
private static String BASIC_MXBEAN_INTERFACE_NAME = "BasicMXBean";
private long timeForNotificationInSeconds = 3L;
private int numOfNotifications = 1;
private BlockingQueue<Notification> notifList = null;
private int numOfNotifDescriptorElements = 13;
/*
* First Debug properties and arguments are collect in expected
* map (argName, value) format, then calls original test's run method.
*/
public static void main(String args[]) throws Exception {
System.out.println("=================================================");
// Parses parameters
Utils.parseDebugProperties();
Map<String, Object> map = Utils.parseParameters(args) ;
// Run test
MXBeanNotifTest test = new MXBeanNotifTest();
test.run(map);
}
protected void parseArgs(Map<String, Object> args) throws Exception {
String arg = null;
// Init numOfNotifications
// It is the number of notifications we should trigger and check.
arg = (String)args.get("-numOfNotifications") ;
if (arg != null) {
numOfNotifications = (new Integer(arg)).intValue();
}
// Init timeForNotificationInSeconds
// It is the maximum time in seconds we wait for each notification.
arg = (String)args.get("-timeForEachNotificationInSeconds") ;
if (arg != null) {
timeForNotificationInSeconds = (new Long(arg)).longValue();
}
}
public void run(Map<String, Object> args) {
System.out.println("MXBeanNotifTest::run: Start") ;
int errorCount = 0 ;
try {
parseArgs(args);
notifList = new ArrayBlockingQueue<Notification>(numOfNotifications);
// JMX MbeanServer used inside single VM as if remote.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
System.out.println("MXBeanNotifTest::run: Create and register the MBean");
ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
System.out.println("---- OK\n") ;
// ----
System.out.println("MXBeanNotifTest::run: Add me as notification listener");
mbsc.addNotificationListener(objName, this, null, null);
// ----
System.out.println("MXBeanNotifTest::run: Retrieve the Descriptor"
+ " that should be in MBeanNotificationInfo");
TabularData tabData =
(TabularData)mbsc.getAttribute(objName, "NotifDescriptorAsMapAtt");
Map<String, String> descrMap = new HashMap<>();
for (Iterator<?> it = tabData.values().iterator(); it.hasNext(); ) {
CompositeData compData = (CompositeData)it.next();
descrMap.put((String)compData.get("key"),
(String)compData.get("value"));
}
Descriptor refNotifDescriptor = new ImmutableDescriptor(descrMap);
System.out.println("---- OK\n") ;
// ----
// Because the MBean holding the targeted attribute is MXBean, we
// should use for the setAttribute a converted form for the
// attribute value as described by the MXBean mapping rules.
// This explains all that lovely stuff for creating a
// TabularDataSupport.
//
// WARNING : the MBeanInfo of the MXBean used on opposite side
// is computed when the MBean is registered.
// It means the Descriptor considered for the MBeanNotificationInfo
// is not the one we set in the lines below, it is too late.
// However, we check that set is harmless when we check
// the MBeanNotificationInfo.
//
System.out.println("MXBeanNotifTest::run: Set a Map<String, String>"
+ " attribute");
String typeName =
"java.util.Map<java.lang.String,java.lang.String>";
String[] keyValue = new String[] {"key", "value"};
OpenType<?>[] openTypes =
new OpenType<?>[] {SimpleType.STRING, SimpleType.STRING};
CompositeType rowType = new CompositeType(typeName, typeName,
keyValue, keyValue, openTypes);
TabularType tabType = new TabularType(typeName, typeName,
rowType, new String[]{"key"});
TabularDataSupport convertedDescrMap =
new TabularDataSupport(tabType);
for (int i = 0; i < numOfNotifDescriptorElements; i++) {
Object[] descrValue = {"field" + i, "value" + i};
CompositeData data =
new CompositeDataSupport(rowType, keyValue, descrValue);
convertedDescrMap.put(data);
}
Attribute descrAtt =
new Attribute("NotifDescriptorAsMapAtt", convertedDescrMap);
mbsc.setAttribute(objName, descrAtt);
System.out.println("---- OK\n") ;
// ----
System.out.println("MXBeanNotifTest::run: Compare the Descriptor from"
+ " the MBeanNotificationInfo against a reference");
MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
errorCount += checkMBeanInfo(mbInfo, refNotifDescriptor);
System.out.println("---- DONE\n") ;
// ----
System.out.println("Check isInstanceOf(Basic)");
if ( ! mbsc.isInstanceOf(objName, BASIC_MXBEAN_CLASS_NAME) ) {
errorCount++;
System.out.println("---- ERROR isInstanceOf returned false\n") ;
} else {
System.out.println("---- OK\n") ;
}
// ----
System.out.println("Check isInstanceOf(BasicMXBean)");
if ( ! mbsc.isInstanceOf(objName, BASIC_MXBEAN_INTERFACE_NAME) ) {
errorCount++;
System.out.println("---- ERROR isInstanceOf returned false\n") ;
} else {
System.out.println("---- OK\n") ;
}
// ----
System.out.println("MXBeanNotifTest::run: Ask for "
+ numOfNotifications + " notification(s)");
Object[] sendNotifParam = new Object[1];
String[] sendNotifSig = new String[]{"java.lang.String"};
for (int i = 0; i < numOfNotifications; i++) {
// Select which type of notification we ask for
if ( i % 2 == 0 ) {
sendNotifParam[0] = Basic.NOTIF_TYPE_0;
} else {
sendNotifParam[0] = Basic.NOTIF_TYPE_1;
}
// Trigger notification emission
mbsc.invoke(objName,
"sendNotification",
sendNotifParam,
sendNotifSig);
// Wait for it then check it when it comes early enough
Notification notif =
notifList.poll(timeForNotificationInSeconds,
TimeUnit.SECONDS) ;
// The very first notification is likely to come in slower than
// all the others. Because that test isn't targeting the speed
// notifications are delivered with, we prefer to secure it.
if (i == 0 && notif == null) {
System.out.println("MXBeanNotifTest::run: Wait extra "
+ timeForNotificationInSeconds + " second(s) the "
+ " very first notification");
notif = notifList.poll(timeForNotificationInSeconds,
TimeUnit.SECONDS);
}
if ( notif == null ) {
errorCount++;
System.out.println("---- ERROR No notification received"
+ " within allocated " + timeForNotificationInSeconds
+ " second(s) !");
} else {
errorCount +=
checkNotification(notif,
(String)sendNotifParam[0],
Basic.NOTIFICATION_MESSAGE,
objName);
}
}
int toc = 0;
while ( notifList.size() < 2 && toc < 10 ) {
Thread.sleep(499);
toc++;
}
System.out.println("---- DONE\n") ;
} catch(Exception e) {
Utils.printThrowable(e, true) ;
throw new RuntimeException(e);
}
if ( errorCount == 0 ) {
System.out.println("MXBeanNotifTest::run: Done without any error") ;
} else {
System.out.println("MXBeanNotifTest::run: Done with "
+ errorCount
+ " error(s)") ;
throw new RuntimeException("errorCount = " + errorCount);
}
}
private int checkMBeanInfo(MBeanInfo mbi, Descriptor refDescr) {
MBeanNotificationInfo[] notifsInfo = mbi.getNotifications();
int res = 0;
for (MBeanNotificationInfo mbni : notifsInfo) {
if ( mbni.getDescriptor().equals(refDescr) ) {
System.out.println("(OK)");
} else {
System.out.println("(ERROR) Descriptor of the notification is "
+ mbni.getDescriptor()
+ " as we expect "
+ refDescr);
res++;
}
}
return res;
}
private int checkNotification(Notification notif,
String refType,
String refMessage,
ObjectName refSource) {
int res = 0;
Utils.debug(Utils.DEBUG_VERBOSE,
"\t getSource " + notif.getSource());
Utils.debug(Utils.DEBUG_VERBOSE,
"\t getMessage " + notif.getMessage());
Utils.debug(Utils.DEBUG_VERBOSE,
"\t getSequenceNumber " + notif.getSequenceNumber());
Utils.debug(Utils.DEBUG_VERBOSE,
"\t getTimeStamp " + notif.getTimeStamp());
Utils.debug(Utils.DEBUG_VERBOSE,
"\t getType " + notif.getType());
Utils.debug(Utils.DEBUG_VERBOSE,
"\t getUserData " + notif.getUserData());
if ( ! notif.getType().equals(refType) ) {
res++;
System.out.println("(ERROR) Type is not "
+ refType + " in notification\n" + notif);
} else {
if ( notif.getType().equals(Basic.NOTIF_TYPE_0)
&& ! (notif instanceof javax.management.Notification) ) {
res++;
System.out.println("(ERROR) Notification is not instance of "
+ " javax.management.Notification but rather "
+ notif.getClass().getName());
} else if ( notif.getType().equals(Basic.NOTIF_TYPE_1)
&& ! (notif instanceof SqeNotification) ) {
res++;
System.out.println("(ERROR) Notification is not instance of "
+ " javasoft.sqe.jmx.share.SqeNotification but rather "
+ notif.getClass().getName());
}
}
if ( ! notif.getMessage().equals(refMessage) ) {
res++;
System.out.println("(ERROR) Message is not "
+ refMessage + " in notification\n" + notif);
}
if ( ! notif.getSource().equals(refSource) ) {
res++;
System.out.println("(ERROR) Source is not "
+ refSource + " in notification\n" + notif);
}
return res;
}
public void handleNotification(Notification notification, Object handback) {
Utils.debug(Utils.DEBUG_VERBOSE,
"MXBeanNotifTest::handleNotification: Received "
+ notification);
notifList.add(notification);
}
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058865
* @summary Checks that a serialized instance is not transmitted from an MXBean.
* All the communication should be done via Open Types
* @author Olivier Lagneau
* @modules java.management
* @library /lib/testlibrary
* @compile Basic.java
* @run main/othervm/timeout=300 -DDEBUG_STANDARD MXBeanWeirdParamTest
*/
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.Process;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
import jdk.testlibrary.ProcessTools;
import jdk.testlibrary.JDKToolFinder;
public class MXBeanWeirdParamTest {
private static String BASIC_MXBEAN_CLASS_NAME = "Basic";
private static final String CLIENT_CLASS_MAIN =
"MXBeanWeirdParamTest$ClientSide";
private JMXConnectorServer cs;
/*
* First Debug properties and arguments are collect in expected
* map (argName, value) format, then calls original test's run method.
*/
public static void main(String args[]) throws Exception {
System.out.println("=================================================");
// Parses parameters
Utils.parseDebugProperties();
Map<String, Object> map = Utils.parseParameters(args) ;
// Run test
MXBeanWeirdParamTest test = new MXBeanWeirdParamTest();
test.run(map);
}
/*
* Create the MBeansServe side of the test and returns its address
*/
private JMXServiceURL createServerSide() throws Exception {
final int NINETY_SECONDS = 90;
// We will use the platform mbean server
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
Utils.waitReady(cs, NINETY_SECONDS);
JMXServiceURL addr = cs.getAddress();
return addr;
}
/*
* Creating command-line for running subprocess JVM:
*
* JVM command line is like:
* {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
*
* {defaultopts} are the default java options set by the framework.
*
*/
private List<String> buildCommandLine() {
List<String> opts = new ArrayList<>();
opts.add(JDKToolFinder.getJDKTool("java"));
opts.addAll(Arrays.asList(jdk.testlibrary.Utils.getTestJavaOpts()));
// We need to set WEIRD_PARAM propertty on the client-side
opts.add("-DWEIRD_PARAM");
opts.add("-cp");
opts.add(System.getProperty("test.class.path", "test.class.path"));
opts.add(CLIENT_CLASS_MAIN);
return opts;
}
/**
* Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
* subprocess standard I/O to the current (parent) process. This provides a
* trace of what happens in the subprocess while it is runnning (and before
* it terminates).
*
* @param serviceUrlStr string representing the JMX service Url to connect to.
*/
private int runClientSide(String serviceUrlStr) throws Exception {
// Building command-line
List<String> opts = buildCommandLine();
opts.add(serviceUrlStr);
// Launch separate JVM subprocess
int exitCode = 0;
String[] optsArray = opts.toArray(new String[0]);
ProcessBuilder pb = new ProcessBuilder(optsArray);
Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);
// Handling end of subprocess
try {
exitCode = p.waitFor();
if (exitCode != 0) {
System.out.println(
"Subprocess unexpected exit value of [" + exitCode +
"]. Expected 0.\n");
}
} catch (InterruptedException e) {
System.out.println("Parent process interrupted with exception : \n " + e + " :" );
// Parent thread unknown state, killing subprocess.
p.destroyForcibly();
throw new RuntimeException(
"Parent process interrupted with exception : \n " + e + " :" );
} finally {
return exitCode;
}
}
public void run(Map<String, Object> args) throws Exception {
System.out.println("MXBeanWeirdParamTest::run: Start") ;
int errorCount = 0;
try {
// Initialise the server side
JMXServiceURL urlToUse = createServerSide();
// Run client side
errorCount = runClientSide(urlToUse.toString());
if ( errorCount == 0 ) {
System.out.println("MXBeanWeirdParamTest::run: Done without any error") ;
} else {
System.out.println("MXBeanWeirdParamTest::run: Done with "
+ errorCount
+ " error(s)") ;
throw new RuntimeException("errorCount = " + errorCount);
}
cs.stop();
} catch(Exception e) {
throw new RuntimeException(e);
}
}
private static class ClientSide {
public static void main(String args[]) throws Exception {
int errorCount = 0 ;
String msgTag = "ClientSide::main: ";
try {
// Get a connection to remote mbean server
JMXServiceURL addr = new JMXServiceURL(args[0]);
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
System.out.println(msgTag + "Create and register the MBean");
ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
System.out.println(msgTag +"---- OK\n") ;
// ----
System.out.println(msgTag +"Get attribute SqeParameterAtt on our MXBean");
Object result = mbsc.getAttribute(objName, "SqeParameterAtt");
System.out.println(msgTag +"(OK) Got result of class "
+ result.getClass().getName());
System.out.println(msgTag +"Received CompositeData is " + result);
System.out.println(msgTag +"---- OK\n") ;
// ----
// We use the value returned by getAttribute to perform the invoke.
System.out.println(msgTag +"Call operation doWeird on our MXBean [1]");
mbsc.invoke(objName, "doWeird",
new Object[]{result},
new String[]{"javax.management.openmbean.CompositeData"});
System.out.println(msgTag +"---- OK\n") ;
// ----
// We build the CompositeData ourselves that time.
System.out.println(msgTag +"Call operation doWeird on our MXBean [2]");
String typeName = "SqeParameter";
String[] itemNames = new String[] {"glop"};
OpenType<?>[] openTypes = new OpenType<?>[] {SimpleType.STRING};
CompositeType rowType = new CompositeType(typeName, typeName,
itemNames, itemNames, openTypes);
Object[] itemValues = {"HECTOR"};
CompositeData data =
new CompositeDataSupport(rowType, itemNames, itemValues);
TabularType tabType = new TabularType(typeName, typeName,
rowType, new String[]{"glop"});
TabularDataSupport tds = new TabularDataSupport(tabType);
tds.put(data);
System.out.println(msgTag +"Source CompositeData is " + data);
mbsc.invoke(objName, "doWeird",
new Object[]{data},
new String[]{"javax.management.openmbean.CompositeData"});
System.out.println(msgTag +"---- OK\n") ;
// ----
System.out.println(msgTag +"Unregister the MBean");
mbsc.unregisterMBean(objName);
System.out.println(msgTag +"---- OK\n") ;
// Terminate the JMX Client
cc.close();
} catch(Exception e) {
Utils.printThrowable(e, true) ;
errorCount++;
throw new RuntimeException(e);
} finally {
System.exit(errorCount);
}
}
}
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.management.DescriptorKey;
/**
* That annotation is usable everywhere DescriptorKey is (and even more).
* It is for use to test that you can retrieve the SqeDescriptorKey into the
* appropriate Descriptor instances as built by the JMX runtime.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface SqeDescriptorKey {
@DescriptorKey("sqeDescriptorKey")
String value();
// List descriptor fields that may be added or may be updated
// when retrieving an MBeanInfo using a JMXWS connection compared to the
// MBeanInfo returned by a local MBeanServer.
// The annotation format is :
// <descriptorFieldName>=<descriptorFieldValue>
// The values actually handled by the test suite are :
// openType=SimpleType.VOID
@DescriptorKey("descriptorFields")
String[] descriptorFields() default {};
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.management.Notification;
/**
* Could hold someday a specific semantic.
* For now it is used to have a Notification which of another class, no more.
*/
public class SqeNotification extends Notification {
/** Creates a new instance of SqeNotification */
public SqeNotification(String type, Object source, long sequenceNumber) {
super(type, source, sequenceNumber);
}
/** Creates a new instance of SqeNotification */
public SqeNotification(String type, Object source, long sequenceNumber,
long timeStamp) {
super(type, source, sequenceNumber, timeStamp);
}
/** Creates a new instance of SqeNotification */
public SqeNotification(String type, Object source, long sequenceNumber,
long timeStamp, String message) {
super(type, source, sequenceNumber, timeStamp, message);
}
/** Creates a new instance of SqeNotification */
public SqeNotification(String type, Object source, long sequenceNumber,
String message) {
super(type, source, sequenceNumber, message);
}
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.Serializable;
/**
* That class is to use as an MBean operation parameter or returned value.
* The property Glop with its public getter + setter is only there to be
* reconstructible following MXBean specification, so that SqeParameter can be
* used for what it is designed to.
*/
public class SqeParameter implements Serializable {
private static boolean weird;
private String glop;
static {
if ( System.getProperty("WEIRD_PARAM") != null ) {
weird = true;
}
}
/**
* Creates a new instance of SqeParameter.
* <br>When the Java property WEIRD_PARAM is set, that constructor
* throws an exception.
* <br>That can be used to ensure the class is instantiated on server side
* but never on client side.
*/
public SqeParameter() throws Exception {
if ( weird ) {
throw new Exception();
}
}
public String getGlop() {
return glop;
}
public void setGlop(String value) {
glop = value;
}
}
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
import java.lang.reflect.Method;
import javax.management.remote.JMXConnectorServerMBean;
// utility class for MXBean* tests coming from JMX Tonga test suite
class Utils {
// DEBUG is printed depending on the DEBUG and DEBUG_LEVEL JAVA property
private static final String DEBUG_HEADER = "[debug] ";
// DEBUG levels
private static int selectedDebugLevel = 0;
static final int DEBUG_STANDARD = 1;
static final int DEBUG_VERBOSE = 2; // Mainly used for stress tests
static final int DEBUG_ALL = DEBUG_STANDARD | DEBUG_VERBOSE;
static void parseDebugProperties() {
int level = 0;
Properties p = System.getProperties();
// get selected levels
if (p.getProperty("DEBUG_STANDARD") != null) {
level |= DEBUG_STANDARD;
}
if (p.getProperty("DEBUG_VERBOSE") != null) {
level |= DEBUG_VERBOSE;
}
if (p.getProperty("DEBUG_ALL") != null) {
level |= DEBUG_ALL;
}
selectedDebugLevel = level;
}
/**
* Reproduces the original parsing and collection of test parameters
* from the DTonga JMX test suite.
*
* Collects passed args and returns them in a map(argname, value) structure,
* which will be then propagated as necessary to various called methods.
*/
static Map<String, Object> parseParameters(String args[])
throws Exception {
Utils.debug(DEBUG_STANDARD, "TestRoot::parseParameters: Start");
HashMap<String, Object> map = new HashMap<>();
for ( int i = 0; i < args.length; i++ ) {
if ( args[i].trim().startsWith("-") ) {
if ((i+1) < args.length && !args[i+1].startsWith("-") ) {
Utils.debug(DEBUG_STANDARD,
"TestRoot::parseParameters: added in map = " +
args[i] +
" with value " +
args[i+1]) ;
map.put(args[i].trim(), args[i+1].trim()) ;
} else if ((i+1) < args.length && args[i+1].startsWith("-") ||
(i+1) == args.length ) {
Utils.debug(DEBUG_STANDARD,
"TestRoot::parseParameters: added in map = " +
args[i] +
" with null value") ;
map.put(args[i].trim(), null) ;
} else {
System.out.println(
"TestRoot::parseParameters: (WARNING) not added in map = " +
args[i]) ;
}
}
}
Utils.debug(DEBUG_STANDARD, "TestRoot::parseParameters: Done") ;
return map ;
}
/**
* This method is to be used in all tests to print anything
* that is temporary.
* Printing is done only when debug is activated by the property DEBUG.
* Printing depends also on the DEBUG_LEVEL property.
* Here it encapsulates a System.out.println.
*/
public static void debug(int level, String line) {
if ((selectedDebugLevel & level) != 0) {
System.out.println(DEBUG_HEADER + line);
}
}
/**
* Do print stack trace when withStack is true.
* Does try to call getTargetException() and getTargetError() then
* print embedded stacks in the case of an Exception wrapping
* another Exception or an Error. Recurse until no more wrapping
* is found.
*/
public static void printThrowable(Throwable theThro, boolean withStack) {
try {
if (withStack) {
theThro.printStackTrace(System.out);
}
if (theThro instanceof Exception) {
Exception t = (Exception) theThro;
Method target = null;
String blank = " ";
try {
target = t.getClass().getMethod("getTargetException",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetException method could be there or not
}
System.out.println(blank + t.getClass() + "==>" + t.getMessage());
while (target != null) {
try {
t = (Exception) target.invoke(t,
(java.lang.Object[]) null);
} catch (Exception ee) {
t = null;
}
try {
if (t != null) {
blank = blank + " ";
System.out.println(blank + t.getClass() + "==>" +
t.getMessage());
try {
target =
t.getClass().getMethod("getTargetException",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetException method could be there or not }
}
} else {
target = null;
}
} catch (Exception ee) {
target = null;
}
}
// We may have exceptions wrapping an Error then it is
// getTargetError that is likely to be called
try {
target = ((Exception) theThro).getClass().getMethod("getTargetError",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetError method could be there or not
}
Throwable err = theThro;
while (target != null) {
try {
err = (Error) target.invoke(err,
(java.lang.Object[]) null);
} catch (Exception ee) {
err = null;
}
try {
if (err != null) {
blank = blank + " ";
System.out.println(blank + err.getClass() + "==>" +
err.getMessage());
if (withStack) {
err.printStackTrace(System.out);
}
try {
target = err.getClass().getMethod("getTargetError",
(java.lang.Class<?>[]) null);
} catch (Exception ee) {
// OK: getTargetError method could be there or not
}
} else {
target = null;
}
} catch (Exception ee) {
target = null;
}
}
} else {
System.out.println("Throwable is : " + theThro);
}
} catch (Throwable x) {
System.out.println("Exception : raised in printException : " + x);
}
}
/**
* Wait up to maxTimeInSeconds second(s) the given JMX connector server
* comes up (which means isActive returns true).
* If it fails to do so we throw a RunTime exception.
*/
public static void waitReady(JMXConnectorServerMBean server,
int maxTimeInSeconds) throws Exception {
int elapsed = 0;
while (!server.isActive() && elapsed < maxTimeInSeconds) {
Thread.sleep(1000);
elapsed++;
}
if (server.isActive()) {
String message = "Utils::waitReady: JMX connector server came up";
if ( elapsed == 0) {
message += " immediately";
} else {
message += " after " + elapsed + " seconds";
}
message += " [" + server.getAddress() + "]";
Utils.debug(DEBUG_STANDARD, message);
} else {
String message = "Utils::waitReady: (ERROR) JMX connector" +
" server didn't come up after " + elapsed + " seconds [" +
server.getAddress() + "]";
System.out.println(message);
throw new RuntimeException(message);
}
}
}
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public abstract class QueryData {
protected int intValue = 9;
protected long longValue = 9L;
protected Integer integerValue = Integer.valueOf(9);
protected boolean booleanValue = true;
protected double doubleValue = 9D;
protected float floatValue = 9.0F;
protected String stringValue = "9";
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
# Access control file for SQE tests.
# Default username
SQE_username readwrite create Simple
# Functional authorization tests
username1 readwrite create Simple
username2 readonly
username3 readonly
username4 readwrite create Simple
username5 readwrite create Simple
PasswordFileAuthentication {
com.sun.jmx.remote.security.FileLoginModule required
passwordFile="${password.file}";
};
SampleLoginModule {
TestSampleLoginModule required;
};
# Password file for default SQE username.
SQE_username SQE_password
# Functional authorization tests
username1 password1
username2 password2
username3 password3
username4 password4
username5 password5
username6 password6
usernameFileLoginModule passwordFileLoginModule
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册