Search in sources :

Example 6 with Goods

use of com.goodskill.entity.Goods 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 7 with Goods

use of com.goodskill.entity.Goods in project goodsKill by techa03.

the class MyJob method execute.

@Override
public void execute(ShardingContext context) {
    switch(context.getShardingItem()) {
        case 0:
            try {
                log.info("商品es索引开始更新。。。");
                List list = goodsService.list().parallelStream().map(g -> {
                    Goods goods = new Goods();
                    BeanUtils.copyProperties(g, goods);
                    return goods;
                }).collect(Collectors.toList());
                goodsEsService.saveBatch(list);
                log.info("商品es索引更新成功,条数:{}", list.size());
            } catch (Exception e) {
                log.warn("商品es索引定时任务更新失败!", e);
            }
            break;
        // case n: ...
        default:
            break;
    }
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) ShardingContext(org.apache.shardingsphere.elasticjob.api.ShardingContext) Component(org.springframework.stereotype.Component) List(java.util.List) GoodsService(com.goodskill.api.service.GoodsService) SimpleJob(org.apache.shardingsphere.elasticjob.simple.job.SimpleJob) Resource(javax.annotation.Resource) DubboReference(org.apache.dubbo.config.annotation.DubboReference) GoodsEsService(com.goodskill.es.api.GoodsEsService) Collectors(java.util.stream.Collectors) Goods(com.goodskill.entity.Goods) BeanUtils(org.springframework.beans.BeanUtils) List(java.util.List) Goods(com.goodskill.entity.Goods)

Example 8 with Goods

use of com.goodskill.entity.Goods in project goodsKill by techa03.

the class GoodsServiceImplTest method addGoods.

@Test
public void addGoods() {
    Goods goods = new Goods();
    goodsService.addGoods(goods, new byte[100]);
    verify(goodsEsService, only()).save(any());
}
Also used : Goods(com.goodskill.entity.Goods) Test(org.junit.jupiter.api.Test)

Aggregations

Goods (com.goodskill.entity.Goods)8 Seckill (com.goodskill.entity.Seckill)4 Test (org.junit.jupiter.api.Test)3 AlipayTradePrecreateResponse (com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse)1 GoodsService (com.goodskill.api.service.GoodsService)1 SuccessKilled (com.goodskill.entity.SuccessKilled)1 GoodsEsService (com.goodskill.es.api.GoodsEsService)1 GlobalTransactional (io.seata.spring.annotation.GlobalTransactional)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 Slf4j (lombok.extern.slf4j.Slf4j)1 DubboReference (org.apache.dubbo.config.annotation.DubboReference)1 ShardingContext (org.apache.shardingsphere.elasticjob.api.ShardingContext)1 SimpleJob (org.apache.shardingsphere.elasticjob.simple.job.SimpleJob)1 BeanUtils (org.springframework.beans.BeanUtils)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Component (org.springframework.stereotype.Component)1 Transactional (org.springframework.transaction.annotation.Transactional)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1