INT-2265
fixed GemfireGroupStoreTests.testMultipleInstancesOfGroupStore() test to avoid intermittent failures refactored MessageGroupMetadata to eliminate the usage of TreeMap in favor of LinkedList for storing UUIDs of Messages
This commit is contained in:
committed by
Mark Fisher
parent
91b0f46c44
commit
3f6896677f
@@ -18,8 +18,8 @@ package org.springframework.integration.store;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
@@ -35,11 +35,9 @@ public class MessageGroupMetadata implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static String CREATED_DATE = "CREATED_DATE";
|
||||
|
||||
private final Object groupId;
|
||||
|
||||
private final TreeMap<Long, UUID> messageCreationDateToIdMappings;
|
||||
|
||||
private final List<UUID> messageIds = new LinkedList<UUID>();
|
||||
|
||||
private final boolean complete;
|
||||
|
||||
@@ -53,12 +51,8 @@ public class MessageGroupMetadata implements Serializable{
|
||||
|
||||
Assert.notNull(messageGroup, "'messageGroup' must not be null");
|
||||
this.groupId = messageGroup.getGroupId();
|
||||
this.messageCreationDateToIdMappings = new TreeMap<Long, UUID>();
|
||||
|
||||
for (Message<?> message : messageGroup.getMessages()) {
|
||||
Long createdDate = (Long) message.getHeaders().get(CREATED_DATE);
|
||||
Assert.notNull(createdDate > 0, CREATED_DATE + " must not be null");
|
||||
this.messageCreationDateToIdMappings.put(createdDate, message.getHeaders().getId());
|
||||
this.messageIds.add(message.getHeaders().getId());
|
||||
}
|
||||
this.complete = messageGroup.isComplete();
|
||||
this.timestamp = messageGroup.getTimestamp();
|
||||
@@ -67,14 +61,7 @@ public class MessageGroupMetadata implements Serializable{
|
||||
}
|
||||
|
||||
public void remove(UUID messageId){
|
||||
long currentTimestamp = 0;
|
||||
for (Entry<Long, UUID> entry : messageCreationDateToIdMappings.entrySet()) {
|
||||
if (entry.getValue().equals(messageId)){
|
||||
currentTimestamp = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.messageCreationDateToIdMappings.remove(currentTimestamp);
|
||||
this.messageIds.remove(messageId);
|
||||
}
|
||||
|
||||
public void setLastModified(long lastModified) {
|
||||
@@ -86,14 +73,14 @@ public class MessageGroupMetadata implements Serializable{
|
||||
}
|
||||
|
||||
public Iterator<UUID> messageIdIterator(){
|
||||
return this.messageCreationDateToIdMappings.values().iterator();
|
||||
return this.messageIds.iterator();
|
||||
}
|
||||
|
||||
public UUID firstId(){
|
||||
Entry<Long, UUID> firstEntry = messageCreationDateToIdMappings.firstEntry();
|
||||
if (firstEntry != null){
|
||||
return firstEntry.getValue();
|
||||
if (this.messageIds.size() > 0){
|
||||
return this.messageIds.iterator().next();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -112,5 +99,4 @@ public class MessageGroupMetadata implements Serializable{
|
||||
public int getLastReleasedMessageSequenceNumber() {
|
||||
return this.lastReleasedMessageSequenceNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.integration.Message;
|
||||
|
||||
Reference in New Issue
Block a user