package org.redisson.spring.data.connection;

import static org.assertj.core.api.Assertions.*;

import java.util.List;

import org.junit.Test;
import org.redisson.BaseTest;

public class RedissonMultiConnectionTest extends BaseConnectionTest {

    @Test
    public void testEcho() {
        RedissonConnection connection = new RedissonConnection(redisson);
        connection.multi();
        assertThat(connection.echo("test".getBytes())).isNull();
        assertThat(connection.exec().iterator().next()).isEqualTo("test".getBytes());
    }

    @Test
    public void testSetGet() {
        RedissonConnection connection = new RedissonConnection(redisson);
        connection.multi();
        assertThat(connection.isQueueing()).isTrue();
        connection.set("key".getBytes(), "value".getBytes());
        assertThat(connection.get("key".getBytes())).isNull();
        
        List<Object> result = connection.exec();
        assertThat(connection.isQueueing()).isFalse();
        assertThat(result.get(0)).isEqualTo("value".getBytes());
    }
    
    @Test
    public void testHSetGet() {
        RedissonConnection connection = new RedissonConnection(redisson);
        connection.multi();
        assertThat(connection.hSet("key".getBytes(), "field".getBytes(), "value".getBytes())).isNull();
        assertThat(connection.hGet("key".getBytes(), "field".getBytes())).isNull();
        
        List<Object> result = connection.exec();
        assertThat((Boolean)result.get(0)).isTrue();
        assertThat(result.get(1)).isEqualTo("value".getBytes());
    }
    
}

@@ -116,132 +116,2523 @@
 st;%0A
-%0Aimport org.junit.Test;%0Aimport org.redisson.BaseTest;%0A%0Apublic class RedissonMultiConnectionTest extends BaseConnectionTest %7B
+import java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0A%0Aimport org.junit.Test;%0Aimport org.redisson.BaseTest;%0Aimport org.springframework.dao.DataAccessException;%0Aimport org.springframework.data.redis.core.RedisOperations;%0Aimport org.springframework.data.redis.core.SessionCallback;%0Aimport org.springframework.data.redis.core.StringRedisTemplate;%0Aimport org.springframework.data.redis.core.ValueOperations;%0A%0Apublic class RedissonMultiConnectionTest extends BaseConnectionTest %7B%0A%0A    @Test%0A    public void testBroken() throws InterruptedException %7B%0A        StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(new RedissonConnectionFactory(redisson));%0A        ExecutorService e = Executors.newFixedThreadPool(32);%0A        AtomicBoolean hasErrors = new AtomicBoolean();%0A        for (int i = 0; i %3C 10; i++) %7B%0A            e.submit(() -%3E %7B%0A                stringRedisTemplate.execute(new SessionCallback%3CVoid%3E() %7B%0A                    @Override%0A                    public Void execute(RedisOperations operations) throws DataAccessException %7B%0A                        try %7B%0A                            ValueOperations%3CString, String%3E valueOps = operations.opsForValue();%0A                            operations.multi();%0A                            valueOps.set(%22test3%22, %22value%22);%0A                        %7D catch (Exception e) %7B%0A                            e.printStackTrace();%0A                            hasErrors.set(true);%0A                        %7D%0A                        return null;%0A                    %7D%0A                %7D);%0A                stringRedisTemplate.execute(new SessionCallback%3CVoid%3E() %7B%0A                    @Override%0A                    public Void execute(RedisOperations operations) throws DataAccessException %7B%0A                        try %7B%0A                            ValueOperations%3CString, String%3E valueOps = operations.opsForValue();%0A                            valueOps.set(%22test1%22, %22value%22);%0A                            assertThat(valueOps.get(%22test1%22)).isEqualTo(%22value%22);%0A                        %7D catch (Exception e) %7B%0A                            e.printStackTrace();%0A                            hasErrors.set(true);%0A                        %7D%0A                        return null;%0A                    %7D%0A                %7D);%0A            %7D);%0A        %7D%0A        e.shutdown();%0A        e.awaitTermination(1, TimeUnit.MINUTES);%0A        assertThat(hasErrors).isFalse();%0A    %7D
 %0A%0A  

test added