Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-2518

Resequencer With Custom Comparator Does Not Release Properly

    Details

      Description

      The ResequencingMessageGroupProcessor allows a custom Comparator to sort the messages in the group. However, the processMessageGroup() method still uses the sequenceNumber header to decide what can be released.

      The messages are sorted in some arbitrary order and then we release the partial group based on the sequence number...

      currentSequence = extractSequenceNumber(message);
      if (currentSequence - 1 > previousSequence) {
          //there is a gap in the sequence here
          break;
      }

      Well, it is very likely there will be a gap because the messages aren't sorted by sequenceNumber.

      It seems to me that, if we allow a custom comparator, we must also allow a custom expression to invoke in extractSequenceNumber (or provide some other mechanism to assess what can be released).

      I modified one of the test cases to show this problem

       
      @Test
      public void testBasicResequencingWithCustomComparator() throws InterruptedException {
      	this.processor.setComparator(new Comparator<Message<?>>() {			
      		@SuppressWarnings({ "unchecked", "rawtypes" })
      		public int compare(Message<?> o1, Message<?> o2) {
      			return ((Comparable)o1.getPayload()).compareTo(o2.getPayload());
      		}
      	});
      	QueueChannel replyChannel = new QueueChannel();
      	Message<?> message1 = createMessage("789", "ABC", 4, 1, replyChannel);
      	Message<?> message2 = createMessage("123", "ABC", 4, 4, replyChannel);
      	Message<?> message3 = createMessage("456", "ABC", 4, 3, replyChannel);
      	Message<?> message4 = createMessage("111", "ABC", 4, 2, replyChannel);		
      	this.resequencer.handleMessage(message1);
      	this.resequencer.handleMessage(message3);
      	this.resequencer.handleMessage(message2);
      	this.resequencer.handleMessage(message4);		
      	Message<?> reply0 = replyChannel.receive(0);
      	Message<?> reply1 = replyChannel.receive(0);
      	Message<?> reply2 = replyChannel.receive(0);
      	Message<?> reply3 = replyChannel.receive(0);
      	assertNotNull(reply0);
      	assertEquals(new Integer(2), reply0.getHeaders().getSequenceNumber());
      	assertNotNull(reply1);
      	assertEquals(new Integer(4), reply1.getHeaders().getSequenceNumber());
      	assertNotNull(reply2);
      	assertEquals(new Integer(3), reply2.getHeaders().getSequenceNumber());
      	assertNotNull(reply3);
      	assertEquals(new Integer(1), reply3.getHeaders().getSequenceNumber());
      }

      Only the first message (message4) is released, even though the full "set" of 4 messages are complete in that sequences 1, 2, 3, 4 are all present.

        Issue Links

          Activity

          grussell Gary Russell created issue -
          mark.fisher Mark Fisher made changes -
          Field Original Value New Value
          Assignee Mark Fisher [ mark.fisher ] Gary Russell [ grussell ]
          Fix Version/s 2.1.2 [ 12835 ]
          Fix Version/s 2.2 Backlog [ 12807 ]
          mark.fisher Mark Fisher made changes -
          Assignee Gary Russell [ grussell ] Oleg Zhurakousky [ [email protected] ]
          oleg.zhurakousky@springsource.com Oleg Zhurakousky made changes -
          Fix Version/s 2.2 Backlog [ 12807 ]
          Fix Version/s 2.2 M3 Sprint 1 [ 12813 ]
          oleg.zhurakousky@springsource.com Oleg Zhurakousky made changes -
          Remaining Estimate 0.25d [ 7200 ]
          Original Estimate 0.25d [ 7200 ]
          oleg.zhurakousky@springsource.com Oleg Zhurakousky made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          oleg.zhurakousky@springsource.com Oleg Zhurakousky made changes -
          Worklog Id 28818 [ 28818 ]
          Remaining Estimate 0.25d [ 7200 ] 0d [ 0 ]
          Time Spent 0.25d [ 7200 ]
          oleg.zhurakousky@springsource.com Oleg Zhurakousky made changes -
          Labels pull-request-submitted
          grussell Gary Russell made changes -
          Resolution Complete [ 8 ]
          Status In Progress [ 3 ] Resolved [ 5 ]
          grussell Gary Russell made changes -
          Link This issue is related to INT-2624 [ INT-2624 ]
          grussell Gary Russell made changes -
          Fix Version/s 2.2 M3 [ 13000 ]
          grussell Gary Russell made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          abilan Artem Bilan made changes -
          Link This issue is related to INT-3317 [ INT-3317 ]

            People

            • Assignee:
              oleg.zhurakousky@springsource.com Oleg Zhurakousky
              Reporter:
              grussell Gary Russell
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0.25d
                0.25d
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 0.25d
                0.25d