Skip to content

Instantly share code, notes, and snippets.

@artembilan
Created March 28, 2018 17:12
Show Gist options
  • Save artembilan/489bd44d1df0c6e3abc3f9de586a9e8f to your computer and use it in GitHub Desktop.
Save artembilan/489bd44d1df0c6e3abc3f9de586a9e8f to your computer and use it in GitHub Desktop.
@Test
public void testTransactionalBRPOP() {
RedisConnectionFactory connectionFactory = new JedisConnectionFactory();
RedisTemplate<String, String> redisTemplate = new StringRedisTemplate(connectionFactory);
redisTemplate.setEnableTransactionSupport(true);
redisTemplate.afterPropertiesSet();
TransactionTemplate transactionTemplate = new TransactionTemplate(new PseudoTransactionManager());
String redisList = "SpringIntegrationTestList";
redisTemplate.delete(redisList);
// See 'leftPush()' JavaDocs: '@return {@literal null} when used in pipeline / transaction.'
assertNull(transactionTemplate.execute(status -> redisTemplate.boundListOps(redisList).leftPush("bar")));
assertEquals(new Long(1), redisTemplate.boundListOps(redisList).size());
assertEquals(new Long(1), transactionTemplate.execute(status -> redisTemplate.boundListOps(redisList).size()));
assertNotNull(transactionTemplate.execute(status -> redisTemplate.boundListOps(redisList).rightPop()));
}
public static class PseudoTransactionManager extends AbstractPlatformTransactionManager {
private static final long serialVersionUID = 1L;
@Override
protected Object doGetTransaction() throws TransactionException {
return new Object();
}
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
//noop
}
@Override
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
//noop
}
@Override
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
//noop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment