This is an automated email from the ASF dual-hosted git repository. buhhunyx pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push: new de3d4bf [cxf-rt-ws-rm] improve test stability de3d4bf is described below commit de3d4bfecc0664cb5f68f1ebb1ad7ca656229706 Author: amarkevich <amarkev...@talend.com> AuthorDate: Tue Mar 12 11:02:09 2019 +0300 [cxf-rt-ws-rm] improve test stability --- .../org/apache/cxf/ws/rm/DestinationSequence.java | 10 ++-- .../java/org/apache/cxf/ws/rm/SequenceMonitor.java | 25 ++++------ .../apache/cxf/ws/rm/DestinationSequenceTest.java | 58 ++++++++-------------- 3 files changed, 36 insertions(+), 57 deletions(-) diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/DestinationSequence.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/DestinationSequence.java index cd3f224..59b59fa 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/DestinationSequence.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/DestinationSequence.java @@ -128,9 +128,9 @@ public class DestinationSequence extends AbstractSequence { public void acknowledge(Message message) throws SequenceFault { RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false); SequenceType st = rmps.getSequence(); - long messageNumber = st.getMessageNumber().longValue(); + long messageNumber = st.getMessageNumber(); LOG.fine("Acknowledging message: " + messageNumber); - if (0 != lastMessageNumber && messageNumber > lastMessageNumber) { + if (0L != lastMessageNumber && messageNumber > lastMessageNumber) { RMConstants consts = getProtocol().getConstants(); SequenceFaultFactory sff = new SequenceFaultFactory(consts); throw sff.createSequenceTerminatedFault(st.getIdentifier(), false); @@ -150,13 +150,13 @@ public class DestinationSequence extends AbstractSequence { break; } long diff = r.getLower() - messageNumber; - if (diff == 1) { + if (diff == 1L) { r.setLower(messageNumber); updated = true; done = true; - } else if (diff > 0) { + } else if (diff > 0L) { break; - } else if (messageNumber - r.getUpper().longValue() == 1) { + } else if (messageNumber - r.getUpper() == 1L) { r.setUpper(messageNumber); updated = true; done = true; diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/SequenceMonitor.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/SequenceMonitor.java index 03f6eaf..330a9ce 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/SequenceMonitor.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/SequenceMonitor.java @@ -19,8 +19,8 @@ package org.apache.cxf.ws.rm; -import java.util.ArrayList; -import java.util.List; +import java.util.Deque; +import java.util.concurrent.ConcurrentLinkedDeque; import java.util.logging.Logger; import org.apache.cxf.common.logging.LogUtils; @@ -31,24 +31,24 @@ public class SequenceMonitor { private static final Logger LOG = LogUtils.getL7dLogger(SequenceMonitor.class); private long monitorInterval = DEFAULT_MONITOR_INTERVAL; private long firstCheck; - private List<Long> receiveTimes = new ArrayList<>(); + private final Deque<Long> receiveTimes = new ConcurrentLinkedDeque<>(); public void acknowledgeMessage() { long now = System.currentTimeMillis(); - if (0 == firstCheck) { + if (0L == firstCheck) { firstCheck = now + monitorInterval; } - receiveTimes.add(Long.valueOf(now)); + receiveTimes.add(now); } public int getMPM() { long now = System.currentTimeMillis(); int mpm = 0; - if (firstCheck > 0 && now >= firstCheck) { + if (firstCheck > 0L && now >= firstCheck) { long threshold = now - monitorInterval; while (!receiveTimes.isEmpty()) { - if (receiveTimes.get(0).longValue() <= threshold) { - receiveTimes.remove(0); + if (receiveTimes.getFirst() <= threshold) { + receiveTimes.removeFirst(); } else { break; } @@ -59,16 +59,13 @@ public class SequenceMonitor { return mpm; } - public synchronized long getLastArrivalTime() { - if (!receiveTimes.isEmpty()) { - return receiveTimes.get(receiveTimes.size() - 1).longValue(); - } - return 0; + public long getLastArrivalTime() { + return !receiveTimes.isEmpty() ? receiveTimes.getLast() : 0L; } protected void setMonitorInterval(long i) { if (receiveTimes.isEmpty()) { - firstCheck = 0; + firstCheck = 0L; monitorInterval = i; } else { LOG.warning("Cannot change monitor interval at this point."); diff --git a/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/DestinationSequenceTest.java b/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/DestinationSequenceTest.java index 69fe902..32e53bb 100644 --- a/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/DestinationSequenceTest.java +++ b/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/DestinationSequenceTest.java @@ -47,6 +47,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; @@ -95,15 +96,15 @@ public class DestinationSequenceTest { DestinationSequence seq = new DestinationSequence(id, ref, destination, ProtocolVariation.RM10WSA200408); assertEquals(id, seq.getIdentifier()); - assertEquals(0, seq.getLastMessageNumber()); + assertEquals(0L, seq.getLastMessageNumber()); assertSame(ref, seq.getAcksTo()); assertNotNull(seq.getAcknowledgment()); assertNotNull(seq.getMonitor()); SequenceAcknowledgement ack = new SequenceAcknowledgement(); - seq = new DestinationSequence(id, ref, 10, ack, ProtocolVariation.RM10WSA200408); + seq = new DestinationSequence(id, ref, 10L, ack, ProtocolVariation.RM10WSA200408); assertEquals(id, seq.getIdentifier()); - assertEquals(10, seq.getLastMessageNumber()); + assertEquals(10L, seq.getLastMessageNumber()); assertSame(ref, seq.getAcksTo()); assertSame(ack, seq.getAcknowledgment()); assertNotNull(seq.getMonitor()); @@ -124,7 +125,7 @@ public class DestinationSequenceTest { otherId.setValue("otherSeq"); otherSeq = new DestinationSequence(otherId, ref, destination, ProtocolVariation.RM10WSA200408); assertFalse(seq.equals(otherSeq)); - assertTrue(seq.hashCode() != otherSeq.hashCode()); + assertNotEquals(seq.hashCode(), otherSeq.hashCode()); } @Test @@ -345,7 +346,7 @@ public class DestinationSequenceTest { } @Test - public void testMonitor() throws SequenceFault { + public void testMonitor() throws SequenceFault, InterruptedException { Timer timer = control.createMock(Timer.class); setUpDestination(timer, null); Message[] messages = new Message[15]; @@ -358,28 +359,20 @@ public class DestinationSequenceTest { ProtocolVariation.RM10WSA200408); SequenceMonitor monitor = seq.getMonitor(); assertNotNull(monitor); - monitor.setMonitorInterval(500); + monitor.setMonitorInterval(500L); assertEquals(0, monitor.getMPM()); for (int i = 0; i < 10; i++) { seq.acknowledge(messages[i]); - try { - Thread.sleep(55); - } catch (InterruptedException ex) { - // ignore - } + Thread.sleep(55L); } int mpm1 = monitor.getMPM(); assertTrue("unexpected MPM: " + mpm1, mpm1 > 0); for (int i = 10; i < messages.length; i++) { seq.acknowledge(messages[i]); - try { - Thread.sleep(110); - } catch (InterruptedException ex) { - // ignore - } + Thread.sleep(110L); } int mpm2 = monitor.getMPM(); assertTrue(mpm2 > 0); @@ -409,7 +402,7 @@ public class DestinationSequenceTest { } @Test - public void testAcknowledgeDeferred() throws SequenceFault, RMException { + public void testAcknowledgeDeferred() throws SequenceFault, RMException, InterruptedException { Timer timer = new Timer(); RMEndpoint rme = control.createMock(RMEndpoint.class); setUpDestination(timer, rme); @@ -429,7 +422,7 @@ public class DestinationSequenceTest { control.replay(); ap.setIntraMessageThreshold(0); - config.setAcknowledgementInterval(Long.valueOf(200)); + config.setAcknowledgementInterval(200L); assertFalse(seq.sendAcknowledgement()); @@ -439,11 +432,8 @@ public class DestinationSequenceTest { assertFalse(seq.sendAcknowledgement()); - try { - Thread.sleep(250); - } catch (InterruptedException ex) { - // ignore - } + Thread.sleep(250L); + assertTrue(seq.sendAcknowledgement()); seq.acknowledgmentSent(); assertFalse(seq.sendAcknowledgement()); @@ -495,7 +485,7 @@ public class DestinationSequenceTest { } @Test - public void testInOrderWait() { + public void testInOrderWait() throws InterruptedException { setUpDestination(); Message[] messages = new Message[5]; for (int i = 0; i < messages.length; i++) { @@ -540,17 +530,13 @@ public class DestinationSequenceTest { 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 - } + Thread.sleep(100L); } boolean timedOut = false; for (int i = 0; i < messages.length; i++) { try { - threads[i].join(1000); + threads[i].join(1000L); } catch (InterruptedException ex) { timedOut = true; } @@ -564,7 +550,7 @@ public class DestinationSequenceTest { } @Test - public void testScheduleSequenceTermination() throws SequenceFault { + public void testScheduleSequenceTermination() throws SequenceFault, InterruptedException { Timer timer = new Timer(); RMEndpoint rme = control.createMock(RMEndpoint.class); EasyMock.expect(rme.getProxy()).andReturn(control.createMock(Proxy.class)).anyTimes(); @@ -581,15 +567,11 @@ public class DestinationSequenceTest { EasyMock.expect(rme.getLastApplicationMessage()).andReturn(arrival); control.replay(); - config.setInactivityTimeout(Long.valueOf(200)); + config.setInactivityTimeout(200L); seq.acknowledge(message); - try { - Thread.sleep(250); - } catch (InterruptedException ex) { - // ignore - } + Thread.sleep(250L); control.verify(); } @@ -720,7 +702,7 @@ public class DestinationSequenceTest { dp.setAcksPolicy(ap); config = new RMConfiguration(); - config.setBaseRetransmissionInterval(Long.valueOf(3000)); + config.setBaseRetransmissionInterval(3000L); EasyMock.expect(manager.getConfiguration()).andReturn(config).anyTimes(); endpoint = rme; if (endpoint == null) {