use of org.springframework.data.redis.core.ZSetOperations.TypedTuple in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithMapPayloadPojoParsedHeaderKey.
@Test
@RedisAvailable
public void testZsetWithMapPayloadPojoParsedHeaderKey() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deletePresidents(jcf);
String key = "presidents";
RedisZSet<President> redisZset = new DefaultRedisZSet<President>(key, this.initTemplate(jcf, new RedisTemplate<String, President>()));
assertEquals(0, redisZset.size());
RedisTemplate<String, President> template = this.initTemplate(jcf, new RedisTemplate<String, President>());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
handler.setKey(key);
handler.setCollectionType(CollectionType.ZSET);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Map<President, Double> presidents = new HashMap<President, Double>();
presidents.put(new President("John Adams"), 18D);
presidents.put(new President("Barack Obama"), 21D);
presidents.put(new President("Thomas Jefferson"), 19D);
presidents.put(new President("John Quincy Adams"), 19D);
presidents.put(new President("Zachary Taylor"), 19D);
presidents.put(new President("Theodore Roosevelt"), 20D);
presidents.put(new President("Woodrow Wilson"), 20D);
presidents.put(new President("George W. Bush"), 21D);
presidents.put(new President("Franklin D. Roosevelt"), 20D);
presidents.put(new President("Ronald Reagan"), 20D);
presidents.put(new President("William J. Clinton"), 20D);
presidents.put(new President("Abraham Lincoln"), 19D);
presidents.put(new President("George Washington"), 18D);
Message<Map<President, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
handler.handleMessage(message);
assertEquals(13, redisZset.size());
Set<TypedTuple<President>> entries = redisZset.rangeByScoreWithScores(18, 19);
assertEquals(6, entries.size());
this.deletePresidents(jcf);
}
use of org.springframework.data.redis.core.ZSetOperations.TypedTuple in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadAsSingleEntryAndHeaderKeyHeaderScore.
@Test
@RedisAvailable
public void testZsetWithListPayloadAsSingleEntryAndHeaderKeyHeaderScore() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisZSet<List<String>> redisZset = new DefaultRedisZSet<List<String>>(key, this.initTemplate(jcf, new RedisTemplate<String, List<String>>()));
assertEquals(0, redisZset.size());
RedisTemplate<String, List<String>> template = this.initTemplate(jcf, new RedisTemplate<String, List<String>>());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
handler.setCollectionType(CollectionType.ZSET);
handler.setExtractPayloadElements(false);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = MessageBuilder.withPayload(list).setHeader("redis_key", key).setHeader("redis_zsetScore", 4).build();
handler.handleMessage(message);
assertEquals(1, redisZset.size());
Set<TypedTuple<List<String>>> entries = redisZset.rangeByScoreWithScores(1, 4);
for (TypedTuple<List<String>> pepboys : entries) {
assertTrue(pepboys.getScore() == 4);
}
this.deleteKey(jcf, "foo");
}
use of org.springframework.data.redis.core.ZSetOperations.TypedTuple in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadParsedAndProvidedKeyScoreIncrementAsStringHeader.
@Test
@RedisAvailable
public void testZsetWithListPayloadParsedAndProvidedKeyScoreIncrementAsStringHeader() {
// see INT-2775
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisZSet<String> redisZset = new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
assertEquals(0, redisZset.size());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setCollectionType(CollectionType.ZSET);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = MessageBuilder.withPayload(list).setHeader(RedisHeaders.ZSET_INCREMENT_SCORE, "true").build();
handler.handleMessage(message);
assertEquals(3, redisZset.size());
Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
for (TypedTuple<String> pepboy : pepboys) {
assertTrue(pepboy.getScore() == 1);
}
handler.handleMessage(message);
assertEquals(3, redisZset.size());
pepboys = redisZset.rangeByScoreWithScores(1, 2);
// should have incremented
for (TypedTuple<String> pepboy : pepboys) {
assertTrue(pepboy.getScore() == 2);
}
this.deleteKey(jcf, "foo");
}
use of org.springframework.data.redis.core.ZSetOperations.TypedTuple in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithMapPayloadParsedHeaderKey.
@Test
@RedisAvailable
public void testZsetWithMapPayloadParsedHeaderKey() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deletePresidents(jcf);
String key = "presidents";
RedisZSet<String> redisZset = new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
assertEquals(0, redisZset.size());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setCollectionType(CollectionType.ZSET);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Map<String, Double> presidents = new HashMap<String, Double>();
presidents.put("John Adams", 18D);
presidents.put("Barack Obama", 21D);
presidents.put("Thomas Jefferson", 19D);
presidents.put("John Quincy Adams", 19D);
presidents.put("Zachary Taylor", 19D);
presidents.put("Theodore Roosevelt", 20D);
presidents.put("Woodrow Wilson", 20D);
presidents.put("George W. Bush", 21D);
presidents.put("Franklin D. Roosevelt", 20D);
presidents.put("Ronald Reagan", 20D);
presidents.put("William J. Clinton", 20D);
presidents.put("Abraham Lincoln", 19D);
presidents.put("George Washington", 18D);
Message<Map<String, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
handler.handleMessage(message);
assertEquals(13, redisZset.size());
Set<TypedTuple<String>> entries = redisZset.rangeByScoreWithScores(18, 19);
assertEquals(6, entries.size());
this.deletePresidents(jcf);
}
use of org.springframework.data.redis.core.ZSetOperations.TypedTuple in project spring-integration by spring-projects.
the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadParsedAndProvidedKeyDefault.
@Test
@RedisAvailable
public void testZsetWithListPayloadParsedAndProvidedKeyDefault() {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
this.deleteKey(jcf, "foo");
String key = "foo";
RedisZSet<String> redisZset = new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
assertEquals(0, redisZset.size());
RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
handler.setKey(key);
handler.setCollectionType(CollectionType.ZSET);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
List<String> list = new ArrayList<String>();
list.add("Manny");
list.add("Moe");
list.add("Jack");
Message<List<String>> message = MessageBuilder.withPayload(list).setHeader(RedisHeaders.ZSET_INCREMENT_SCORE, true).build();
handler.handleMessage(message);
assertEquals(3, redisZset.size());
Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
for (TypedTuple<String> pepboy : pepboys) {
assertTrue(pepboy.getScore() == 1);
}
handler.handleMessage(message);
assertEquals(3, redisZset.size());
pepboys = redisZset.rangeByScoreWithScores(1, 2);
// should have incremented by 1
for (TypedTuple<String> pepboy : pepboys) {
assertEquals(Double.valueOf(2), pepboy.getScore());
}
this.deleteKey(jcf, "foo");
}
Aggregations