use of org.apache.cxf.testutil.recorders.OutMessageRecorder in project cxf by apache.
the class RMPolicyWsdlTestBase method setUpBus.
public void setUpBus(String port) throws Exception {
SpringBusFactory bf = new SpringBusFactory();
bus = bf.createBus("org/apache/cxf/systest/ws/policy/rmwsdl.xml");
BusFactory.setDefaultBus(bus);
outRecorder = new OutMessageRecorder();
bus.getOutInterceptors().add(outRecorder);
inRecorder = new InMessageRecorder();
bus.getInInterceptors().add(inRecorder);
}
use of org.apache.cxf.testutil.recorders.OutMessageRecorder in project cxf by apache.
the class AbstractClientPersistenceTest method startClient.
void startClient() throws Exception {
LOG.fine("Creating greeter client");
System.setProperty("db.name", getPrefix() + "-client");
SpringBusFactory bf = new SpringBusFactory();
bus = bf.createBus("/org/apache/cxf/systest/ws/rm/persistent.xml");
BusFactory.setDefaultBus(bus);
System.clearProperty("db.name");
GreeterService gs = new GreeterService();
greeter = gs.getGreeterPort();
updateAddressPort(greeter, getPort());
((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
out = new OutMessageRecorder();
in = new InMessageRecorder();
bus.getOutInterceptors().add(out);
bus.getInInterceptors().add(in);
}
use of org.apache.cxf.testutil.recorders.OutMessageRecorder in project cxf by apache.
the class AbstractServerPersistenceTest method testRecovery.
@Test
public void testRecovery() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
bus = bf.createBus();
BusFactory.setDefaultBus(bus);
LOG.fine("Created bus " + bus + " with default cfg");
ControlService cs = new ControlService();
Control control = cs.getControlPort();
ConnectionHelper.setKeepAliveConnection(control, false, true);
updateAddressPort(control, getPort());
assertTrue("Failed to start greeter", control.startGreeter(SERVER_LOSS_CFG));
LOG.fine("Started greeter server.");
System.setProperty("db.name", getPrefix() + "-recovery");
greeterBus = new SpringBusFactory().createBus(CFG);
System.clearProperty("db.name");
LOG.fine("Created bus " + greeterBus + " with cfg : " + CFG);
BusFactory.setDefaultBus(greeterBus);
// avoid early client resends
greeterBus.getExtension(RMManager.class).getConfiguration().setBaseRetransmissionInterval(new Long(60000));
GreeterService gs = new GreeterService();
Greeter greeter = gs.getGreeterPort();
updateAddressPort(greeter, getPort());
LOG.fine("Created greeter client.");
ConnectionHelper.setKeepAliveConnection(greeter, false, true);
Client c = ClientProxy.getClient(greeter);
HTTPConduit hc = (HTTPConduit) (c.getConduit());
HTTPClientPolicy cp = hc.getClient();
cp.setDecoupledEndpoint("http://localhost:" + getDecoupledPort() + "/decoupled_endpoint");
out = new OutMessageRecorder();
in = new InMessageRecorder();
greeterBus.getOutInterceptors().add(out);
greeterBus.getInInterceptors().add(in);
LOG.fine("Configured greeter client.");
Response<GreetMeResponse>[] responses = cast(new Response[4]);
responses[0] = greeter.greetMeAsync("one");
responses[1] = greeter.greetMeAsync("two");
responses[2] = greeter.greetMeAsync("three");
verifyMissingResponse(responses);
control.stopGreeter(SERVER_LOSS_CFG);
LOG.fine("Stopped greeter server");
out.getOutboundMessages().clear();
in.getInboundMessages().clear();
control.startGreeter(CFG);
String nl = System.getProperty("line.separator");
LOG.fine("Restarted greeter server" + nl + nl);
verifyServerRecovery(responses);
responses[3] = greeter.greetMeAsync("four");
verifyRetransmissionQueue();
verifyAcknowledgementRange(1, 4);
out.getOutboundMessages().clear();
in.getInboundMessages().clear();
greeterBus.shutdown(true);
control.stopGreeter(CFG);
bus.shutdown(true);
}
use of org.apache.cxf.testutil.recorders.OutMessageRecorder in project cxf by apache.
the class SequenceTest method testMultiClientOneway.
@Test
public void testMultiClientOneway() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
String cfgResource = "org/apache/cxf/systest/ws/rm/rminterceptors.xml";
initControl(bf, cfgResource);
class ClientThread extends Thread {
Greeter greeter;
Bus greeterBus;
InMessageRecorder inRecorder;
OutMessageRecorder outRecorder;
String id;
ClientThread(SpringBusFactory bf, String cfgResource, int n) {
SequenceTest.this.initGreeter(bf, cfgResource, false, null);
greeter = SequenceTest.this.greeter;
greeterBus = SequenceTest.this.greeterBus;
inRecorder = SequenceTest.this.inRecorder;
outRecorder = SequenceTest.this.outRecorder;
id = "client " + n;
}
public void run() {
greeter.greetMeOneWay(id + ": once");
greeter.greetMeOneWay(id + ": twice");
greeter.greetMeOneWay(id + ": thrice");
// three application messages plus createSequence
awaitMessages(4, 4);
}
}
ClientThread[] clients = new ClientThread[2];
try {
for (int i = 0; i < clients.length; i++) {
clients[i] = new ClientThread(bf, cfgResource, i);
}
for (int i = 0; i < clients.length; i++) {
clients[i].start();
}
for (int i = 0; i < clients.length; i++) {
clients[i].join();
MessageFlow mf = new MessageFlow(clients[i].outRecorder.getOutboundMessages(), clients[i].inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(4, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3" }, true);
// createSequenceResponse plus 3 partial responses
mf.verifyMessages(4, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, null, null, null }, false);
mf.verifyAcknowledgements(new boolean[] { false, true, true, true }, false);
}
} finally {
for (int i = 0; i < clients.length; i++) {
greeter = clients[i].greeter;
greeterBus = clients[i].greeterBus;
stopClient();
}
greeter = null;
}
}
use of org.apache.cxf.testutil.recorders.OutMessageRecorder in project cxf by apache.
the class SequenceTest method testMultiClientTwoway.
@Test
public void testMultiClientTwoway() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
String cfgResource = "org/apache/cxf/systest/ws/rm/rminterceptors.xml";
initControl(bf, cfgResource);
class ClientThread extends Thread {
Greeter greeter;
Bus greeterBus;
InMessageRecorder inRecorder;
OutMessageRecorder outRecorder;
String id;
ClientThread(SpringBusFactory bf, String cfgResource, int n) {
super("client " + n);
SequenceTest.this.initGreeter(bf, cfgResource, true, null);
greeter = SequenceTest.this.greeter;
greeterBus = SequenceTest.this.greeterBus;
inRecorder = SequenceTest.this.inRecorder;
outRecorder = SequenceTest.this.outRecorder;
id = "client " + n;
}
public void run() {
String s = greeter.greetMe(id + ": a").toLowerCase();
if (!s.contains(id)) {
System.out.println("Correlation problem <" + s + "> <" + id + ">");
}
s = greeter.greetMe(id + ": b").toLowerCase();
if (!s.contains(id)) {
System.out.println("Correlation problem <" + s + "> <" + id + ">");
}
s = greeter.greetMe(id + ": c").toLowerCase();
if (!s.contains(id)) {
System.out.println("Correlation problem <" + s + "> <" + id + ">");
}
// three application messages plus createSequence
awaitMessages(5, 4);
}
}
ClientThread[] clients = new ClientThread[2];
try {
for (int i = 0; i < clients.length; i++) {
clients[i] = new ClientThread(bf, cfgResource, i);
}
for (int i = 0; i < clients.length; i++) {
clients[i].start();
}
for (int i = 0; i < clients.length; i++) {
clients[i].join();
}
for (int i = 0; i < clients.length; i++) {
MessageFlow mf = new MessageFlow(clients[i].outRecorder.getOutboundMessages(), clients[i].inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(5, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETME_ACTION, GREETME_ACTION, GREETME_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3", null }, true);
mf.verifyLastMessage(new boolean[] { false, false, false, false, false }, true);
mf.verifyAcknowledgements(new boolean[] { false, false, true, true, true }, true);
// createSequenceResponse plus 3 greetMeResponse messages plus
// one sequence ack response.
mf.verifyMessages(4, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3" }, false);
mf.verifyLastMessage(new boolean[4], false);
mf.verifyAcknowledgements(new boolean[] { false, true, true, true }, false);
}
} finally {
for (int i = 0; i < clients.length; i++) {
greeter = clients[i].greeter;
greeterBus = clients[i].greeterBus;
stopClient();
}
greeter = null;
}
}
Aggregations