1 /**
2 * Copyright 2003-2006 Greg Luck
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.distribution;
18
19 /**
20 * A utility class for distributed tests
21 *
22 * @author Greg Luck
23 * @version $Id: JVMUtil.java 51 2006-04-24 09:21:10Z gregluck $
24 */
25 public final class JVMUtil {
26 private static final float JDK_1_5 = 1.5f;
27 private static final int FIRST_THREE_CHARS = 3;
28
29 /**
30 * Utility class. No constructor
31 */
32 private JVMUtil() {
33
34 }
35
36
37 /**
38 * JDK Bug Id 4267864 affecting JDKs limits the number of RMI registries to one per virtual
39 * machine. Because tests rely on creating multiple they will only work on JDK1.5.
40 *
41 * This method is used to not run the affected tests on JDK1.4.
42 * @return true if the JDK is limited to one RMI Registry per VM, else false
43 */
44 public static boolean isSingleRMIRegistryPerVM() {
45 String version = System.getProperty("java.version");
46 String majorVersion = version.substring(0, FIRST_THREE_CHARS);
47 float majorVersionFloat = Float.parseFloat(majorVersion);
48 return majorVersionFloat < JDK_1_5;
49 }
50
51
52 /**
53 * Some performance numbers and size limits are higher in 15.
54 * This is used to set the tests as high as possible for each VM.
55 * @return true if JDK1.5 or higher
56 */
57 public static boolean isJDK15() {
58 return !isSingleRMIRegistryPerVM();
59 }
60 }