Skip to content

Commit 836900e

Browse files
mp911dechristophstrobl
authored andcommitted
DATAREDIS-506 - Reformat test and add ticket references.
Original Pull Request: spring-projects#211
1 parent 1a332c0 commit 836900e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,26 +761,34 @@ public void testType() {
761761
assertEquals(DataType.STRING, redisTemplate.type(key1));
762762
}
763763

764+
/**
765+
* @see DATAREDIS-506
766+
*/
764767
@Test
765768
public void testWatch() {
766769
final K key1 = keyFactory.instance();
767770
V value1 = valueFactory.instance();
768771
final V value2 = valueFactory.instance();
769772
final V value3 = valueFactory.instance();
770773
redisTemplate.opsForValue().set(key1, value1);
774+
771775
final Thread th = new Thread(new Runnable() {
772776
public void run() {
773777
redisTemplate.opsForValue().set(key1, value2);
774778
}
775779
});
780+
776781
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
777782
@SuppressWarnings({ "unchecked", "rawtypes" })
778783
public List<Object> execute(RedisOperations operations) throws DataAccessException {
784+
779785
operations.watch(key1);
786+
780787
th.start();
781788
try {
782789
th.join();
783790
} catch (InterruptedException e) {}
791+
784792
operations.multi();
785793
operations.opsForValue().set(key1, value3);
786794
return operations.exec();
@@ -792,11 +800,13 @@ public List<Object> execute(RedisOperations operations) throws DataAccessExcepti
792800
} else {
793801
assertNull(results);
794802
}
803+
795804
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
796805
}
797806

798807
@Test
799808
public void testUnwatch() {
809+
800810
final K key1 = keyFactory.instance();
801811
V value1 = valueFactory.instance();
802812
final V value2 = valueFactory.instance();
@@ -807,48 +817,62 @@ public void run() {
807817
redisTemplate.opsForValue().set(key1, value2);
808818
}
809819
});
820+
810821
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
811822
@SuppressWarnings({ "unchecked", "rawtypes" })
812823
public List<Object> execute(RedisOperations operations) throws DataAccessException {
824+
813825
operations.watch(key1);
826+
814827
th.start();
815828
try {
816829
th.join();
817830
} catch (InterruptedException e) {}
831+
818832
operations.unwatch();
819833
operations.multi();
820834
operations.opsForValue().set(key1, value3);
821835
return operations.exec();
822836
}
823837
});
838+
824839
assertTrue(results.isEmpty());
825840
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value3));
826841
}
827842

843+
/**
844+
* @see DATAREDIS-506
845+
*/
828846
@Test
829847
public void testWatchMultipleKeys() {
848+
830849
final K key1 = keyFactory.instance();
831850
final K key2 = keyFactory.instance();
832851
V value1 = valueFactory.instance();
833852
final V value2 = valueFactory.instance();
834853
final V value3 = valueFactory.instance();
835854
redisTemplate.opsForValue().set(key1, value1);
855+
836856
final Thread th = new Thread(new Runnable() {
837857
public void run() {
838858
redisTemplate.opsForValue().set(key1, value2);
839859
}
840860
});
861+
841862
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
842863
@SuppressWarnings({ "unchecked", "rawtypes" })
843864
public List<Object> execute(RedisOperations operations) throws DataAccessException {
865+
844866
List<K> keys = new ArrayList<K>();
845867
keys.add(key1);
846868
keys.add(key2);
847869
operations.watch(keys);
870+
848871
th.start();
849872
try {
850873
th.join();
851874
} catch (InterruptedException e) {}
875+
852876
operations.multi();
853877
operations.opsForValue().set(key1, value3);
854878
return operations.exec();

0 commit comments

Comments
 (0)