author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 26859 | 8df035e321b8 |
permissions | -rw-r--r-- |
26859
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
1 |
/* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
4 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
8 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
14 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
18 |
* |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
22 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
23 |
import java.io.ByteArrayInputStream; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
24 |
import java.io.FilePermission; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
25 |
import java.io.IOException; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
26 |
import java.security.AccessControlException; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
27 |
import java.security.CodeSource; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
28 |
import java.security.Permission; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
29 |
import java.security.PermissionCollection; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
30 |
import java.security.Permissions; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
31 |
import java.security.Policy; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
32 |
import java.security.ProtectionDomain; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
34 |
import java.util.Collections; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
35 |
import java.util.ConcurrentModificationException; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
36 |
import java.util.Enumeration; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
37 |
import java.util.HashSet; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
38 |
import java.util.PropertyPermission; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
39 |
import java.util.Set; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
40 |
import java.util.concurrent.atomic.AtomicLong; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
41 |
import java.util.logging.LogManager; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
42 |
import java.util.logging.LoggingPermission; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
43 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
44 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
45 |
* @test |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
46 |
* @bug 8043306 |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
47 |
* @summary tests LogManager.addConfigurationListener and |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
48 |
* LogManager.removeConfigurationListener; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
49 |
* @build TestConfigurationListeners |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
50 |
* @run main/othervm TestConfigurationListeners UNSECURE |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
51 |
* @run main/othervm TestConfigurationListeners PERMISSION |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
52 |
* @run main/othervm TestConfigurationListeners SECURE |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
53 |
* @author danielfuchs |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
54 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
55 |
public class TestConfigurationListeners { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
56 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
57 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
58 |
* We will test add and remove ConfigurationListeners in 3 configurations. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
59 |
* UNSECURE: No security manager. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
60 |
* SECURE: With the security manager present - and the required |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
61 |
* LoggingPermission("control") granted. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
62 |
* PERMISSION: With the security manager present - and the required |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
63 |
* LoggingPermission("control") *not* granted. Here we will |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
64 |
* test that the expected security permission is thrown. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
65 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
66 |
public static enum TestCase { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
67 |
UNSECURE, SECURE, PERMISSION; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
68 |
public void run(String name) throws Exception { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
69 |
System.out.println("Running test case: " + name()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
70 |
switch (this) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
71 |
case UNSECURE: |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
72 |
testUnsecure(name); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
73 |
break; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
74 |
case SECURE: |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
75 |
testSecure(name); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
76 |
break; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
77 |
case PERMISSION: |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
78 |
testPermission(name); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
79 |
break; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
80 |
default: |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
81 |
throw new Error("Unknown test case: "+this); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
82 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
83 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
84 |
public String loggerName(String name) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
85 |
return name; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
86 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
87 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
88 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
89 |
public static void main(String... args) throws Exception { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
90 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
91 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
92 |
if (args == null || args.length == 0) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
93 |
args = new String[] { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
94 |
TestCase.UNSECURE.name(), |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
95 |
TestCase.SECURE.name(), |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
96 |
}; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
97 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
98 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
99 |
for (String testName : args) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
100 |
TestCase test = TestCase.valueOf(testName); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
101 |
test.run(test.loggerName("foo.bar")); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
102 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
103 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
104 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
105 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
106 |
* Test without security manager. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
107 |
* @param loggerName The logger to use. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
108 |
* @throws Exception if the test fails. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
109 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
110 |
public static void testUnsecure(String loggerName) throws Exception { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
111 |
if (System.getSecurityManager() != null) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
112 |
throw new Error("Security manager is set"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
113 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
114 |
test(loggerName); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
115 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
116 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
117 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
118 |
* Test with security manager. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
119 |
* @param loggerName The logger to use. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
120 |
* @throws Exception if the test fails. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
121 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
122 |
public static void testSecure(String loggerName) throws Exception { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
123 |
if (System.getSecurityManager() != null) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
124 |
throw new Error("Security manager is already set"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
125 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
126 |
Policy.setPolicy(new SimplePolicy(TestCase.SECURE)); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
127 |
System.setSecurityManager(new SecurityManager()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
128 |
test(loggerName); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
129 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
130 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
131 |
/** |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
132 |
* Test the LoggingPermission("control") is required. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
133 |
* @param loggerName The logger to use. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
134 |
*/ |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
135 |
public static void testPermission(String loggerName) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
136 |
TestConfigurationListener run = new TestConfigurationListener( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
137 |
TestCase.PERMISSION.toString()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
138 |
if (System.getSecurityManager() != null) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
139 |
throw new Error("Security manager is already set"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
140 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
141 |
Policy.setPolicy(new SimplePolicy(TestCase.PERMISSION)); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
142 |
System.setSecurityManager(new SecurityManager()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
143 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
144 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
145 |
LogManager.getLogManager().addConfigurationListener(run); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
146 |
throw new RuntimeException("addConfigurationListener: Permission not checked!"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
147 |
} catch (AccessControlException x) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
148 |
boolean ok = false; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
149 |
if (x.getPermission() instanceof LoggingPermission) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
150 |
if ("control".equals(x.getPermission().getName())) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
151 |
System.out.println("addConfigurationListener: Got expected exception: " + x); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
152 |
ok = true; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
153 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
154 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
155 |
if (!ok) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
156 |
throw new RuntimeException("addConfigurationListener: Unexpected exception: "+x, x); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
157 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
158 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
159 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
160 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
161 |
LogManager.getLogManager().removeConfigurationListener(run); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
162 |
throw new RuntimeException("removeConfigurationListener: Permission not checked!"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
163 |
} catch (AccessControlException x) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
164 |
boolean ok = false; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
165 |
if (x.getPermission() instanceof LoggingPermission) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
166 |
if ("control".equals(x.getPermission().getName())) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
167 |
System.out.println("removeConfigurationListener: Got expected exception: " + x); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
168 |
ok = true; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
169 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
170 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
171 |
if (!ok) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
172 |
throw new RuntimeException("removeConfigurationListener: Unexpected exception: "+x, x); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
173 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
174 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
175 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
176 |
LogManager.getLogManager().addConfigurationListener(null); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
177 |
throw new RuntimeException( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
178 |
"addConfigurationListener(null): Expected NPE not thrown."); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
179 |
} catch (NullPointerException npe) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
180 |
System.out.println("Got expected NPE: "+npe); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
181 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
182 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
183 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
184 |
LogManager.getLogManager().removeConfigurationListener(null); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
185 |
throw new RuntimeException( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
186 |
"removeConfigurationListener(null): Expected NPE not thrown."); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
187 |
} catch (NullPointerException npe) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
188 |
System.out.println("Got expected NPE: "+npe); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
189 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
190 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
191 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
192 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
193 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
194 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
195 |
static class TestConfigurationListener implements Runnable { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
196 |
final AtomicLong count = new AtomicLong(0); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
197 |
final String name; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
198 |
TestConfigurationListener(String name) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
199 |
this.name = name; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
200 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
201 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
202 |
public void run() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
203 |
final long times = count.incrementAndGet(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
204 |
System.out.println("Configured \"" + name + "\": " + times); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
205 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
206 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
207 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
208 |
static class ConfigurationListenerException extends RuntimeException { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
209 |
public ConfigurationListenerException(String msg) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
210 |
super(msg); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
211 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
212 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
213 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
214 |
public String toString() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
215 |
return this.getClass().getName() + ": " + getMessage(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
216 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
217 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
218 |
static class ConfigurationListenerError extends Error { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
219 |
public ConfigurationListenerError(String msg) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
220 |
super(msg); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
221 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
222 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
223 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
224 |
public String toString() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
225 |
return this.getClass().getName() + ": " + getMessage(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
226 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
227 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
228 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
229 |
static class ThrowingConfigurationListener extends TestConfigurationListener { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
230 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
231 |
final boolean error; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
232 |
public ThrowingConfigurationListener(String name, boolean error) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
233 |
super(name); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
234 |
this.error = error; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
235 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
236 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
237 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
238 |
public void run() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
239 |
if (error) |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
240 |
throw new ConfigurationListenerError(name); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
241 |
else |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
242 |
throw new ConfigurationListenerException(name); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
243 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
244 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
245 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
246 |
public String toString() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
247 |
final Class<? extends Throwable> type = |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
248 |
error ? ConfigurationListenerError.class |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
249 |
: ConfigurationListenerException.class; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
250 |
return type.getName()+ ": " + name; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
251 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
252 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
253 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
254 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
255 |
private static void expect(TestConfigurationListener listener, long value) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
256 |
final long got = listener.count.longValue(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
257 |
if (got != value) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
258 |
throw new RuntimeException(listener.name + " expected " + value +", got " + got); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
259 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
260 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
261 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
262 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
263 |
public interface ThrowingConsumer<T, I extends Exception> { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
264 |
public void accept(T t) throws I; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
265 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
266 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
267 |
public static class ReadConfiguration implements ThrowingConsumer<LogManager, IOException> { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
268 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
269 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
270 |
public void accept(LogManager t) throws IOException { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
271 |
t.readConfiguration(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
272 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
273 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
274 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
275 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
276 |
public static void test(String loggerName) throws Exception { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
277 |
System.out.println("Starting test for " + loggerName); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
278 |
test("m.readConfiguration()", (m) -> m.readConfiguration()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
279 |
test("m.readConfiguration(new ByteArrayInputStream(new byte[0]))", |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
280 |
(m) -> m.readConfiguration(new ByteArrayInputStream(new byte[0]))); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
281 |
System.out.println("Test passed for " + loggerName); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
282 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
283 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
284 |
public static void test(String testName, |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
285 |
ThrowingConsumer<LogManager, IOException> readConfiguration) throws Exception { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
286 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
287 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
288 |
System.out.println("\nBEGIN " + testName); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
289 |
LogManager m = LogManager.getLogManager(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
290 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
291 |
final TestConfigurationListener l1 = new TestConfigurationListener("l#1"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
292 |
final TestConfigurationListener l2 = new TestConfigurationListener("l#2"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
293 |
final TestConfigurationListener l3 = new ThrowingConfigurationListener("l#3", false); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
294 |
final TestConfigurationListener l4 = new ThrowingConfigurationListener("l#4", true); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
295 |
final TestConfigurationListener l5 = new ThrowingConfigurationListener("l#5", false); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
296 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
297 |
final Set<String> expectedExceptions = |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
298 |
Collections.unmodifiableSet( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
299 |
new HashSet<>(Arrays.asList( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
300 |
l3.toString(), l4.toString(), l5.toString()))); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
301 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
302 |
m.addConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
303 |
m.addConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
304 |
expect(l1, 0); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
305 |
expect(l2, 0); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
306 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
307 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
308 |
expect(l1, 1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
309 |
expect(l2, 1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
310 |
m.addConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
311 |
expect(l1, 1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
312 |
expect(l2, 1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
313 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
314 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
315 |
expect(l2, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
316 |
m.removeConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
317 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
318 |
expect(l2, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
319 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
320 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
321 |
expect(l2, 3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
322 |
m.removeConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
323 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
324 |
expect(l2, 3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
325 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
326 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
327 |
expect(l2, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
328 |
m.removeConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
329 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
330 |
expect(l2, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
331 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
332 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
333 |
expect(l2, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
334 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
335 |
// l1 and l2 should no longer be present: this should not fail... |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
336 |
m.removeConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
337 |
m.removeConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
338 |
m.removeConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
339 |
m.removeConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
340 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
341 |
expect(l2, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
342 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
343 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
344 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
345 |
expect(l2, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
346 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
347 |
// add back l1 and l2 |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
348 |
m.addConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
349 |
m.addConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
350 |
expect(l1, 2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
351 |
expect(l2, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
352 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
353 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
354 |
expect(l1, 3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
355 |
expect(l2, 5); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
356 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
357 |
m.removeConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
358 |
m.removeConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
359 |
expect(l1, 3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
360 |
expect(l2, 5); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
361 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
362 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
363 |
expect(l1, 3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
364 |
expect(l2, 5); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
365 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
366 |
// Check the behavior when listeners throw exceptions |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
367 |
// l3, l4, and l5 will throw an error/exception. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
368 |
// The first that is raised will be propagated, after all listeners |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
369 |
// have been invoked. The other exceptions will be added to the |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
370 |
// suppressed list. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
371 |
// |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
372 |
// We will check that all listeners have been invoked and that we |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
373 |
// have the set of 3 exceptions expected from l3, l4, l5. |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
374 |
// |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
375 |
m.addConfigurationListener(l4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
376 |
m.addConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
377 |
m.addConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
378 |
m.addConfigurationListener(l3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
379 |
m.addConfigurationListener(l5); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
380 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
381 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
382 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
383 |
throw new RuntimeException("Excpected exception/error not raised"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
384 |
} catch(ConfigurationListenerException | ConfigurationListenerError t) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
385 |
final Set<String> received = new HashSet<>(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
386 |
received.add(t.toString()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
387 |
for (Throwable s : t.getSuppressed()) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
388 |
received.add(s.toString()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
389 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
390 |
System.out.println("Received exceptions: " + received); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
391 |
if (!expectedExceptions.equals(received)) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
392 |
throw new RuntimeException( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
393 |
"List of received exceptions differs from expected:" |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
394 |
+ "\n\texpected: " + expectedExceptions |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
395 |
+ "\n\treceived: " + received); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
396 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
397 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
398 |
expect(l1, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
399 |
expect(l2, 6); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
400 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
401 |
m.removeConfigurationListener(l1); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
402 |
m.removeConfigurationListener(l2); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
403 |
m.removeConfigurationListener(l3); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
404 |
m.removeConfigurationListener(l4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
405 |
m.removeConfigurationListener(l5); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
406 |
readConfiguration.accept(m); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
407 |
expect(l1, 4); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
408 |
expect(l2, 6); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
409 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
410 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
411 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
412 |
m.addConfigurationListener(null); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
413 |
throw new RuntimeException( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
414 |
"addConfigurationListener(null): Expected NPE not thrown."); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
415 |
} catch (NullPointerException npe) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
416 |
System.out.println("Got expected NPE: "+npe); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
417 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
418 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
419 |
try { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
420 |
m.removeConfigurationListener(null); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
421 |
throw new RuntimeException( |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
422 |
"removeConfigurationListener(null): Expected NPE not thrown."); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
423 |
} catch (NullPointerException npe) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
424 |
System.out.println("Got expected NPE: "+npe); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
425 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
426 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
427 |
System.out.println("END " + testName+"\n"); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
428 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
429 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
430 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
431 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
26859
diff
changeset
|
432 |
static final class PermissionsBuilder { |
26859
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
433 |
final Permissions perms; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
434 |
public PermissionsBuilder() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
435 |
this(new Permissions()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
436 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
437 |
public PermissionsBuilder(Permissions perms) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
438 |
this.perms = perms; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
439 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
440 |
public PermissionsBuilder add(Permission p) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
441 |
perms.add(p); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
442 |
return this; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
443 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
444 |
public PermissionsBuilder addAll(PermissionCollection col) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
445 |
if (col != null) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
446 |
for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
447 |
perms.add(e.nextElement()); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
448 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
449 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
450 |
return this; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
451 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
452 |
public Permissions toPermissions() { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
453 |
final PermissionsBuilder builder = new PermissionsBuilder(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
454 |
builder.addAll(perms); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
455 |
return builder.perms; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
456 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
457 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
458 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
459 |
public static class SimplePolicy extends Policy { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
460 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
461 |
final Permissions permissions; |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
462 |
public SimplePolicy(TestCase test) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
463 |
permissions = new Permissions(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
464 |
if (test != TestCase.PERMISSION) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
465 |
permissions.add(new LoggingPermission("control", null)); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
466 |
permissions.add(new PropertyPermission("java.util.logging.config.class", "read")); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
467 |
permissions.add(new PropertyPermission("java.util.logging.config.file", "read")); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
468 |
permissions.add(new PropertyPermission("java.home", "read")); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
469 |
permissions.add(new FilePermission("<<ALL FILES>>", "read")); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
470 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
471 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
472 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
473 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
474 |
public boolean implies(ProtectionDomain domain, Permission permission) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
475 |
return permissions.implies(permission); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
476 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
477 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
478 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
479 |
public PermissionCollection getPermissions(CodeSource codesource) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
480 |
return new PermissionsBuilder().addAll(permissions).toPermissions(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
481 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
482 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
483 |
@Override |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
484 |
public PermissionCollection getPermissions(ProtectionDomain domain) { |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
485 |
return new PermissionsBuilder().addAll(permissions).toPermissions(); |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
486 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
487 |
} |
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
488 |
|
8df035e321b8
8043306: Provide a replacement for the API that allowed to listen for LogManager configuration changes
dfuchs
parents:
diff
changeset
|
489 |
} |