import com.abssh.vo.Person;
import com.abssh.service.PersonService;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.Serializable;
import java.util.PrimitiveIterator;

/**
 * Created by Steven on 2015/10/23.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:spring-context*.xml","classpath*:spring-mvc.xml"})
public class TestMemcached extends AbstractJUnit4SpringContextTests {

    @Autowired
    private PersonService personService;

    @Autowired
    private RedisTemplate<Serializable, Serializable> redisTemplate;

    private Person person;
    @Before
    public void init(){
        person = new Person();
        person.setUserId("1");
        person.setUsername("abssh");
        person.setPassword("abssh");
    }

    @Test
    public void TestPerson(){
        //personService.savePerson(person);
        personService.getPerson("1");
        personService.getPerson("1");
        personService.getPerson("1");
    }

    @Test
    @Ignore
    public void TestMemcached(){
        personService.getPersonMemcached("1");
        personService.getPersonMemcached("1");
        personService.getPersonMemcached("1");
    }

    @Test
    public void TestRedis1(){
        Person p = personService.getPersonRedis("1");
        System.out.println(p.getUsername());
        personService.getPersonRedis("1");
        System.out.println(p.getUsername());
        personService.getPersonRedis("1");
    }

    @Test
    @Ignore
    public void TestRedis2(){
        redisTemplate.opsForValue().set("1",person);
        Person p = (Person) redisTemplate.opsForValue().get("1");
        System.out.println(p.getUsername());
    }
}
