KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > LBTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.config;
25
26 import java.util.Set JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import javax.management.*;
30
31 import com.sun.enterprise.management.AMXTestBase;
32 import com.sun.enterprise.management.Capabilities;
33 import com.sun.enterprise.management.ClusterSupportRequired;
34
35 /**
36   Unit test class to create-delete lb-config and load-balancer elements
37  */

38 public final class LBTest extends AMXTestBase
39     implements ClusterSupportRequired
40 {
41
42     final boolean runDels = true;
43     final boolean runCreates = true;
44     final boolean testGetLoadBalancerConfigMap = false;
45     
46     public LBTest() {}
47
48     public void testCreateLBConfig() {
49         if ( checkNotOffline( "testDeleteLBConfig" ) ) {
50             if (!runCreates) return;
51             String JavaDoc name = "test-lb-config";
52             boolean monitoringEnabled = true;
53             boolean routeCookieEnabled = false;
54             boolean httpsRouting = false;
55             String JavaDoc responseTimeout = "130";
56             String JavaDoc reloadInterval = "380";
57
58             Map JavaDoc<String JavaDoc,String JavaDoc> params = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
59             //params.put("name", name);
60
params.put("route-cookie-enabled", "" + routeCookieEnabled);
61             params.put("monitoring-enabled", "" + monitoringEnabled);
62             params.put("https-routing", "" + httpsRouting);
63             params.put("response-timeout-in-seconds", responseTimeout);
64             params.put("reload-poll-interval-in-seconds", reloadInterval);
65
66             try {
67                 getDomainConfig().createLBConfig(name, params);
68             } catch (Throwable JavaDoc t) {
69                 t.printStackTrace();
70             }
71         }
72     }
73
74     public void testCreateLoadBalancerConfig() {
75     if ( checkNotOffline( "testDeleteLBConfig" ) ) {
76             if (!runCreates) return;
77             String JavaDoc name = "test-load-balancer";
78             String JavaDoc lbConfigName = "test-lb-config";
79             boolean autoApplyEnabled = true;
80             Map JavaDoc<String JavaDoc,String JavaDoc> optional = null;
81             try {
82                 getDomainConfig().createLoadBalancerConfig(name, lbConfigName, autoApplyEnabled, optional);
83             } catch (Throwable JavaDoc t) {
84                 t.printStackTrace();
85             }
86         }
87     }
88
89     public void testGetLBConfigMap() {
90         try {
91             Map JavaDoc map = getDomainConfig().getLBConfigMap();
92             //System.out.println("Here is a list of Load Balancer Config MBeans in DAS: ");
93
//System.out.println(map);
94
} catch (Throwable JavaDoc t) {
95             t.printStackTrace();
96         }
97     }
98     
99     public void testGetLoadBalancerConfigMap() {
100     if (testGetLoadBalancerConfigMap==false) return;
101         try {
102             Map JavaDoc map = getDomainConfig().getLoadBalancerConfigMap();
103             //System.out.println("Here is a list of Load Balancer Config MBeans in DAS: ");
104
//System.out.println(map);
105
ObjectName objName = new ObjectName("amx:j2eeType=X-LoadBalancerConfig,name=test-load-balancer");
106             MBeanInfo minfo = getConnection().getMBeanInfo(objName);
107             MBeanAttributeInfo[] mattrsinfo = minfo.getAttributes();
108             /*
109             for (MBeanAttributeInfo mattrinfo : mattrsinfo)
110             {
111                 System.out.println("Attribute Name is : " + mattrinfo.getName());
112             }
113             */

114             
115             String JavaDoc[] attrsNames = (String JavaDoc[]) getConnection().getAttribute(objName, "AttributeNames");
116             /*for (String attrName : attrsNames)
117                 System.out.println("Actual Attribute Name is : " + attrName);
118             System.out.println("AttributeNames are : " + attrsNames);
119             System.out.println("MBeanInfo is \n"+minfo);*/

120             
121             String JavaDoc attrName = (String JavaDoc) getConnection().getAttribute(objName, "LbConfigName");
122             System.out.println("attrName is = "+attrName);
123     } catch (Throwable JavaDoc t) {
124             t.printStackTrace();
125         }
126     }
127
128     public void testDeleteLoadBalancerConfig() {
129         if ( checkNotOffline( "testDeleteLBConfig" ) ) {
130             
131             if (!runDels) return;
132             String JavaDoc name = "test-load-balancer";
133             try {
134                 getDomainConfig().removeLoadBalancerConfig(name);
135             } catch (Throwable JavaDoc t) {
136                 t.printStackTrace();
137             }
138         }
139     }
140
141     public void testDeleteLBConfig() {
142         if ( checkNotOffline( "testDeleteLBConfig" ) ) {
143             
144             if (!runDels) return;
145             String JavaDoc name = "test-lb-config";
146             try {
147                 getDomainConfig().removeLBConfig(name);
148             } catch (Throwable JavaDoc t) {
149                 t.printStackTrace();
150             }
151         }
152     }
153 }
154
Popular Tags