Search in sources :

Example 1 with InMessageRecorder

use of org.apache.cxf.testutil.recorders.InMessageRecorder 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);
}
Also used : InMessageRecorder(org.apache.cxf.testutil.recorders.InMessageRecorder) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) OutMessageRecorder(org.apache.cxf.testutil.recorders.OutMessageRecorder)

Example 2 with InMessageRecorder

use of org.apache.cxf.testutil.recorders.InMessageRecorder 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);
}
Also used : InMessageRecorder(org.apache.cxf.testutil.recorders.InMessageRecorder) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) OutMessageRecorder(org.apache.cxf.testutil.recorders.OutMessageRecorder) GreeterService(org.apache.cxf.greeter_control.GreeterService)

Example 3 with InMessageRecorder

use of org.apache.cxf.testutil.recorders.InMessageRecorder 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);
}
Also used : OutMessageRecorder(org.apache.cxf.testutil.recorders.OutMessageRecorder) GreeterService(org.apache.cxf.greeter_control.GreeterService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) GreetMeResponse(org.apache.cxf.greeter_control.types.GreetMeResponse) Response(javax.xml.ws.Response) InMessageRecorder(org.apache.cxf.testutil.recorders.InMessageRecorder) Control(org.apache.cxf.greeter_control.Control) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) ControlService(org.apache.cxf.greeter_control.ControlService) Greeter(org.apache.cxf.greeter_control.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 4 with InMessageRecorder

use of org.apache.cxf.testutil.recorders.InMessageRecorder 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;
    }
}
Also used : Bus(org.apache.cxf.Bus) InMessageRecorder(org.apache.cxf.testutil.recorders.InMessageRecorder) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) OutMessageRecorder(org.apache.cxf.testutil.recorders.OutMessageRecorder) Greeter(org.apache.cxf.greeter_control.Greeter) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 5 with InMessageRecorder

use of org.apache.cxf.testutil.recorders.InMessageRecorder 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;
    }
}
Also used : Bus(org.apache.cxf.Bus) InMessageRecorder(org.apache.cxf.testutil.recorders.InMessageRecorder) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) OutMessageRecorder(org.apache.cxf.testutil.recorders.OutMessageRecorder) Greeter(org.apache.cxf.greeter_control.Greeter) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Aggregations

InMessageRecorder (org.apache.cxf.testutil.recorders.InMessageRecorder)10 OutMessageRecorder (org.apache.cxf.testutil.recorders.OutMessageRecorder)10 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)8 Greeter (org.apache.cxf.greeter_control.Greeter)6 Test (org.junit.Test)6 MessageFlow (org.apache.cxf.systest.ws.util.MessageFlow)5 Closeable (java.io.Closeable)3 BasicGreeterService (org.apache.cxf.greeter_control.BasicGreeterService)3 PingMeFault (org.apache.cxf.greeter_control.PingMeFault)3 Endpoint (javax.xml.ws.Endpoint)2 Bus (org.apache.cxf.Bus)2 GreeterService (org.apache.cxf.greeter_control.GreeterService)2 Response (javax.xml.ws.Response)1 Client (org.apache.cxf.endpoint.Client)1 Control (org.apache.cxf.greeter_control.Control)1 ControlService (org.apache.cxf.greeter_control.ControlService)1 GreetMeResponse (org.apache.cxf.greeter_control.types.GreetMeResponse)1 MessageRecorder (org.apache.cxf.testutil.recorders.MessageRecorder)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)1