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