簡體   English   中英

spring-integration MockIntegrationContext ReactiveStreamConsumer: IllegalArgumentException: 'subscriber' 在“...端點”中不能是 null

[英]spring-integration MockIntegrationContext ReactiveStreamConsumer: IllegalArgumentException: 'subscriber' must not be null in the "...endpoint"

由於缺少“訂閱者”字段,我的測試失敗IllegalArgumentException: 'subscriber' must not be null in the "...endpoint"

    @Test
    public void test() throws InterruptedException {
        ArgumentCaptor<Message<?>> captor = messageArgumentCaptor();
        CountDownLatch receiveLatch = new CountDownLatch(1);
        MessageHandler mockMessageHandler = mockMessageHandler(captor).handleNext(m -> receiveLatch.countDown());
        this.mockIntegrationContext
                .substituteMessageHandlerFor(
                        "test2.org.springframework.integration.config.ConsumerEndpointFactoryBean#1",
                        mockMessageHandler);
        this.integrationFlowWithReactiveConsumerHandler.getInputChannel().send(new GenericMessage<>("test2"));
        assertThat(receiveLatch.await(10, TimeUnit.SECONDS)).isTrue();
        verify(mockMessageHandler).handleMessage(any());
        assertThat(captor.getValue().getPayload())
                .isEqualTo("reactive-message-text");
    }

當端點為ReactiveStreamsConsumer時,它在MockIntegrationContext.java中失敗,調用substituteMessageHandlerFor方法

    public void substituteMessageHandlerFor(String consumerEndpointId, // NOSONAR - complexity
            MessageHandler mockMessageHandler, boolean autoStartup) {

        Object endpoint = this.beanFactory.getBean(consumerEndpointId, IntegrationConsumer.class);
        if (autoStartup && endpoint instanceof Lifecycle) {
            ((Lifecycle) endpoint).stop();
        }
        DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(endpoint);
        Object targetMessageHandler = directFieldAccessor.getPropertyValue(HANDLER);
        Assert.notNull(targetMessageHandler, () -> "'handler' must not be null in the: " + endpoint);
        if (endpoint instanceof ReactiveStreamsConsumer) {
            Object targetSubscriber = directFieldAccessor.getPropertyValue("subscriber");
            Assert.notNull(targetSubscriber, () -> "'subscriber' must not be null in the: " + endpoint);

處理程序端點 bean 是...:reactive-outbound-channel-adapter ,它正在使用 ReactiveStreamConsumer 構造函數實例化,其中“subsciber”字段默認為 null。

    /**
     * Instantiate an endpoint based on the provided {@link MessageChannel} and {@link ReactiveMessageHandler}.
     * @param inputChannel the channel to consume in reactive manner.
     * @param reactiveMessageHandler the {@link ReactiveMessageHandler} to process messages.
     * @since 5.3
     */
    public ReactiveStreamsConsumer(MessageChannel inputChannel, ReactiveMessageHandler reactiveMessageHandler) {
        Assert.notNull(inputChannel, "'inputChannel' must not be null");
        this.inputChannel = inputChannel;
        this.handler = new ReactiveMessageHandlerAdapter(reactiveMessageHandler);
        this.reactiveMessageHandler = reactiveMessageHandler;
        this.publisher = IntegrationReactiveUtils.messageChannelToFlux(inputChannel);
        this.subscriber = null;
        this.lifecycleDelegate =
                reactiveMessageHandler instanceof Lifecycle ? (Lifecycle) reactiveMessageHandler : null;
    }

在測試期間它創建端點 bean,然后在substituteMessageHandlerFor期間它拋出缺少subscriber字段的異常

使用單個 DB 反應式處理程序,集成流程很簡單。

有任何想法嗎? 非常感謝。

這是測試框架中的錯誤。 當我們在ReactiveStreamsConsumer中引入ReactiveMessageHandler支持時,我們只是錯過了分別調整MockIntegrationContext邏輯。

目前沒有任何合理的解決方法來模擬反應式端點。 但是,您可以在流程中引入一些中間端點,例如bridge()並只模擬這個端點而不返回任何結果。 因此,您的測試將通過,並且最終不會將任何內容發送到真正的反應端點。

請隨時提出 GH 問題,我們會盡快進行調查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM