use of com.goodskill.entity.SuccessKilled in project goodsKill by techa03.
the class SeckillServiceImplTest method executeSeckill.
@Test
public void executeSeckill() {
long seckillId = 1L;
String userPhone = "123213";
String md5 = MD5Util.getMD5(seckillId);
when(baseMapper.reduceNumber(eq(seckillId), any())).thenReturn(1);
SuccessKilled successKilled = new SuccessKilled();
successKilled.setSeckillId(seckillId);
successKilled.setUserPhone(userPhone);
when(successKilledMapper.insert(successKilled)).thenReturn(1);
when(successKilledMapper.selectOne(any())).thenReturn(new SuccessKilled());
when(alipayRunner.tradePrecreate(seckillId)).thenReturn("1");
assertNotNull(seckillService.executeSeckill(seckillId, userPhone, md5));
}
use of com.goodskill.entity.SuccessKilled in project goodsKill by techa03.
the class SeckillServiceImplTest method reduceNumber.
@Test
public void reduceNumber() {
SuccessKilled successKilled = new SuccessKilled();
when(seckillService.reduceNumber(successKilled)).thenThrow(new RuntimeException());
seckillService.reduceNumber(successKilled);
}
use of com.goodskill.entity.SuccessKilled in project goodsKill by techa03.
the class MultiDatasourceTransactionTest method testInsert.
@Test
@Transactional
public void testInsert() {
Goods entity = new Goods();
entity.setName("test");
goodsMapper.insert(entity);
SuccessKilled su = new SuccessKilled();
su.setUserPhone("3434");
su.setSeckillId(1432L);
successKilledMapper.insert(su);
su = new SuccessKilled();
su.setUserPhone("3435");
su.setSeckillId(1432L);
successKilledMapper.insert(su);
su = new SuccessKilled();
su.setUserPhone("3435");
su.setSeckillId(1431L);
successKilledMapper.insert(su);
su = new SuccessKilled();
su.setUserPhone("3434");
su.setSeckillId(1431L);
successKilledMapper.insert(su);
}
use of com.goodskill.entity.SuccessKilled in project goodsKill by techa03.
the class SeckillServiceImpl method deleteSuccessKillRecord.
@Override
public void deleteSuccessKillRecord(long seckillId) {
SuccessKilled example = new SuccessKilled();
example.setSeckillId(seckillId);
successKilledMapper.delete(new QueryWrapper<>(example));
}
use of com.goodskill.entity.SuccessKilled in project goodsKill by techa03.
the class SeckillProcedureExecutor method dealSeckill.
/**
* 处理用户秒杀请求
*
* @param seckillId 秒杀活动id
* @param userPhone
* @param note 秒杀备注信息
*/
@Override
public void dealSeckill(long seckillId, String userPhone, String note) {
try {
InetAddress localHost = InetAddress.getLocalHost();
SuccessKilled successKilled = new SuccessKilled();
successKilled.setSeckillId(seckillId);
successKilled.setUserPhone(userPhone);
successKilled.setCreateTime(new Date());
successKilled.setServerIp(localHost.getHostAddress() + ":" + localHost.getHostName());
if (seckillService.reduceNumber(successKilled) < 1) {
Seckill seckill = seckillMapper.selectById(seckillId);
log.debug("当前库存:{}", seckill.getNumber());
// 高并发时限制只能发一次秒杀完成通知
if (!SeckillStatusConstant.END.equals(seckill.getStatus()) && sendTopicTimes.getAndIncrement() == 0) {
streamBridge.send(DEFAULT_BINDING_NAME, MessageBuilder.withPayload(SeckillMockResponseDTO.builder().seckillId(seckillId).note(note).status(true).build()).build());
Seckill sendTopicResult = new Seckill();
sendTopicResult.setSeckillId(seckillId);
sendTopicResult.setStatus(SeckillStatusConstant.END);
seckillMapper.updateById(sendTopicResult);
// 重置发送成功通知次数
sendTopicTimes.set(0);
}
if (seckill.getNumber() <= 0) {
log.debug("库存不足,无法继续秒杀!");
}
}
} catch (UnknownHostException e) {
log.error(e.getMessage(), e);
}
}
Aggregations