1 /*
2 * Copyright (c) 1998, 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 */
169 throw new AssertionError("this should be unreachable");
170 }
171 }
172
173 public static double getTimeoutFactor() {
174 String prop = getProperty("test.timeout.factor", "1.0");
175 double timeoutFactor = 1.0;
176
177 try {
178 timeoutFactor = Double.parseDouble(prop);
179 } catch (NumberFormatException ignore) { }
180
181 return timeoutFactor;
182 }
183
184 /**
185 * Computes a deadline from a timestamp and a timeout value.
186 * Maximum timeout (before multipliers are applied) is one hour.
187 */
188 public static long computeDeadline(long timestamp, long timeout) {
189 final long MAX_TIMEOUT_MS = 3_600_000L;
190
191 if (timeout < 0L || timeout > MAX_TIMEOUT_MS) {
192 throw new IllegalArgumentException("timeout " + timeout + "ms out of range");
193 }
194
195 return timestamp + (long)(timeout * getTimeoutFactor());
196 }
197
198 /**
199 * Property mutators
200 */
201 public static void setBoolean(String property, boolean value) {
202 setProperty(property, (new Boolean(value)).toString());
203 }
204 public static void setInteger(String property, int value) {
205 setProperty(property, Integer.toString(value));
206 }
207 public static void setProperty(String property, String value) {
208 final String prop = property;
209 final String val = value;
210 java.security.AccessController.doPrivileged(
211 new java.security.PrivilegedAction<Void>() {
|
1 /*
2 * Copyright (c) 1998, 2018, 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 */
169 throw new AssertionError("this should be unreachable");
170 }
171 }
172
173 public static double getTimeoutFactor() {
174 String prop = getProperty("test.timeout.factor", "1.0");
175 double timeoutFactor = 1.0;
176
177 try {
178 timeoutFactor = Double.parseDouble(prop);
179 } catch (NumberFormatException ignore) { }
180
181 return timeoutFactor;
182 }
183
184 /**
185 * Computes a deadline from a timestamp and a timeout value.
186 * Maximum timeout (before multipliers are applied) is one hour.
187 */
188 public static long computeDeadline(long timestamp, long timeout) {
189 if (timeout < 0L) {
190 throw new IllegalArgumentException("timeout " + timeout + "ms out of range");
191 }
192
193 return timestamp + (long)(timeout * getTimeoutFactor());
194 }
195
196 /**
197 * Property mutators
198 */
199 public static void setBoolean(String property, boolean value) {
200 setProperty(property, (new Boolean(value)).toString());
201 }
202 public static void setInteger(String property, int value) {
203 setProperty(property, Integer.toString(value));
204 }
205 public static void setProperty(String property, String value) {
206 final String prop = property;
207 final String val = value;
208 java.security.AccessController.doPrivileged(
209 new java.security.PrivilegedAction<Void>() {
|