use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class RedisService method getSeckill.
public Seckill getSeckill(long seckillId) {
String key = "seckill:" + seckillId;
byte[] bytes = (byte[]) redisTemplate.opsForValue().get(key.getBytes());
if (bytes != null) {
Seckill seckill = schema.newMessage();
ProtostuffIOUtil.mergeFrom(bytes, seckill, schema);
return seckill;
} else {
Seckill seckill = seckillMapper.selectById(seckillId);
if (seckill == null) {
throw new RuntimeException("秒杀活动不存在!");
}
putSeckill(seckill);
return seckill;
}
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class GoodskillSeataApplication method testGlobalTransaction.
/**
* 测试seata分布式事务
*/
@GetMapping("/test")
@GlobalTransactional
public void testGlobalTransaction() {
Goods goods = new Goods();
goods.setName("test");
goodsService.addGoods(goods, null);
Seckill seckill = seckillService.getById(1001L);
seckill.setNumber(seckill.getNumber() - 1);
seckillService.saveOrUpdate(seckill);
// 测试异常情况
throw new RuntimeException();
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class SeckillServiceImplTest method exportSeckillUrl.
@Test
public void exportSeckillUrl() {
Seckill t = new Seckill();
t.setStartTime(new Date());
t.setEndTime(new Date());
when(redisService.getSeckill(1L)).thenReturn(t);
assertNotNull(seckillService.exportSeckillUrl(1L));
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class SeckillProcedureExecutorTest method dealSeckill.
@Test
void dealSeckill() {
long seckillId = 1001L;
Seckill seckill = new Seckill();
seckill.setNumber(0);
when(seckillMapper.selectById(seckillId)).thenReturn(seckill);
seckillProcedureExecutor.dealSeckill(seckillId, "123", "test");
Seckill updateSeckill = new Seckill();
updateSeckill.setSeckillId(seckillId);
updateSeckill.setStatus(SeckillStatusConstant.END);
verify(seckillMapper, times(1)).updateById(updateSeckill);
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class SynchronizedLockStrategyTest method execute.
@Test
@Disabled
public void execute() {
SeckillMockRequestDTO requestDto = new SeckillMockRequestDTO();
long seckillId = 1L;
requestDto.setSeckillId(seckillId);
requestDto.setCount(2);
requestDto.setPhoneNumber("1");
Seckill sendTopicResult = new Seckill();
sendTopicResult.setSeckillId(seckillId);
sendTopicResult.setStatus(SeckillStatusConstant.END);
Seckill seckill1 = new Seckill();
seckill1.setNumber(0);
when(seckillMapper.selectById(seckillId)).thenReturn(seckill1);
synchronizedLockStrategy.execute(requestDto);
verify(seckillMapper, times(2)).updateById(sendTopicResult);
}
Aggregations