Search in sources :

Example 11 with AcknowledgementRange

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

the class ManagedRMEndpoint method getDestinationSequenceAcknowledgedRange.

@ManagedOperation(description = "Destination Sequence Acknowledged Range")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "sequenceId", description = "The sequence identifier") })
public Long[] getDestinationSequenceAcknowledgedRange(String sid) {
    DestinationSequence ds = getDestinationSeq(sid);
    if (null == ds) {
        throw new IllegalArgumentException("no sequence");
    }
    List<Long> list = new ArrayList<>();
    for (AcknowledgementRange r : ds.getAcknowledgment().getAcknowledgementRange()) {
        list.add(r.getLower());
        list.add(r.getUpper());
    }
    return list.toArray(new Long[list.size()]);
}
Also used : ArrayList(java.util.ArrayList) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) ManagedOperationParameters(org.apache.cxf.management.annotation.ManagedOperationParameters) ManagedOperation(org.apache.cxf.management.annotation.ManagedOperation)

Example 12 with AcknowledgementRange

use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange 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 13 with AcknowledgementRange

use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange 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 14 with AcknowledgementRange

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

the class DestinationSequenceTest method testMerge.

@Test
public void testMerge() {
    DestinationSequence seq = new DestinationSequence(id, ref, destination, ProtocolVariation.RM10WSA200408);
    List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange();
    AcknowledgementRange r;
    for (int i = 0; i < 5; i++) {
        r = new AcknowledgementRange();
        r.setLower(new Long(3 * i + 1));
        r.setUpper(new Long(3 * i + 3));
        ranges.add(r);
    }
    seq.mergeRanges();
    assertEquals(1, ranges.size());
    r = ranges.get(0);
    assertEquals(new Long(1), r.getLower());
    assertEquals(new Long(15), r.getUpper());
    ranges.clear();
    for (int i = 0; i < 5; i++) {
        r = new AcknowledgementRange();
        r.setLower(new Long(3 * i + 1));
        r.setUpper(new Long(3 * i + 2));
        ranges.add(r);
    }
    seq.mergeRanges();
    assertEquals(5, ranges.size());
    ranges.clear();
    for (int i = 0; i < 5; i++) {
        if (i != 2) {
            r = new AcknowledgementRange();
            r.setLower(new Long(3 * i + 1));
            r.setUpper(new Long(3 * i + 3));
            ranges.add(r);
        }
    }
    seq.mergeRanges();
    assertEquals(2, ranges.size());
    r = ranges.get(0);
    assertEquals(new Long(1), r.getLower());
    assertEquals(new Long(6), r.getUpper());
    r = ranges.get(1);
    assertEquals(new Long(10), r.getLower());
    assertEquals(new Long(15), r.getUpper());
}
Also used : AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) Test(org.junit.Test)

Aggregations

AcknowledgementRange (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)14 Test (org.junit.Test)10 Message (org.apache.cxf.message.Message)5 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)5 ArrayList (java.util.ArrayList)4 Timer (java.util.Timer)4 InputStream (java.io.InputStream)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 ManagedOperation (org.apache.cxf.management.annotation.ManagedOperation)2 ManagedOperationParameters (org.apache.cxf.management.annotation.ManagedOperationParameters)2 RMProperties (org.apache.cxf.ws.rm.RMProperties)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Fault (org.apache.cxf.interceptor.Fault)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)1 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)1 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)1