|  |  | 
 |  |  | package com.xcong.excoin; | 
 |  |  |  | 
 |  |  | import cn.hutool.crypto.SecureUtil; | 
 |  |  | import com.xcong.excoin.modules.coin.dao.OrderCoinsDao; | 
 |  |  | import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity; | 
 |  |  | import com.xcong.excoin.modules.coin.service.OrderCoinService; | 
 |  |  | import com.xcong.excoin.trade.CoinTrader; | 
 |  |  | import com.xcong.excoin.trade.CoinTraderFactory; | 
 |  |  | import com.xcong.excoin.utils.CoinTypeConvert; | 
 |  |  | import com.xcong.excoin.utils.RedisUtils; | 
 |  |  | import lombok.SneakyThrows; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.junit.jupiter.api.Test; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.boot.test.context.SpringBootTest; | 
 |  |  |  | 
 |  |  | import javax.annotation.Resource; | 
 |  |  | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | @Slf4j | 
 |  |  | @SpringBootTest | 
 |  |  | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | 
 |  |  | public class TradeTest { | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void buy(){ | 
 |  |  |         redisUtils.set("ROC_NEW_PRICE",new BigDecimal("12.33")); | 
 |  |  |         redisUtils.set("GBZ_NEW_PRICE",new BigDecimal("12.33")); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static void main(String[] args) throws InterruptedException { | 
 |  |  |         // 测试两个地方 | 
 |  |  |         List<String> list  = new ArrayList<>(); | 
 |  |  |         list.add("1"); | 
 |  |  |         list.add("2"); | 
 |  |  |         list.add("3"); | 
 |  |  |         list.add("4"); | 
 |  |  |         // 开一个线程 | 
 |  |  |         Thread thread = new Thread(new Runnable() { | 
 |  |  |             @SneakyThrows | 
 |  |  |             @Override | 
 |  |  |             public void run() { | 
 |  |  |                 Thread.sleep(1000); | 
 |  |  |                 synchronized (list){ | 
 |  |  |                     Iterator<String> iterator = list.iterator(); | 
 |  |  |                     while (iterator.hasNext()){ | 
 |  |  |                         System.out.println("线程里"+iterator.next()); | 
 |  |  |                         iterator.remove(); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |         String s = SecureUtil.md5("330021"); | 
 |  |  |         System.out.println(s); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |         thread.start(); | 
 |  |  |         synchronized (list){ | 
 |  |  |             Iterator<String> iterator = list.iterator(); | 
 |  |  |             while (iterator.hasNext()){ | 
 |  |  |                 Thread.sleep(1000); | 
 |  |  |                 System.out.println(iterator.next()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     @Test | 
 |  |  |     public void gbz() { | 
 |  |  |         System.out.println(redisUtils.getString(CoinTypeConvert.convertToKey("GBZ"+"/USDT"))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |         // | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private CoinTraderFactory factory; | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void traderTest() { | 
 |  |  |         OrderCoinsEntity coinsEntity = orderCoinsDao.selectById(19); | 
 |  |  |         String symbol = coinsEntity.getSymbol(); | 
 |  |  |         CoinTrader trader = factory.getTrader(symbol); | 
 |  |  |         trader.trade(coinsEntity); | 
 |  |  |     } | 
 |  |  | } |