Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/LazyCompositeDataTest.java
38833 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.HashMap;24import java.util.Map;25import javax.management.openmbean.ArrayType;26import javax.management.openmbean.CompositeData;27import javax.management.openmbean.CompositeDataSupport;28import javax.management.openmbean.CompositeType;29import javax.management.openmbean.OpenDataException;30import javax.management.openmbean.OpenType;31import javax.management.openmbean.SimpleType;32import sun.management.LazyCompositeData;3334/**35* @test36* @bug 813987037* @summary sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType38* @modules java.management/sun.management39* @author Jaroslav Bachorik40*/4142public class LazyCompositeDataTest {43private final static CompositeData dataV1, dataV2;4445static {46try {47// ***48// prepare the composite types4950// composite type stored in an array; V151CompositeType subtypeV1 = new CompositeType(52"Subtype1",53"Version 1",54new String[]{"item1"},55new String[]{"Item 1"},56new OpenType<?>[]{57SimpleType.STRING58}59);6061// composite type stored in an array; V262CompositeType subtypeV2 = new CompositeType(63"Subtype2",64"Version 2",65new String[]{"item1", "item2"},66new String[]{"Item 1", "Item 2"},67new OpenType<?>[]{68SimpleType.STRING,69SimpleType.INTEGER70}71);727374// main composite type; V175// one of the items is array of 'subtypeV1' instances76CompositeType typeV1 = new CompositeType(77"MyDataV1",78"Version 1",79new String[]{"item1", "item2"},80new String[]{"Item 1", "Item 2"},81new OpenType<?>[]{82SimpleType.STRING,83ArrayType.getArrayType(subtypeV1)84}85);8687// main composite type; V288// one of the items is array of 'subtypeV2' instances89CompositeType typeV2 = new CompositeType(90"MyDataV2",91"Version 2",92new String[]{"item1", "item2"},93new String[]{"Item 1", "Item 2"},94new OpenType<?>[]{95SimpleType.STRING,96ArrayType.getArrayType(subtypeV2)97}98);99// ***100101// ***102// construct the data103Map<String, Object> subitemsV1 = new HashMap<>();104Map<String, Object> subitemsV2 = new HashMap<>();105106Map<String, Object> itemsV1 = new HashMap<>();107Map<String, Object> itemsV2 = new HashMap<>();108109subitemsV1.put("item1", "item1");110subitemsV2.put("item1", "item1");111subitemsV2.put("item2", 42);112113itemsV1.put("item1", "item1");114itemsV1.put("item2", new CompositeData[]{new CompositeDataSupport(subtypeV1, subitemsV1)});115116itemsV2.put("item1", "item1");117itemsV2.put("item2", new CompositeData[]{new CompositeDataSupport(subtypeV2, subitemsV2)});118119dataV1 = new CompositeDataSupport(typeV1, itemsV1);120dataV2 = new CompositeDataSupport(typeV2, itemsV2);121// ***122} catch (OpenDataException e) {123throw new Error(e);124}125}126127private static class MyDataV1 extends LazyCompositeData {128@Override129protected CompositeData getCompositeData() {130return dataV1;131}132133public boolean isTypeMached(CompositeType type) {134return isTypeMatched(this.getCompositeType(), type);135}136}137138private static class MyDataV2 extends LazyCompositeData {139@Override140protected CompositeData getCompositeData() {141return dataV2;142}143144}145146public static void main(String[] args) throws Exception {147System.out.println("Checking LazyCompositeData.isTypeMatched()");148MyDataV1 v1 = new MyDataV1();149MyDataV2 v2 = new MyDataV2();150151if (!v1.isTypeMached(v2.getCompositeType())) {152System.err.println("=== FAILED");153System.err.println("V1 should be matched by V2");154System.err.println("\n=== V1");155System.err.println(v1.getCompositeType());156System.err.println("\n=== V2");157System.err.println(v2.getCompositeType());158throw new Error();159}160System.out.println("=== PASSED");161}162}163164