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);
}
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);
}
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());
}
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);
}
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();
}
Aggregations