Created
March 28, 2018 17:12
-
-
Save artembilan/489bd44d1df0c6e3abc3f9de586a9e8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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