Search in sources :

Example 31 with SequenceAcknowledgement

use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement in project cxf by apache.

the class DestinationSequenceTest method testInOrderWait.

@Test
public void testInOrderWait() {
    setUpDestination();
    Message[] messages = new Message[5];
    for (int i = 0; i < messages.length; i++) {
        messages[i] = setUpMessage(Integer.toString(i + 1));
    }
    config.setDeliveryAssurance(DeliveryAssurance.AT_LEAST_ONCE);
    SequenceAcknowledgement ack = factory.createSequenceAcknowledgement();
    List<AcknowledgementRange> ranges = new ArrayList<>();
    final AcknowledgementRange r = factory.createSequenceAcknowledgementAcknowledgementRange();
    r.setUpper(new Long(messages.length));
    ranges.add(r);
    final DestinationSequence ds = new DestinationSequence(id, ref, 0, ack, ProtocolVariation.RM10WSA200408);
    ds.setDestination(destination);
    class Acknowledger extends Thread {

        Message message;

        long messageNr;

        Acknowledger(Message m, long mn) {
            message = m;
            messageNr = mn;
        }

        public void run() {
            try {
                ds.acknowledge(message);
                ds.applyDeliveryAssurance(messageNr, message);
            } catch (Exception ex) {
            // ignore
            }
        }
    }
    control.replay();
    Thread[] threads = new Thread[messages.length];
    for (int i = messages.length - 1; i >= 0; i--) {
        threads[i] = new Acknowledger(messages[i], i + 1);
        threads[i].start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
        // ignore
        }
    }
    boolean timedOut = false;
    for (int i = 0; i < messages.length; i++) {
        try {
            threads[i].join(1000);
        } catch (InterruptedException ex) {
            timedOut = true;
        }
    }
    assertTrue("timed out waiting for messages to be processed in order", !timedOut);
    control.verify();
}
Also used : Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) Test(org.junit.Test)

Example 32 with SequenceAcknowledgement

use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement in project cxf by apache.

the class DestinationSequenceTest method testApplyDeliveryAssuranceAtMostOnce.

@Test
public void testApplyDeliveryAssuranceAtMostOnce() throws RMException {
    setUpDestination();
    long mn = 10;
    SequenceAcknowledgement ack = control.createMock(SequenceAcknowledgement.class);
    List<AcknowledgementRange> ranges = new ArrayList<>();
    AcknowledgementRange r = control.createMock(AcknowledgementRange.class);
    EasyMock.expect(ack.getAcknowledgementRange()).andReturn(ranges);
    config.setDeliveryAssurance(DeliveryAssurance.AT_MOST_ONCE);
    control.replay();
    DestinationSequence ds = new DestinationSequence(id, ref, 0, ack, ProtocolVariation.RM10WSA200408);
    ds.setDestination(destination);
    ds.applyDeliveryAssurance(mn, null);
    control.verify();
    control.reset();
    ranges.add(r);
    EasyMock.expect(destination.getReliableEndpoint()).andReturn(endpoint);
    EasyMock.expect(endpoint.getConfiguration()).andReturn(config).anyTimes();
    EasyMock.expect(ack.getAcknowledgementRange()).andReturn(ranges);
    EasyMock.expect(r.getLower()).andReturn(new Long(5));
    EasyMock.expect(r.getUpper()).andReturn(new Long(15));
    control.replay();
    ds.applyDeliveryAssurance(mn, null);
    control.verify();
}
Also used : ArrayList(java.util.ArrayList) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) Test(org.junit.Test)

Example 33 with SequenceAcknowledgement

use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement in project cxf by apache.

the class SourceSequenceTest method testSetAcknowledged.

@Test
public void testSetAcknowledged() throws RMException {
    SourceSequence seq = new SourceSequence(id, ProtocolVariation.RM10WSA200408);
    setUpSource();
    seq.setSource(source);
    SequenceAcknowledgement ack = seq.getAcknowledgement();
    ack = factory.createSequenceAcknowledgement();
    SequenceAcknowledgement.AcknowledgementRange r = factory.createSequenceAcknowledgementAcknowledgementRange();
    r.setLower(new Long(1));
    r.setUpper(new Long(2));
    ack.getAcknowledgementRange().add(r);
    r = factory.createSequenceAcknowledgementAcknowledgementRange();
    r.setLower(new Long(4));
    r.setUpper(new Long(6));
    ack.getAcknowledgementRange().add(r);
    r = factory.createSequenceAcknowledgementAcknowledgementRange();
    r.setLower(new Long(8));
    r.setUpper(new Long(10));
    ack.getAcknowledgementRange().add(r);
    rq.purgeAcknowledged(seq);
    EasyMock.expectLastCall();
    control.replay();
    seq.setAcknowledged(ack);
    assertSame(ack, seq.getAcknowledgement());
    assertEquals(3, ack.getAcknowledgementRange().size());
    assertTrue(!seq.isAcknowledged(3));
    assertTrue(seq.isAcknowledged(5));
    control.verify();
}
Also used : SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) Test(org.junit.Test)

Example 34 with SequenceAcknowledgement

use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement in project cxf by apache.

the class SourceSequenceTest method testAllAcknowledged.

@Test
public void testAllAcknowledged() throws RMException {
    SourceSequence seq = new SourceSequence(id, null, null, 4, false, ProtocolVariation.RM10WSA200408);
    setUpSource();
    seq.setSource(source);
    assertTrue(!seq.allAcknowledged());
    seq.setLastMessage(true);
    assertTrue(!seq.allAcknowledged());
    SequenceAcknowledgement ack = factory.createSequenceAcknowledgement();
    SequenceAcknowledgement.AcknowledgementRange r = factory.createSequenceAcknowledgementAcknowledgementRange();
    r.setLower(new Long(1));
    r.setUpper(new Long(2));
    ack.getAcknowledgementRange().add(r);
    rq.purgeAcknowledged(seq);
    EasyMock.expectLastCall();
    control.replay();
    seq.setAcknowledged(ack);
    assertTrue(!seq.allAcknowledged());
    r.setUpper(new Long(4));
    assertTrue(seq.allAcknowledged());
    control.verify();
}
Also used : SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) Test(org.junit.Test)

Aggregations

SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)33 Test (org.junit.Test)11 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)10 ArrayList (java.util.ArrayList)6 AckRequestedType (org.apache.cxf.ws.rm.v200702.AckRequestedType)6 AcknowledgementRange (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)5 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)5 Element (org.w3c.dom.Element)5 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)4 CloseSequenceType (org.apache.cxf.ws.rm.v200702.CloseSequenceType)4 CreateSequenceType (org.apache.cxf.ws.rm.v200702.CreateSequenceType)4 TerminateSequenceType (org.apache.cxf.ws.rm.v200702.TerminateSequenceType)4 InputStream (java.io.InputStream)3 Connection (java.sql.Connection)3 JAXBElement (javax.xml.bind.JAXBElement)3 QName (javax.xml.namespace.QName)3 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)3 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)3 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)3 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)3