第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Spring Integration 任務(wù)執(zhí)行器在測(cè)試過程中大約 1000 毫秒后毫無警告地終止

Spring Integration 任務(wù)執(zhí)行器在測(cè)試過程中大約 1000 毫秒后毫無警告地終止

猛跑小豬 2023-10-19 21:04:22
我使用 Spring Integration 構(gòu)建以下流程:輸入通道 -> 拆分器 -> 轉(zhuǎn)換器 -> 服務(wù)激活器 -> 聚合器Transformer 和 Service Activator 使用任務(wù)執(zhí)行器鏈接并執(zhí)行。在應(yīng)用程序執(zhí)行期間,沒有任何問題。但是,當(dāng)我嘗試運(yùn)行單元測(cè)試時(shí),如果存在長(zhǎng)時(shí)間運(yùn)行的任務(wù),則執(zhí)行服務(wù)激活器的執(zhí)行程序線程會(huì)神秘退出。為了演示這一點(diǎn),我創(chuàng)建了一個(gè)具有以下配置的示例項(xiàng)目:<task:executor id="executor" pool-size="20" keep-alive="120" queue-capacity="100"/><jms:message-driven-channel-adapter id="helloWorldJMSAdapater" destination="helloWorldJMSQueue"    channel="helloWorldChannel"/>    <int:channel id="helloWorldChannel"/><int:splitter id="splitter" input-channel="helloWorldChannel" output-channel="execChannel">    <bean id="stringSplitter" class="hello.Splitter"></bean></int:splitter><int:channel id="execChannel">    <int:dispatcher task-executor="executor"></int:dispatcher></int:channel><int:chain input-channel="execChannel" output-channel="aggregatorChannel">    <int:transformer>        <bean id="stringTransformer" class="hello.Transformer"></bean>    </int:transformer>    <int:service-activator id="helloWorldServiceActivator" ref="helloWorldAmqService" method="processMsg"/></int:chain><int:aggregator input-channel="aggregatorChannel" output-channel="errorChannel">    <bean class="hello.ResponseAggregator"/></int:aggregator>這是 Splitter 類:public class Splitter {public List<String> splitMessage(Message message)  {    String msg = message.getPayload().toString();    return Arrays.asList(msg.split(","));}}這是 Transformer 類:public class Transformer {public String transform(Message message)  {    String msg = message.getPayload().toString();    return msg+"t";}}為了模擬長(zhǎng)時(shí)間運(yùn)行的任務(wù),我Thread.sleep()在 processMsg 方法中添加了一個(gè)。
查看完整描述

1 回答

?
呼啦一陣風(fēng)

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊

您的問題是您錯(cuò)過了一個(gè)事實(shí),即您的應(yīng)用程序是一個(gè)async,但您的測(cè)試與處理多線程解決方案無關(guān)。


您在測(cè)試方法中發(fā)送一條消息,并且不執(zhí)行任何操作來等待輸出消息。因此,啟動(dòng)測(cè)試執(zhí)行的主線程就存在,而將其他線程中的所有執(zhí)行拋在后面。


您的想法是發(fā)送到而helloWorldChannel不是處理 JMS 目的地是一個(gè)不錯(cuò)的選擇。唯一的問題是聚合后不等待流結(jié)果。


將端點(diǎn)的輸出放入 中也很奇怪errorChannel,但您可以在生成消息之前從測(cè)試用例中訂閱它:


@Autowired

private SubscribableChannel errorChannel;



@Test

public void test() {

    SettableListenableFuture<Message<?>> messageFuture = new SettableListenableFuture<>();

    this.errorChannel.subscribe((message) -> messageFuture.set(message));

    helloWorldChannel.send(MessageBuilder.withPayload("1,2,3,4,6").build());

    Message<?> messageToAssert = messageFuture.get(10, TimeUnit.SECONDS);

    ...

}

這樣,您的主 JUnit 線程將等待該 中的結(jié)果,而與流行為無關(guān)Future。


查看完整回答
反對(duì) 回復(fù) 2023-10-19
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)