package thrift; import core.thrift.MyAsyncMethodCallback; import core.thrift.ThriftClientPool; import core.thrift.comment.QueryComment; import core.thrift.task.TSDM; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; //让测试运行于Spring环境 @RunWith(SpringJUnit4ClassRunner.class) @SpringJUnitWebConfig @ContextConfiguration(classes = SpringConfig.class) @ComponentScan("core.thrift") public class ThriftTest { private static Logger log = LogManager.getLogger(); @Test public void commentSum() throws Exception { MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); ThriftClientPool.doExecute(client -> client.commentSum(49052, call), QueryComment.AsyncClient.class); log.info(call.getResult()); } @Test public void download() throws Exception { MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); ThriftClientPool.doExecute(client -> client.download(new ArrayList() {{ add(49052); }}, "test", call), QueryComment.AsyncClient.class); log.info(call.getResult()); } @Test public void work() throws Exception { MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); ThriftClientPool.doExecute(client -> client.qiandao(call), TSDM.AsyncClient.class); log.info(call.getResult()); } }