001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.clustering;
021:
022: import junit.framework.TestCase;
023: import org.apache.axis2.clustering.ClusterManager;
024: import org.apache.axis2.clustering.ClusteringFault;
025: import org.apache.axis2.clustering.context.DefaultContextManagerListener;
026: import org.apache.axis2.clustering.configuration.TestConfigurationManagerListener;
027: import org.apache.axis2.clustering.configuration.ConfigurationManagerListener;
028: import org.apache.axis2.clustering.configuration.DefaultConfigurationManagerListener;
029: import org.apache.axis2.context.ConfigurationContext;
030: import org.apache.axis2.context.ConfigurationContextFactory;
031: import org.apache.axis2.description.AxisService;
032: import org.apache.axis2.description.AxisServiceGroup;
033: import org.apache.axis2.engine.AxisConfiguration;
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: public abstract class ClusterManagerTestCase extends TestCase {
038:
039: protected ClusterManager clusterManager1 = null;
040: protected ClusterManager clusterManager2 = null;
041: protected AxisConfiguration axisConfiguration1 = null;
042: protected AxisConfiguration axisConfiguration2 = null;
043: protected ConfigurationContext configurationContext1 = null;
044: protected ConfigurationContext configurationContext2 = null;
045: protected ConfigurationManagerListener configManagerListener1;
046: protected ConfigurationManagerListener configManagerListener2;
047: protected AxisServiceGroup serviceGroup1 = null;
048: protected AxisServiceGroup serviceGroup2 = null;
049: protected AxisService service1 = null;
050: protected AxisService service2 = null;
051: protected String serviceName = "testService";
052:
053: protected abstract ClusterManager getClusterManager(
054: ConfigurationContext configCtx);
055:
056: protected boolean skipChannelTests = false;
057: protected TestConfigurationManagerListener configurationManagerListener;
058: protected DefaultContextManagerListener contextManagerListener;
059:
060: private static final Log log = LogFactory
061: .getLog(ClusterManagerTestCase.class);
062:
063: protected void setUp() throws Exception {
064:
065: Thread.sleep(3000);
066:
067: configurationContext1 = ConfigurationContextFactory
068: .createDefaultConfigurationContext();
069: configurationContext2 = ConfigurationContextFactory
070: .createDefaultConfigurationContext();
071:
072: clusterManager1 = getClusterManager(configurationContext1);
073: clusterManager2 = getClusterManager(configurationContext2);
074:
075: clusterManager1.getContextManager().setConfigurationContext(
076: configurationContext1);
077: clusterManager2.getContextManager().setConfigurationContext(
078: configurationContext2);
079:
080: clusterManager1.getConfigurationManager()
081: .setConfigurationContext(configurationContext1);
082: clusterManager2.getConfigurationManager()
083: .setConfigurationContext(configurationContext2);
084:
085: configManagerListener1 = new DefaultConfigurationManagerListener();
086: clusterManager1
087: .getConfigurationManager()
088: .setConfigurationManagerListener(configManagerListener1);
089: configManagerListener2 = new DefaultConfigurationManagerListener();
090: clusterManager2
091: .getConfigurationManager()
092: .setConfigurationManagerListener(configManagerListener2);
093:
094: //giving both Nodes the same deployment configuration
095: axisConfiguration1 = configurationContext1
096: .getAxisConfiguration();
097: serviceGroup1 = new AxisServiceGroup(axisConfiguration1);
098: service1 = new AxisService(serviceName);
099: serviceGroup1.addService(service1);
100: axisConfiguration1.addServiceGroup(serviceGroup1);
101:
102: axisConfiguration2 = configurationContext2
103: .getAxisConfiguration();
104: serviceGroup2 = new AxisServiceGroup(axisConfiguration2);
105: service2 = new AxisService(serviceName);
106: serviceGroup2.addService(service2);
107: axisConfiguration2.addServiceGroup(serviceGroup2);
108:
109: //Initiating ClusterManagers
110: try {
111: clusterManager1.init();
112: clusterManager2.init();
113: } catch (ClusteringFault e) {
114: String message = "Could not initialize ClusterManagers. Please check the network connection";
115: if (log.isErrorEnabled()) {
116: log.error(message);
117: }
118:
119: skipChannelTests = true;
120: }
121: }
122:
123: protected void tearDown() throws Exception {
124: super.tearDown();
125: clusterManager1.shutdown();
126: clusterManager2.shutdown();
127: }
128:
129: }
|