Search in sources :

Example 1 with SuccessKilled

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));
}
Also used : SuccessKilled(com.goodskill.entity.SuccessKilled) Test(org.junit.jupiter.api.Test)

Example 2 with SuccessKilled

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);
}
Also used : SuccessKilled(com.goodskill.entity.SuccessKilled) Test(org.junit.jupiter.api.Test)

Example 3 with 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);
}
Also used : Goods(com.goodskill.entity.Goods) SuccessKilled(com.goodskill.entity.SuccessKilled) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SuccessKilled

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));
}
Also used : SuccessKilled(com.goodskill.entity.SuccessKilled)

Example 5 with SuccessKilled

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) SuccessKilled(com.goodskill.entity.SuccessKilled) Seckill(com.goodskill.entity.Seckill) InetAddress(java.net.InetAddress) Date(java.util.Date)

Aggregations

SuccessKilled (com.goodskill.entity.SuccessKilled)10 Date (java.util.Date)4 Test (org.junit.jupiter.api.Test)4 RepeatKillException (com.goodskill.common.exception.RepeatKillException)2 SeckillCloseException (com.goodskill.common.exception.SeckillCloseException)2 SeckillException (com.goodskill.common.exception.SeckillException)2 Seckill (com.goodskill.entity.Seckill)2 IOException (java.io.IOException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 Goods (com.goodskill.entity.Goods)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1