KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > j2ee > management > JVMTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.j2ee.management;
19
20 import java.net.InetAddress JavaDoc;
21 import javax.management.j2ee.statistics.JVMStats JavaDoc;
22 import org.apache.geronimo.management.JVM;
23
24 /**
25  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
26  */

27 public class JVMTest extends Abstract77Test {
28     private JVM jvm;
29     private org.apache.geronimo.management.geronimo.JVM jvmEx;
30     private String JavaDoc node;
31     private Runtime JavaDoc runtime;
32
33     public void testStandardInterface() {
34         assertEquals(JVM_DATA.getAbstractName().getObjectName().getCanonicalName(), jvm.getObjectName());
35         assertEquals(System.getProperty("java.version"), jvm.getJavaVersion());
36         assertEquals(System.getProperty("java.vendor"), jvm.getJavaVendor());
37         assertEquals(node, jvm.getNode());
38     }
39
40     public void testStandardAttributes() throws Exception JavaDoc {
41         assertEquals(JVM_DATA.getAbstractName().getObjectName().getCanonicalName(), kernel.getAttribute(JVM_DATA.getAbstractName(), "objectName"));
42         assertEquals(System.getProperty("java.version"), kernel.getAttribute(JVM_DATA.getAbstractName(), "javaVersion"));
43         assertEquals(System.getProperty("java.vendor"), kernel.getAttribute(JVM_DATA.getAbstractName(), "javaVendor"));
44         assertEquals(node, kernel.getAttribute(JVM_DATA.getAbstractName(), "node"));
45     }
46
47     public void testGeronimoInterface() {
48         assertEquals(runtime.availableProcessors(), jvmEx.getAvailableProcessors());
49
50     }
51
52     public void testGeronimoAttributes() throws Exception JavaDoc {
53         assertEquals(new Integer JavaDoc(runtime.availableProcessors()), kernel.getAttribute(JVM_DATA.getAbstractName(), "availableProcessors"));
54     }
55
56     public void testStatistics() throws Exception JavaDoc {
57         assertEquals(Boolean.TRUE, kernel.getAttribute(JVM_DATA.getAbstractName(), "statisticsProvider"));
58         JVMStats JavaDoc stats = (JVMStats JavaDoc) kernel.getAttribute(JVM_DATA.getAbstractName(), "stats");
59         assertNotNull(stats.getHeapSize());
60         assertTrue(stats.getHeapSize().getCurrent() > 0);
61         assertNotNull(stats.getHeapSize().getDescription());
62         assertTrue(stats.getHeapSize().getHighWaterMark() > 0);
63         assertTrue(stats.getHeapSize().getLastSampleTime() > 0);
64         assertTrue(stats.getHeapSize().getLowerBound() == 0);
65         assertTrue(stats.getHeapSize().getLowWaterMark() > 0);
66         assertNotNull(stats.getHeapSize().getName());
67         assertTrue(stats.getHeapSize().getStartTime() > 0);
68         assertNotNull(stats.getHeapSize().getUnit());
69         assertTrue(stats.getHeapSize().getUpperBound() > 0);
70         assertNotNull(stats.getUpTime());
71         assertTrue(stats.getUpTime().getCount() > 0);
72         assertNotNull(stats.getUpTime().getDescription());
73         assertTrue(stats.getUpTime().getLastSampleTime() > 0);
74         assertNotNull(stats.getUpTime().getName());
75         assertTrue(stats.getUpTime().getStartTime() > 0);
76         assertNotNull(stats.getUpTime().getUnit());
77     }
78
79     protected void setUp() throws Exception JavaDoc {
80         super.setUp();
81         jvm = (JVM) kernel.getGBean(JVM_DATA.getAbstractName());
82         jvmEx = (org.apache.geronimo.management.geronimo.JVM) kernel.getGBean(JVM_DATA.getAbstractName());
83         node = InetAddress.getLocalHost().toString();
84         runtime = Runtime.getRuntime();
85     }
86
87     protected void tearDown() throws Exception JavaDoc {
88         super.tearDown();
89     }
90 }
91
Popular Tags