GH-248: Use keySet() for HazelcastMS to list keys
Fixes https://github.com/spring-projects/spring-integration-extensions/issues/248 The `HazelcastMessageStore.doListKeys()` uses `this.map.values()` by mistake. * Fix `HazelcastMessageStore.doListKeys()` to use a `keySet()` for a proper filtering and result inferring * Add unit test to cover an iteration functionality for message groups in the store
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
* Copyright 2017-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,8 +23,8 @@ import org.springframework.util.Assert;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.map.IMap;
|
||||
import com.hazelcast.query.Predicate;
|
||||
import com.hazelcast.query.impl.predicates.SqlPredicate;
|
||||
import com.hazelcast.query.Predicates;
|
||||
import com.hazelcast.query.QueryConstants;
|
||||
|
||||
/**
|
||||
* The Hazelcast {@link IMap}-based {@link AbstractKeyValueMessageStore} implementation.
|
||||
@@ -77,9 +77,7 @@ public class HazelcastMessageStore extends AbstractKeyValueMessageStore {
|
||||
protected Collection<?> doListKeys(String keyPattern) {
|
||||
Assert.hasText(keyPattern, "'keyPattern' must not be empty");
|
||||
keyPattern = keyPattern.replaceAll("\\*", "%");
|
||||
@SuppressWarnings("unchecked")
|
||||
Predicate<Object, Object> sqlPredicate = new SqlPredicate("__key like " + keyPattern);
|
||||
return this.map.values(sqlPredicate);
|
||||
return this.map.keySet(Predicates.like(QueryConstants.KEY_ATTRIBUTE_NAME.value(), keyPattern));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2020 the original author or authors.
|
||||
* Copyright 2017-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -132,4 +132,18 @@ public class HazelcastMessageStoreTests {
|
||||
assertThat(size).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageStoreIterator() {
|
||||
Message<?> message1 = MessageBuilder.withPayload("test").build();
|
||||
Message<?> message2 = MessageBuilder.withPayload("test").build();
|
||||
store.addMessageToGroup("test", message1);
|
||||
store.addMessageToGroup("test", message2);
|
||||
int groupCount = 0;
|
||||
for (MessageGroup messageGroup : store) {
|
||||
assertThat(messageGroup.size()).isEqualTo(2);
|
||||
groupCount++;
|
||||
}
|
||||
assertThat(groupCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user