1 package org.objectweb.celtix.systest.ws.rm; 2 3 import java.net.URL ; 4 import java.util.Collection ; 5 import java.util.HashMap ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 import javax.xml.namespace.QName ; 10 import javax.xml.soap.SOAPElement ; 11 import javax.xml.soap.SOAPMessage ; 12 import javax.xml.ws.BindingProvider; 13 import javax.xml.ws.Endpoint; 14 import javax.xml.ws.handler.Handler; 15 import javax.xml.ws.handler.LogicalMessageContext; 16 17 import junit.framework.Test; 18 import junit.framework.TestSuite; 19 20 import org.objectweb.celtix.Bus; 21 import org.objectweb.celtix.BusException; 22 import org.objectweb.celtix.bindings.AbstractBindingImpl; 23 import org.objectweb.celtix.bus.busimpl.BusConfigurationBuilder; 24 import org.objectweb.celtix.bus.configuration.wsrm.StoreInitParamType; 25 import org.objectweb.celtix.bus.configuration.wsrm.StoreType; 26 import org.objectweb.celtix.bus.ws.rm.Names; 27 import org.objectweb.celtix.bus.ws.rm.RMHandler; 28 import org.objectweb.celtix.bus.ws.rm.persistence.jdbc.RMTxStore; 29 import org.objectweb.celtix.configuration.Configuration; 30 import org.objectweb.celtix.configuration.ConfigurationBuilder; 31 import org.objectweb.celtix.configuration.ConfigurationBuilderFactory; 32 import org.objectweb.celtix.greeter_control.Greeter; 33 import org.objectweb.celtix.greeter_control.GreeterService; 34 import org.objectweb.celtix.systest.common.ClientServerSetupBase; 35 import org.objectweb.celtix.systest.common.ClientServerTestBase; 36 import org.objectweb.celtix.systest.common.TestServerBase; 37 import org.objectweb.celtix.ws.rm.persistence.RMDestinationSequence; 38 import org.objectweb.celtix.ws.rm.persistence.RMMessage; 39 import org.objectweb.celtix.ws.rm.persistence.RMSourceSequence; 40 41 44 public class PersistenceTest extends ClientServerTestBase { 45 46 private static final String APP_NAMESPACE = "http://celtix.objectweb.org/greeter_control"; 47 private static final String GREETMEONEWAY_ACTION = APP_NAMESPACE + "/types/Greeter/greetMeOneWay"; 48 49 private static final QName SERVICE_NAME = new QName (APP_NAMESPACE, "GreeterService"); 50 private static final QName PORT_NAME = new QName (APP_NAMESPACE, "GreeterPort"); 51 52 private Bus bus; 53 private MessageFlow mf; 54 private GreeterService greeterService; 55 private Greeter greeter; 56 private String cfgFileProperty; 57 58 59 public static void main(String [] args) { 60 junit.textui.TestRunner.run(PersistenceTest.class); 61 } 62 63 static class PersistenceTestServer extends TestServerBase { 64 65 protected void run() { 66 67 ControlImpl.setConfigFileProperty("oneway-client-crash"); 68 ConfigurationBuilder builder = ConfigurationBuilderFactory.getBuilder(); 69 builder.buildConfiguration(BusConfigurationBuilder.BUS_CONFIGURATION_URI, "celtix"); 70 71 GreeterImpl implementor = new GreeterImpl(); 72 String address = "http://localhost:9000/SoapContext/GreeterPort"; 73 Endpoint.publish(address, implementor); 74 75 } 76 77 public static void main(String [] args) { 78 try { 79 PersistenceTestServer s = new PersistenceTestServer(); 80 s.start(); 81 } catch (Exception ex) { 82 ex.printStackTrace(); 83 System.exit(-1); 84 } finally { 85 System.out.println("done!"); 86 } 87 } 88 } 89 90 public static Test suite() throws Exception { 91 TestSuite suite = new TestSuite(PersistenceTest.class); 92 return new ClientServerSetupBase(suite) { 93 public void startServers() throws Exception { 94 assertTrue("server did not launch correctly", launchServer(PersistenceTestServer.class, 98 "Windows 2000".equals(System.getProperty("os.name")))); 99 } 100 101 public void setUp() throws Exception { 102 103 RMTxStore.deleteDatabaseFiles("rmpersist", true); 104 105 URL url = getClass().getResource("oneway-client-crash.xml"); 106 assertNotNull("cannot find test resource", url); 107 configFileName = url.toString(); 108 ConfigurationBuilder builder = ConfigurationBuilderFactory.getBuilder(); 109 builder.buildConfiguration(BusConfigurationBuilder.BUS_CONFIGURATION_URI, "celtix"); 110 111 super.setUp(); 112 113 } 114 115 public void tearDown() { 116 RMTxStore.deleteDatabaseFiles("rmpersist", false); 117 } 118 }; 119 } 120 121 public void setUp() throws BusException { 122 123 cfgFileProperty = System.getProperty("celtix.config.file"); 124 URL url = getClass().getResource("oneway-client-crash.xml"); 125 assertNotNull("cannot find test resource", url); 126 String configFileName = url.toString(); 127 System.setProperty("celtix.config.file", configFileName); 128 129 bus = Bus.init(); 130 131 URL wsdl = getClass().getResource("/wsdl/greeter_control.wsdl"); 132 greeterService = new GreeterService(wsdl, SERVICE_NAME); 133 134 greeter = greeterService.getPort(PORT_NAME, Greeter.class); 135 136 BindingProvider provider = (BindingProvider)greeter; 137 AbstractBindingImpl abi = (AbstractBindingImpl)provider.getBinding(); 138 List <Handler> handlerChain = abi.getHandlerChain(); 139 assertTrue(handlerChain.size() > 0); 140 141 List <SOAPMessage > outboundMessages = null; 142 List <LogicalMessageContext> inboundContexts = null; 143 144 145 boolean found = false; 146 for (Handler h : handlerChain) { 147 if (!found && h instanceof SOAPMessageRecorder) { 148 SOAPMessageRecorder recorder = (SOAPMessageRecorder)h; 149 outboundMessages = recorder.getOutboundMessages(); 150 outboundMessages.clear(); 151 found = true; 152 break; 153 } 154 } 155 assertTrue("Could not find SOAPMessageRecorder in handler chain", found); 156 handlerChain = abi.getPreLogicalSystemHandlers(); 157 assertTrue(handlerChain.size() > 0); 158 found = false; 159 for (Handler h : handlerChain) { 160 if (!found && h instanceof LogicalMessageContextRecorder) { 161 LogicalMessageContextRecorder recorder = (LogicalMessageContextRecorder)h; 162 inboundContexts = recorder.getInboundContexts(); 163 inboundContexts.clear(); 164 found = true; 165 break; 166 } 167 } 168 assertTrue("Could not find LogicalMessageContextRecorder in pre logical system handler chain", found); 169 170 mf = new MessageFlow(outboundMessages, inboundContexts); 171 172 } 173 174 public void tearDown() throws BusException { 175 RMHandler rmh = getRMHandler(); 176 rmh.destroy(); 177 178 greeter = null; 179 bus.shutdown(true); 180 181 if (null == cfgFileProperty) { 182 System.clearProperty("celtix.config.file"); 183 } else { 184 System.setProperty("celtix.config.file", cfgFileProperty); 185 } 186 } 187 188 public void testPopulateStore() throws Exception { 189 190 greeter.greetMeOneWay("one"); 191 greeter.greetMeOneWay("two"); 192 greeter.greetMeOneWay("three"); 193 194 mf.verifyMessages(4, true); 195 String [] expectedActions = new String [] {Names.WSRM_CREATE_SEQUENCE_ACTION, 196 GREETMEONEWAY_ACTION, 197 GREETMEONEWAY_ACTION, 198 GREETMEONEWAY_ACTION}; 199 mf.verifyActions(expectedActions, true); 200 mf.verifyMessageNumbers(new String [] {null, "1", "2", "3"}, true); 201 202 203 mf.verifyMessages(5, false); 204 expectedActions = new String [] {null, Names.WSRM_CREATE_SEQUENCE_RESPONSE_ACTION, 205 null, null, null}; 206 mf.verifyActions(expectedActions, false); 207 mf.verifyMessageNumbers(new String [5], false); 208 boolean[] expectedAcks = new boolean[5]; 209 mf.verifyAcknowledgements(expectedAcks, false); 210 211 RMHandler rmh = getRMHandler(); 212 assertNotNull(rmh); 213 214 RMTxStore store = getStore(rmh); 215 assertNotNull(store); 216 217 Collection <RMDestinationSequence> dss = 218 store.getDestinationSequences(rmh.getConfiguration().getParent().getId().toString()); 219 assertEquals(1, dss.size()); 220 221 Collection <RMSourceSequence> sss = 222 store.getSourceSequences(rmh.getConfiguration().getParent().getId().toString()); 223 assertEquals(1, sss.size()); 224 225 Collection <RMMessage> msgs = 226 store.getMessages(sss.iterator().next().getIdentifier(), true); 227 assertEquals(3, msgs.size()); 228 } 229 230 public void testRecover() throws Exception { 231 232 234 try { 235 Thread.sleep(1000 * 10); 236 } catch (InterruptedException ex) { 237 } 239 240 int n = mf.getOutboundMessages().size(); 241 assertTrue(n > 0); 242 String [] expectedActions = new String [n]; 243 for (int i = 0; i < n; i++) { 244 expectedActions[i] = GREETMEONEWAY_ACTION; 245 } 246 mf.verifyActions(expectedActions, true); 247 for (int i = 0; i < n; i++) { 248 SOAPElement elem = mf.getSequence(mf.getOutboundMessages().get(i)); 249 int mn = Integer.parseInt(mf.getMessageNumber(elem)); 250 assertTrue(mn >= 1 && mn <= 3); 251 } 252 253 } 254 255 private RMHandler getRMHandler() { 256 BindingProvider provider = (BindingProvider)greeter; 257 AbstractBindingImpl abi = (AbstractBindingImpl)provider.getBinding(); 258 List <Handler> handlerChain = abi.getPreLogicalSystemHandlers(); 259 assertTrue(handlerChain.size() > 0); 260 for (Handler h : handlerChain) { 261 if (h instanceof RMHandler) { 262 return (RMHandler)h; 263 } 264 } 265 return null; 266 } 267 268 private RMTxStore getStore(RMHandler rmh) { 269 Configuration cfg = rmh.getConfiguration(); 270 StoreType s = cfg.getObject(StoreType.class, "store"); 271 Map <String , String > params = new HashMap <String , String >(); 272 for (StoreInitParamType p : s.getInitParam()) { 273 String name = p.getParamName(); 274 String value = p.getParamValue(); 275 params.put(name, value); 276 } 277 RMTxStore store = new RMTxStore(); 278 store.init(params); 279 return store; 280 } 281 282 } 283 | Popular Tags |