DonalEvans commented on a change in pull request #7513:
URL: https://github.com/apache/geode/pull/7513#discussion_r840037004



##########
File path: 
geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/string/MSetDUnitTest.java
##########
@@ -114,6 +119,33 @@ public void 
testMSet_concurrentInstancesHandleBucketMovement() {
                     .allSatisfy(value -> 
assertThat(value).startsWith("valueTwo"))));
   }
 
+  @Test
+  public void testMSet_isTransactional() {

Review comment:
       The following test fails without your changes and passes with it, and 
demonstrates that the transaction is rolled back if an exception is encountered 
during the MSET operation:
   ```
     public static final String THROWING_CACHE_WRITER_EXCEPTION = "to be 
ignored";
   
     @Test
     public void mset_isTransactional() {
       IgnoredException.addIgnoredException(THROWING_CACHE_WRITER_EXCEPTION);
       String hashTag = "{" + clusterStartUp.getKeyOnServer("tag", 1) + "}";
   
       String key1 = hashTag + "key1";
       String value1 = "value1";
       jedis.set(key1, value1);
   
       String listKey = hashTag + "listKey";
       jedis.lpush(listKey, "1", "2", "3");
   
       String nonExistent = hashTag + "nonExistentKey";
   
       String throwingKey = hashTag + "ThrowingRedisString";
       String throwingKeyValue = "ThrowingRedisStringValue";
   
       jedis.set(throwingKey, throwingKeyValue);
   
       // Install a cache writer that will throw an exception if a key with a 
name equal to throwingKey is updated or created
       clusterStartUp.getMember(1).invoke(() -> {
         RedisClusterStartupRule.getCache()
             .<RedisKey, RedisData>getRegion(DEFAULT_REDIS_REGION_NAME)
             .getAttributesMutator()
             .setCacheWriter(new ThrowingCacheWriter(throwingKey));
       });
   
       String newValue = "should_not_be_set";
   
       assertThatThrownBy(
           () -> jedis.mset(key1, newValue, nonExistent, newValue, throwingKey, 
newValue))
               .hasMessage(SERVER_ERROR_MESSAGE);
   
       assertThat(jedis.get(key1)).isEqualTo(value1);
       assertThat(jedis.type(listKey)).isEqualTo("list");
       assertThat(jedis.exists(nonExistent)).isFalse();
       assertThat(jedis.get(throwingKey)).isEqualTo(throwingKeyValue);
   
       IgnoredException.removeAllExpectedExceptions();
     }
   
     private static class ThrowingCacheWriter implements CacheWriter<RedisKey, 
RedisData> {
       private final byte[] keyBytes;
   
       ThrowingCacheWriter(String key) {
         keyBytes = key.getBytes(StandardCharsets.UTF_8);
       }
   
       @Override
       public void beforeUpdate(EntryEvent<RedisKey, RedisData> event) throws 
CacheWriterException {
         if (Arrays.equals(event.getKey().toBytes(), keyBytes)) {
           throw new CacheWriterException(THROWING_CACHE_WRITER_EXCEPTION);
         }
       }
   
       @Override
       public void beforeCreate(EntryEvent<RedisKey, RedisData> event) throws 
CacheWriterException {
         if (Arrays.equals(event.getKey().toBytes(), keyBytes)) {
           throw new CacheWriterException(THROWING_CACHE_WRITER_EXCEPTION);
         }
       }
   
       @Override
       public void beforeDestroy(EntryEvent<RedisKey, RedisData> event) throws 
CacheWriterException {
   
       }
   
       @Override
       public void beforeRegionDestroy(RegionEvent<RedisKey, RedisData> event)
           throws CacheWriterException {
   
       }
   
       @Override
       public void beforeRegionClear(RegionEvent<RedisKey, RedisData> event)
           throws CacheWriterException {
   
       }
     }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to