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()]);
}
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();
}
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();
}
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());
}
Aggregations