davsclaus commented on code in PR #31241: URL: https://github.com/apache/camel/pull/31241#discussion_r4767805489
########## components/camel-mina-sftp/src/test/java/org/apache/camel/component/file/remote/mina/MinaSftpOperationsBufferSizeTest.java: ########## @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.file.remote.mina; + +import java.lang.reflect.Method; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Unit tests that verify CAMEL-27915: readBufferSize, writeBufferSize, and bulkRequests are propagated to the + * SftpClient.read()/write() calls rather than being silently dropped. + * <p> + * Before the fix, {@code configureBufferSizes} only called {@code SftpModuleProperties.set(session, ...)} which is + * consulted only by {@code SftpFileSystemProvider}, not by {@code SftpClient.read()/write()}. The transfer calls always + * used zero-bufferSize overloads, ignoring the configured sizes. The effective buffer sizes were never stored anywhere + * accessible to the read/write call sites. + * <p> + * After the fix, the effective buffer sizes are stored in {@code effectiveReadBufferSize} and + * {@code effectiveWriteBufferSize} fields and passed directly to {@code read(name, bufferSize)} and + * {@code write(name, bufferSize, modes)}. + */ +class MinaSftpOperationsBufferSizeTest { + + /** + * Verifies that an explicit readBufferSize is captured in effectiveReadBufferSize. + */ + @Test + void testExplicitReadBufferSizePropagated() throws Exception { + MinaSftpConfiguration config = new MinaSftpConfiguration(); + config.setReadBufferSize(65536); + + MinaSftpOperations ops = new MinaSftpOperations(); + invokeConfigureBufferSizes(ops, config); + + assertEquals(65536, getIntField(ops, "effectiveReadBufferSize"), + "effectiveReadBufferSize must hold the configured readBufferSize (CAMEL-27915)"); + } + + /** + * Verifies that an explicit writeBufferSize is captured in effectiveWriteBufferSize. + */ + @Test + void testExplicitWriteBufferSizePropagated() throws Exception { + MinaSftpConfiguration config = new MinaSftpConfiguration(); + config.setWriteBufferSize(98304); + + MinaSftpOperations ops = new MinaSftpOperations(); + invokeConfigureBufferSizes(ops, config); + + assertEquals(98304, getIntField(ops, "effectiveWriteBufferSize"), + "effectiveWriteBufferSize must hold the configured writeBufferSize (CAMEL-27915)"); + } + + /** + * Verifies that when neither size is configured, the effective sizes are 0 (meaning MINA SSHD picks its own default + * for read/write). + */ + @Test + void testDefaultBufferSizesAreZero() throws Exception { + MinaSftpConfiguration config = new MinaSftpConfiguration(); + + MinaSftpOperations ops = new MinaSftpOperations(); + invokeConfigureBufferSizes(ops, config); + + assertEquals(0, getIntField(ops, "effectiveReadBufferSize"), + "effectiveReadBufferSize must be 0 when not configured (MINA SSHD uses its own default)"); + assertEquals(0, getIntField(ops, "effectiveWriteBufferSize"), + "effectiveWriteBufferSize must be 0 when not configured (MINA SSHD uses its own default)"); + } + + /** + * Verifies backward compatibility: bulkRequests sets both effective buffer sizes when neither explicit size is set. + * Each bulk request corresponds to 32 KB, capped at the internal MAX_BUFFER_SIZE (126 * 1024 + 512 = 129024). Review Comment: Fixed in a9ea736: the Javadoc now says 129536, as the assertions do. _Claude Code on behalf of davsclaus_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
