作者归档:huntcool001

关于SpringBoot的测试

package com.heytea.service.order;

import com.alibaba.fastjson.JSON;
import com.heytea.service.order.service.OrderItemService;
import java.util.Map;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ServiceOrderApplicationTests {

  @Autowired
  private OrderItemService orderItemService;
  @Resource
  private RedisTemplate<String, Integer> redisTemplate;

  @Test
  public void contextLoads() {
    Map<Integer, Integer> useActivity = orderItemService.getUseActivity(1);
    System.out.println(JSON.toJSONString(useActivity));
  }

  @Test
  public void redisTest() {
    redisTemplate.executePipelined(new SessionCallback<Object>() {
      @SuppressWarnings({"rawtypes", "unchecked"})
      @Override
      public Object execute(RedisOperations operations) throws DataAccessException {
        operations.opsForHash().put("azzz", "b", 0);
        operations.opsForHash().increment("azzz", "b", 1L);
        operations.opsForHash().increment("azzz", "b", 1L);
        operations.opsForHash().increment("azzz", "b", 1L);
        return null;
      }
    });
    Object o = redisTemplate.opsForHash().get("azzz", "b");
  }
}