/**
 * @projectName willalp-pns-ml
 * @package com.willalp.test
 * @className com.willalp.test.CanteenTest
 * @copyright Copyright 2019 HuiShan, Inc All rights reserved.
 */
package com.willalp;

import com.willalp.canteen.service.IHsGiftService;
import com.willalp.msg.service.IHsAppUserMsgService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * CanteenTest
 * @description 模块单元测试类
 * @author hs
 * @date 2023/2/3 14:57
 * @version 1.0
 */
@SpringBootTest(classes = WillalpApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CanteenTest {
    private static final Logger log = LoggerFactory.getLogger(CanteenTest.class);

    @Autowired
    private IHsGiftService giftService;

    @Autowired
    private IHsAppUserMsgService appUserMsgService;
    @Test
    public void test() {
        //测试积分兑换是否会超卖
        for (int i = 0; i < 200; i++) {
            new Thread(() -> {
                int i1 = (int) (1 + Math.random() * (10 - 1 + 1));
                if (giftService.checkAndReduceGiftInventory(i1, "1601029390240735234") > 0) {
                    log.info("线程[" + Thread.currentThread().getName() + "] - 购买【" + i1 + "】个成功！");
                } else {
                    log.info("线程[" + Thread.currentThread().getName() + "] - 购买【" + i1 + "】个失败~");
                }
            }).start();
        }
    }

    @Test
    public void test1() {
        appUserMsgService.pushMsgSum();
    }
}
 