Search in sources :

Example 21 with Seckill

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

Example 22 with 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();
}
Also used : Goods(com.goodskill.entity.Goods) Seckill(com.goodskill.entity.Seckill) GetMapping(org.springframework.web.bind.annotation.GetMapping) GlobalTransactional(io.seata.spring.annotation.GlobalTransactional)

Example 23 with Seckill

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

Example 24 with Seckill

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

Example 25 with Seckill

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

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