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 org.apache.axiom.om.util.UUIDGenerator;
023: import org.apache.axis2.context.ServiceContext;
024: import org.apache.axis2.context.ServiceGroupContext;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: import java.util.Iterator;
029:
030: public abstract class UpdateStateTestCase extends
031: ClusterManagerTestCase {
032:
033: private static final Log log = LogFactory
034: .getLog(UpdateStateTestCase.class);
035:
036: ServiceContext serviceContext1 = null;
037:
038: ServiceGroupContext serviceGroupContext1 = null;
039:
040: String sgcID = null;
041:
042: String key1 = "key1";
043:
044: String key2 = "key2";
045:
046: String key3 = "key3";
047:
048: String val1 = "val1";
049:
050: String val2 = "val2";
051:
052: String val3 = "val3";
053:
054: public void setUp() throws Exception {
055: super .setUp();
056: if (skipChannelTests) {
057: String message = "Cannot run the clustering test setUp.Please make sure that your "
058: + "network service is enabled. Skipping the test...";
059: log.error(message);
060: return;
061: }
062:
063: sgcID = UUIDGenerator.getUUID();
064:
065: //Adding contexts to the Node1
066: serviceGroupContext1 = configurationContext1
067: .createServiceGroupContext(serviceGroup1);
068: serviceGroupContext1.setId(sgcID);
069:
070: serviceContext1 = serviceGroupContext1
071: .getServiceContext(service1);
072: serviceGroupContext1.addServiceContext(serviceContext1);
073:
074: configurationContext1.setProperty(key1, val1);
075: serviceGroupContext1.setProperty(key2, val2);
076: serviceContext1.setProperty(key3, val3);
077:
078: clusterManager1.getContextManager().updateContext(
079: configurationContext1);
080: clusterManager1.getContextManager().updateContext(
081: serviceGroupContext1);
082: clusterManager1.getContextManager().updateContext(
083: serviceContext1);
084:
085: Thread.sleep(1000);
086: }
087:
088: public void testAddProperty() throws Exception {
089:
090: if (skipChannelTests) {
091: String message = "Cannot run the clustering test.Please make sure that your network "
092: + "service is enabled. Skipping the test...";
093: log.error(message);
094: return;
095: }
096:
097: //TODO uncomment this when configCtx proeprty updates are supported
098: // Object val = configurationContext2.getProperty(key1);
099: // assertNotNull(val);
100: // assertEquals(val, val1);
101:
102: /*ServiceGroupContext serviceGroupContext2 =
103: configurationContext2.getServiceGroupContext(sgcID);
104: assertNotNull(serviceGroupContext2);
105: Object val = serviceGroupContext2.getProperty(key2);
106: assertNotNull(val);
107: assertEquals(val, val2);
108:
109: Thread.sleep(1000);
110:
111: Iterator iter = serviceGroupContext2.getServiceContexts();
112: assertNotNull(iter);
113: assertTrue(iter.hasNext());
114: ServiceContext serviceContext2 = (ServiceContext) iter.next();
115: assertNotNull(serviceContext2);
116: val = serviceContext2.getProperty(key3);
117: assertNotNull(val);
118: assertEquals(val, val3);*/
119:
120: }
121:
122: public void testRemoveProperty() throws Exception {
123:
124: if (skipChannelTests) {
125: String message = "Cannot run the clustering test.Please make sure that your network "
126: + "service is enabled. Skipping the test...";
127: log.error(message);
128: return;
129: }
130:
131: /*serviceGroupContext1.removeProperty(key2);
132: serviceContext1.removeProperty(key3);
133:
134: clusterManager1.getContextManager().updateContext(serviceContext1);
135: clusterManager1.getContextManager().updateContext(serviceGroupContext1);
136:
137: Thread.sleep(1000);
138:
139: ServiceGroupContext serviceGroupContext2 = configurationContext2
140: .getServiceGroupContext(sgcID);
141: assertNotNull(serviceGroupContext2);
142: Object val = serviceGroupContext2.getProperty(key2);
143: assertNull(val);
144:
145: Iterator iter = serviceGroupContext2.getServiceContexts();
146: assertNotNull(iter);
147: assertTrue(iter.hasNext());
148: ServiceContext serviceContext2 = (ServiceContext) iter.next();
149: assertNotNull(serviceContext2);
150: val = serviceContext2.getProperty(key3);
151: assertNull(val);*/
152:
153: }
154:
155: public void testUpdateProperty() throws Exception {
156:
157: if (skipChannelTests) {
158: String message = "Cannot run the clustering test.Please make sure that your network "
159: + "service is enabled. Skipping the test...";
160: log.error(message);
161: return;
162: }
163:
164: /* serviceGroupContext1.setProperty(key2, val3);
165: serviceContext1.setProperty(key3, val2);
166:
167: clusterManager1.getContextManager().updateContext(serviceContext1);
168: clusterManager1.getContextManager().updateContext(serviceGroupContext1);
169:
170: Thread.sleep(1000);
171:
172: ServiceGroupContext serviceGroupContext2 = configurationContext2
173: .getServiceGroupContext(sgcID);
174: assertNotNull(serviceGroupContext2);
175: Object val = serviceGroupContext2.getProperty(key2);
176: assertNotNull(val);
177: assertEquals(val, val3);
178:
179: Iterator iter = serviceGroupContext2.getServiceContexts();
180: assertNotNull(iter);
181: assertTrue(iter.hasNext());
182: ServiceContext serviceContext2 = (ServiceContext) iter.next();
183: assertNotNull(serviceContext2);
184: val = serviceContext2.getProperty(key3);
185: assertNotNull(val);
186: assertEquals(val, val2);*/
187:
188: }
189:
190: }
|