content: package com.alicp.jetcache.redisson;
  
  import com.alicp.jetcache.LoadingCacheTest;
  import com.alicp.jetcache.RefreshCacheTest;
  import com.alicp.jetcache.support.FastjsonKeyConvertor;
  import com.alicp.jetcache.support.JavaValueDecoder;
  import com.alicp.jetcache.support.JavaValueEncoder;
  import com.alicp.jetcache.support.KryoValueDecoder;
  import com.alicp.jetcache.support.KryoValueEncoder;
  import com.alicp.jetcache.test.external.AbstractExternalCacheTest;
  import org.junit.Test;
  import org.redisson.Redisson;
  import org.redisson.api.RedissonClient;
  import org.redisson.config.Config;
  
  import java.util.Random;
  import java.util.concurrent.TimeUnit;
  
  /**
   * Created on 2022/7/13.
   *
   * @author <a href="mailto:jeason1914@qq.com">yangyong</a>
   */
  public class RedissonCacheTest extends AbstractExternalCacheTest {
  
      @Test
      public void redissonTest() throws Exception {
          final Config config = new Config();
          config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(0);
          doTest(Redisson.create(config));
      }
  
      private void doTest(final RedissonClient redissonClient) throws Exception {
          cache = RedissonCacheBuilder.createBuilder()
                  .keyConvertor(FastjsonKeyConvertor.INSTANCE)
                  .valueEncoder(JavaValueEncoder.INSTANCE)
                  .valueDecoder(JavaValueDecoder.INSTANCE)
                  .redissonClient(redissonClient)
                  .keyPrefix(new Random().nextInt() + "")
                  .expireAfterWrite(500, TimeUnit.MILLISECONDS)
                  .buildCache();
  
          baseTest();
          fastjsonKeyCoverterTest();
          expireAfterWriteTest(cache.config().getExpireAfterWriteInMillis());
  
          LoadingCacheTest.loadingCacheTest(RedissonCacheBuilder.createBuilder()
                  .keyConvertor(FastjsonKeyConvertor.INSTANCE)
                  .valueEncoder(JavaValueEncoder.INSTANCE)
                  .valueDecoder(JavaValueDecoder.INSTANCE)
                  .redissonClient(redissonClient)
                  .keyPrefix(new Random().nextInt() + ""), 0);
          RefreshCacheTest.refreshCacheTest(RedissonCacheBuilder.createBuilder()
                  .keyConvertor(FastjsonKeyConvertor.INSTANCE)
                  .valueEncoder(JavaValueEncoder.INSTANCE)
                  .valueDecoder(JavaValueDecoder.INSTANCE)
                  .redissonClient(redissonClient)
                  .keyPrefix(new Random().nextInt() + ""), 200, 100);
  
  
          cache = RedissonCacheBuilder.createBuilder()
                  .keyConvertor(null)
                  .valueEncoder(KryoValueEncoder.INSTANCE)
                  .valueDecoder(KryoValueDecoder.INSTANCE)
                  .redissonClient(redissonClient)
                  .keyPrefix(new Random().nextInt() + "")
                  .buildCache();
          nullKeyConvertorTest();
  
          int thread = 10;
          int time = 3000;
          cache = RedissonCacheBuilder.createBuilder()
                  .keyConvertor(FastjsonKeyConvertor.INSTANCE)
                  .valueEncoder(KryoValueEncoder.INSTANCE)
                  .valueDecoder(KryoValueDecoder.INSTANCE)
                  .redissonClient(redissonClient)
                  .keyPrefix(new Random().nextInt() + "")
                  .buildCache();
          concurrentTest(thread, 500, time);
      }
  }
  