INT-4123: Add Prefix to the Key-Value MSs

Fixes spring-projects/spring-integration#2213
JIRA: https://jira.spring.io/browse/INT-4123

Fully different `MessageStore`s can be configured for the same shared
Key-Value data-base.
Since the retrieval logic is based on the keys, that may cause the
unexpected messages expiration via `MessageGroupStoreReaper`.

* To distinguish store instances on the shared store add `prefix`
option to the `AbstractKeyValueMessageStore`

* Deprecate the `GemfireMessageStore` `Cache`-based configuration - `setIgnoreJta()` and `afterPropertiesSet()`.
The `GemfireMessageStore` relies only on an externally configured `Region`.

**Cherry-pick to 4.3.x**

Doc Polishing
This commit is contained in:
Artem Bilan
2017-09-05 18:23:03 -04:00
committed by Gary Russell
parent df55ac95d8
commit 5263ea6dff
8 changed files with 176 additions and 111 deletions

View File

@@ -69,7 +69,6 @@ public class GemfireGroupStoreTests {
@Test
public void testNonExistingEmptyMessageGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
assertNotNull(messageGroup);
assertTrue(messageGroup instanceof SimpleMessageGroup);
@@ -79,7 +78,6 @@ public class GemfireGroupStoreTests {
@Test
public void testMessageGroupWithAddedMessage() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
messageGroup = store.addMessageToGroup(1, message);
@@ -87,7 +85,6 @@ public class GemfireGroupStoreTests {
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
store.afterPropertiesSet();
messageGroup = store.getMessageGroup(1);
assertEquals(1, messageGroup.size());
@@ -96,7 +93,6 @@ public class GemfireGroupStoreTests {
@Test
public void testRemoveMessageFromTheGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("2");
@@ -121,7 +117,6 @@ public class GemfireGroupStoreTests {
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
store.afterPropertiesSet();
messageGroup = store.getMessageGroup(1);
assertEquals(2, messageGroup.size());
@@ -131,7 +126,6 @@ public class GemfireGroupStoreTests {
@Test
public void testRemoveMessageGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
@@ -145,7 +139,6 @@ public class GemfireGroupStoreTests {
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
store.afterPropertiesSet();
messageGroup = store.getMessageGroup(1);
@@ -156,7 +149,6 @@ public class GemfireGroupStoreTests {
@Test
public void testRemoveNonExistingMessageFromTheGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
store.addMessagesToGroup(messageGroup.getGroupId(), new GenericMessage<String>("1"));
store.removeMessagesFromGroup(1, new GenericMessage<String>("2"));
@@ -165,14 +157,12 @@ public class GemfireGroupStoreTests {
@Test
public void testRemoveNonExistingMessageFromNonExistingTheGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
store.removeMessagesFromGroup(1, new GenericMessage<String>("2"));
}
@Test
public void testCompleteMessageGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> messageToMark = new GenericMessage<String>("1");
store.addMessagesToGroup(messageGroup.getGroupId(), messageToMark);
@@ -184,7 +174,6 @@ public class GemfireGroupStoreTests {
@Test
public void testLastReleasedSequenceNumber() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> messageToMark = new GenericMessage<String>("1");
store.addMessagesToGroup(messageGroup.getGroupId(), messageToMark);
@@ -196,10 +185,8 @@ public class GemfireGroupStoreTests {
@Test
public void testMultipleInstancesOfGroupStore() throws Exception {
GemfireMessageStore store1 = new GemfireMessageStore(region);
store1.afterPropertiesSet();
GemfireMessageStore store2 = new GemfireMessageStore(region);
store2.afterPropertiesSet();
Message<?> message = new GenericMessage<String>("1");
store1.addMessagesToGroup(1, message);
@@ -208,7 +195,6 @@ public class GemfireGroupStoreTests {
assertEquals(2, messageGroup.getMessages().size());
GemfireMessageStore store3 = new GemfireMessageStore(region);
store3.afterPropertiesSet();
store3.removeMessagesFromGroup(1, message);
messageGroup = store3.getMessageGroup(1);
@@ -219,7 +205,6 @@ public class GemfireGroupStoreTests {
@Test
public void testWithMessageHistory() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
store.getMessageGroup(1);
@@ -246,9 +231,7 @@ public class GemfireGroupStoreTests {
@Test
public void testIteratorOfMessageGroups() throws Exception {
GemfireMessageStore store1 = new GemfireMessageStore(region);
store1.afterPropertiesSet();
GemfireMessageStore store2 = new GemfireMessageStore(region);
store2.afterPropertiesSet();
store1.addMessagesToGroup(1, new GenericMessage<String>("1"));
store2.addMessagesToGroup(2, new GenericMessage<String>("2"));
@@ -278,9 +261,7 @@ public class GemfireGroupStoreTests {
public void testConcurrentModifications() throws Exception {
final GemfireMessageStore store1 = new GemfireMessageStore(region);
store1.afterPropertiesSet();
final GemfireMessageStore store2 = new GemfireMessageStore(region);
store2.afterPropertiesSet();
final Message<?> message = new GenericMessage<String>("1");

View File

@@ -37,6 +37,7 @@ import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.store.MessageGroupMetadata;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
@@ -58,8 +59,6 @@ public class GemfireMessageStoreTests {
@Test
public void addAndGetMessage() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
Message<?> message = MessageBuilder.withPayload("test").build();
store.addMessage(message);
Message<?> retrieved = store.getMessage(message.getHeaders().getId());
@@ -76,7 +75,6 @@ public class GemfireMessageStoreTests {
region.afterPropertiesSet();
GemfireMessageStore store = new GemfireMessageStore(region.getObject());
store.afterPropertiesSet();
assertSame(region.getObject(), TestUtils.getPropertyValue(store, "messageStoreRegion"));
region.destroy();
@@ -85,7 +83,6 @@ public class GemfireMessageStoreTests {
@Test
public void testWithMessageHistory() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
store.afterPropertiesSet();
Message<?> message = new GenericMessage<String>("Hello");
DirectChannel fooChannel = new DirectChannel();
@@ -108,7 +105,6 @@ public class GemfireMessageStoreTests {
@Test
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
GemfireMessageStore messageStore = new GemfireMessageStore(region);
messageStore.afterPropertiesSet();
String groupId = "X";
List<Message<?>> messages = new ArrayList<Message<?>>();
@@ -124,6 +120,29 @@ public class GemfireMessageStoreTests {
assertEquals(0, group.size());
}
@Test
public void testAddAndRemoveMessagesFromMessageGroupWithPrefix() throws Exception {
GemfireMessageStore messageStore = new GemfireMessageStore(region, "foo_");
String groupId = "X";
List<Message<?>> messages = new ArrayList<Message<?>>();
for (int i = 0; i < 25; i++) {
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
messages.add(message);
}
MessageGroupMetadata messageGroupMetadata =
(MessageGroupMetadata) region.get("foo_" + "MESSAGE_GROUP_" + groupId);
assertNotNull(messageGroupMetadata);
assertEquals(25, messageGroupMetadata.size());
messageStore.removeMessagesFromGroup(groupId, messages);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
}
@Before
public void prepare() {
if (region != null) {