Search in sources :

Example 1 with Seckill

use of com.goodskill.entity.Seckill in project goodsKill by techa03.

the class SeckillServiceImplTest method getInfoById.

@Test
public void getInfoById() {
    Seckill seckill = new Seckill();
    long seckillId = 1L;
    seckill.setSeckillId(seckillId);
    int goodsId = 2;
    seckill.setGoodsId(goodsId);
    when(seckillServiceInterface.getById(seckillId)).thenReturn(seckill);
    when(goodsService.getById(goodsId)).thenReturn(new Goods());
    seckillService.getInfoById(seckillId);
}
Also used : Goods(com.goodskill.entity.Goods) Seckill(com.goodskill.entity.Seckill) Test(org.junit.jupiter.api.Test)

Example 2 with Seckill

use of com.goodskill.entity.Seckill in project goodsKill by techa03.

the class SeckillServiceImplTest method prepareSeckill.

@Test
public void prepareSeckill() {
    long seckillId = 1L;
    Seckill t = new Seckill();
    when(redisService.getSeckill(seckillId)).thenReturn(t);
    when(redisTemplate.delete(seckillId)).thenReturn(true);
    seckillService.prepareSeckill(seckillId, 10);
    verify(successKilledMongoService, times(1)).deleteRecord(seckillId);
}
Also used : Seckill(com.goodskill.entity.Seckill) Test(org.junit.jupiter.api.Test)

Example 3 with Seckill

use of com.goodskill.entity.Seckill in project goodsKill by techa03.

the class SeckillServiceImplTest method getSeckillList.

@Test
public void getSeckillList() {
    Seckill seckillEntity = new Seckill();
    String goodsName = "test";
    String key = "seckill:list:" + 1 + ":" + 1 + ":" + goodsName;
    when(redisTemplate.opsForValue()).thenReturn(valueOperations);
    when(valueOperations.get(key)).thenReturn(null);
    Page<Seckill> page = new Page<>();
    page.setRecords(Lists.newArrayList(seckillEntity));
    when(baseMapper.selectPage(any(), any())).thenReturn(page);
    assertEquals(1, seckillService.getSeckillList(1, 1, goodsName).getRecords().size());
}
Also used : Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Seckill(com.goodskill.entity.Seckill) Test(org.junit.jupiter.api.Test)

Example 4 with Seckill

use of com.goodskill.entity.Seckill in project goodsKill by techa03.

the class SynchronizedLockStrategyTest method executeNumberGt0.

@Test
public void executeNumberGt0() {
    SeckillMockRequestDTO requestDto = new SeckillMockRequestDTO();
    long seckillId = 1L;
    requestDto.setSeckillId(seckillId);
    requestDto.setCount(1);
    requestDto.setPhoneNumber("1");
    Seckill seckill = new Seckill();
    seckill.setNumber(1);
    when(seckillMapper.selectById(seckillId)).thenReturn(seckill);
    synchronizedLockStrategy.execute(requestDto);
    Seckill sendTopicResult = new Seckill();
    sendTopicResult.setSeckillId(seckillId);
    sendTopicResult.setStatus(SeckillStatusConstant.END);
    verify(seckillMapper, never()).updateById(sendTopicResult);
}
Also used : SeckillMockRequestDTO(com.goodskill.api.dto.SeckillMockRequestDTO) Seckill(com.goodskill.entity.Seckill) Test(org.junit.jupiter.api.Test)

Example 5 with Seckill

use of com.goodskill.entity.Seckill in project goodsKill by techa03.

the class SeckillMockController method redisReactiveMongo.

/**
 * 场景八:使用redis缓存执行库存-1操作,最后通过发送MQ完成数据落地(存入mongoDB)
 */
@ApiOperation(value = "秒杀场景八(秒杀商品存放redis减库存,异步发送秒杀成功MQ,mongoDb数据落地)")
@RequestMapping(value = "/redisReactiveMongo", method = POST, produces = { "application/json;charset=UTF-8" })
public Result redisReactiveMongo(@RequestBody @Valid SeckillWebMockRequestDTO dto) {
    long seckillId = dto.getSeckillId();
    int seckillCount = dto.getSeckillCount();
    int requestCount = dto.getRequestCount();
    prepareSeckill(seckillId, seckillCount, REDIS_MONGO_REACTIVE.getName());
    log.info(REDIS_MONGO_REACTIVE.getName() + "开始时间:{},秒杀id:{}", new Date(), seckillId);
    Seckill seckill = new Seckill();
    seckill.setSeckillId(seckillId);
    AtomicInteger atomicInteger = new AtomicInteger(0);
    for (int i = 0; i < requestCount; i++) {
        taskExecutor.execute(() -> seckillService.execute(new SeckillMockRequestDTO(seckillId, requestCount, String.valueOf(atomicInteger.addAndGet(1))), REDIS_MONGO_REACTIVE.getCode()));
    }
    return Result.ok();
}
Also used : SeckillMockRequestDTO(com.goodskill.api.dto.SeckillMockRequestDTO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Seckill(com.goodskill.entity.Seckill) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Seckill (com.goodskill.entity.Seckill)26 Test (org.junit.jupiter.api.Test)10 Date (java.util.Date)5 Goods (com.goodskill.entity.Goods)4 SeckillMockRequestDTO (com.goodskill.api.dto.SeckillMockRequestDTO)3 ValueOperations (org.springframework.data.redis.core.ValueOperations)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2 SeckillCloseException (com.goodskill.common.exception.SeckillCloseException)2 SuccessKilled (com.goodskill.entity.SuccessKilled)2 AlipayTradePrecreateResponse (com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)1 RepeatKillException (com.goodskill.common.exception.RepeatKillException)1 SeckillException (com.goodskill.common.exception.SeckillException)1 GlobalTransactional (io.seata.spring.annotation.GlobalTransactional)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1