/* * Copyright (c) 2013, 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 8026027 6543126 8187073 * @modules java.logging * java.management * @summary Test Level.parse to look up custom levels by name and its * localized name, as well as severity. * * @run main/othervm CustomLevel
*/
publicclass CustomLevel extends Level { public CustomLevel(String name, int value, String resourceBundleName) { super(name, value, resourceBundleName);
}
// Now verify that custom level instances are correctly // garbage collected when no longer referenced
ReferenceQueue<Level> queue = new ReferenceQueue<>();
List<CustomLevelReference> refs = new ArrayList<>();
List<CustomLevelReference> customRefs = new ArrayList<>(); int otherLevels = 0; while (!levels.isEmpty()) {
Level l = levels.stream().findAny().get(); boolean isCustomLoader = isCustomLoader(l); if (isCustomLoader) otherLevels++;
CustomLevelReference ref = new CustomLevelReference(l, queue); if (isCustomLoader) {
customRefs.add(ref);
} else {
refs.add(ref);
}
// remove strong references to l
levels.remove(l);
l = null;
// Run gc and wait for garbage collection if (otherLevels == otherLevelCount) { if (customRefs.size() != otherLevelCount) { thrownew RuntimeException("Test bug: customRefs.size() != "
+ otherLevelCount);
}
waitForGC(customRefs, queue);
}
} if (otherLevelCount != otherLevels || otherLevelCount == 0) { thrownew RuntimeException("Test bug: "
+ "no or wrong count of levels loaded from custom loader");
} if (!customRefs.isEmpty()) { thrownew RuntimeException( "Test bug: customRefs.size() should be empty!");
} while (!refs.isEmpty()) { final Reference<?> ref = refs.remove(0); if (ref.get() == null) { thrownew RuntimeException("Unexpected garbage collection for "
+ ref);
}
}
}
privatestaticvoid waitForGC(List<CustomLevelReference> customRefs,
ReferenceQueue<Level> queue) throws InterruptedException
{ while (!customRefs.isEmpty()) {
Reference<? extends Level> ref2; do {
System.gc(); Thread.sleep(100);
} while ((ref2 = queue.poll()) == null);
staticvoid checkCustomLevel(Level level, Level expected) { // Level value must be the same if (!level.equals(expected)) { thrownew RuntimeException(formatLevel(level) + " != "
+ formatLevel(expected));
}
// Level.parse is expected to return the custom Level if (level != expected) { thrownew RuntimeException(formatLevel(level) + " != "
+ formatLevel(expected));
}
final ResourceBundle rb = getResourceBundle(level);
String name = rb.getString(level.getName()); if (!level.getLocalizedName().equals(name)) { // must have the same localized name thrownew RuntimeException(level.getLocalizedName() + " != " + name);
}
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.51Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.