Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/LazyCompositeDataTest.java
38833 views
1
/*
2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.util.HashMap;
25
import java.util.Map;
26
import javax.management.openmbean.ArrayType;
27
import javax.management.openmbean.CompositeData;
28
import javax.management.openmbean.CompositeDataSupport;
29
import javax.management.openmbean.CompositeType;
30
import javax.management.openmbean.OpenDataException;
31
import javax.management.openmbean.OpenType;
32
import javax.management.openmbean.SimpleType;
33
import sun.management.LazyCompositeData;
34
35
/**
36
* @test
37
* @bug 8139870
38
* @summary sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
39
* @modules java.management/sun.management
40
* @author Jaroslav Bachorik
41
*/
42
43
public class LazyCompositeDataTest {
44
private final static CompositeData dataV1, dataV2;
45
46
static {
47
try {
48
// ***
49
// prepare the composite types
50
51
// composite type stored in an array; V1
52
CompositeType subtypeV1 = new CompositeType(
53
"Subtype1",
54
"Version 1",
55
new String[]{"item1"},
56
new String[]{"Item 1"},
57
new OpenType<?>[]{
58
SimpleType.STRING
59
}
60
);
61
62
// composite type stored in an array; V2
63
CompositeType subtypeV2 = new CompositeType(
64
"Subtype2",
65
"Version 2",
66
new String[]{"item1", "item2"},
67
new String[]{"Item 1", "Item 2"},
68
new OpenType<?>[]{
69
SimpleType.STRING,
70
SimpleType.INTEGER
71
}
72
);
73
74
75
// main composite type; V1
76
// one of the items is array of 'subtypeV1' instances
77
CompositeType typeV1 = new CompositeType(
78
"MyDataV1",
79
"Version 1",
80
new String[]{"item1", "item2"},
81
new String[]{"Item 1", "Item 2"},
82
new OpenType<?>[]{
83
SimpleType.STRING,
84
ArrayType.getArrayType(subtypeV1)
85
}
86
);
87
88
// main composite type; V2
89
// one of the items is array of 'subtypeV2' instances
90
CompositeType typeV2 = new CompositeType(
91
"MyDataV2",
92
"Version 2",
93
new String[]{"item1", "item2"},
94
new String[]{"Item 1", "Item 2"},
95
new OpenType<?>[]{
96
SimpleType.STRING,
97
ArrayType.getArrayType(subtypeV2)
98
}
99
);
100
// ***
101
102
// ***
103
// construct the data
104
Map<String, Object> subitemsV1 = new HashMap<>();
105
Map<String, Object> subitemsV2 = new HashMap<>();
106
107
Map<String, Object> itemsV1 = new HashMap<>();
108
Map<String, Object> itemsV2 = new HashMap<>();
109
110
subitemsV1.put("item1", "item1");
111
subitemsV2.put("item1", "item1");
112
subitemsV2.put("item2", 42);
113
114
itemsV1.put("item1", "item1");
115
itemsV1.put("item2", new CompositeData[]{new CompositeDataSupport(subtypeV1, subitemsV1)});
116
117
itemsV2.put("item1", "item1");
118
itemsV2.put("item2", new CompositeData[]{new CompositeDataSupport(subtypeV2, subitemsV2)});
119
120
dataV1 = new CompositeDataSupport(typeV1, itemsV1);
121
dataV2 = new CompositeDataSupport(typeV2, itemsV2);
122
// ***
123
} catch (OpenDataException e) {
124
throw new Error(e);
125
}
126
}
127
128
private static class MyDataV1 extends LazyCompositeData {
129
@Override
130
protected CompositeData getCompositeData() {
131
return dataV1;
132
}
133
134
public boolean isTypeMached(CompositeType type) {
135
return isTypeMatched(this.getCompositeType(), type);
136
}
137
}
138
139
private static class MyDataV2 extends LazyCompositeData {
140
@Override
141
protected CompositeData getCompositeData() {
142
return dataV2;
143
}
144
145
}
146
147
public static void main(String[] args) throws Exception {
148
System.out.println("Checking LazyCompositeData.isTypeMatched()");
149
MyDataV1 v1 = new MyDataV1();
150
MyDataV2 v2 = new MyDataV2();
151
152
if (!v1.isTypeMached(v2.getCompositeType())) {
153
System.err.println("=== FAILED");
154
System.err.println("V1 should be matched by V2");
155
System.err.println("\n=== V1");
156
System.err.println(v1.getCompositeType());
157
System.err.println("\n=== V2");
158
System.err.println(v2.getCompositeType());
159
throw new Error();
160
}
161
System.out.println("=== PASSED");
162
}
163
}
164