wojtre commented on code in PR #11894:
URL: https://github.com/apache/nifi/pull/11894#discussion_r4494043170


##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-service-shared/src/test/java/org/apache/nifi/kafka/service/Kafka3ConnectionServiceTest.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.nifi.kafka.service;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockConfigurationContext;
+import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.NoOpProcessor;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+class Kafka3ConnectionServiceTest {
+
+    private static final String SERVICE_ID = 
Kafka3ConnectionService.class.getSimpleName();
+
+    private static final String BOOTSTRAP_SERVERS = "localhost:9092";
+
+    private static final String MAX_PARTITION_FETCH_BYTES = "262144";
+
+    private static final String FETCH_MAX_BYTES = "10000000";
+
+    private TestRunner runner;
+
+    private Kafka3ConnectionService service;
+
+    @BeforeEach
+    void setRunner() throws InitializationException {
+        runner = TestRunners.newTestRunner(NoOpProcessor.class);
+        service = new Kafka3ConnectionService();
+        runner.addControllerService(SERVICE_ID, service);
+        runner.setProperty(service, Kafka3ConnectionService.BOOTSTRAP_SERVERS, 
BOOTSTRAP_SERVERS);
+    }
+
+    @Test
+    void testFetchSizeDefaultsInConsumerProperties() {
+        runner.assertValid(service);
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        
assertEquals(String.valueOf(ConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES), 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(String.valueOf(ConsumerConfig.DEFAULT_FETCH_MAX_BYTES), 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizeConfiguredInConsumerProperties() {
+        runner.setProperty(service, 
Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, Kafka3ConnectionService.FETCH_MAX_BYTES, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        assertEquals(MAX_PARTITION_FETCH_BYTES, 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(FETCH_MAX_BYTES, 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizePropertyNamesResolveToSupportedDescriptors() {
+        runner.setProperty(service, 
ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, ConsumerConfig.FETCH_MAX_BYTES_CONFIG, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final PropertyDescriptor maxPartitionFetchBytes = 
getConfiguredDescriptor(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG);
+        assertSame(Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, 
maxPartitionFetchBytes);
+        assertFalse(maxPartitionFetchBytes.isDynamic());
+
+        final PropertyDescriptor fetchMaxBytes = 
getConfiguredDescriptor(ConsumerConfig.FETCH_MAX_BYTES_CONFIG);
+        assertSame(Kafka3ConnectionService.FETCH_MAX_BYTES, fetchMaxBytes);
+        assertFalse(fetchMaxBytes.isDynamic());
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        assertEquals(MAX_PARTITION_FETCH_BYTES, 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(FETCH_MAX_BYTES, 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizeNotInProducerProperties() {

Review Comment:
   Removed.



##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-service-shared/src/test/java/org/apache/nifi/kafka/service/Kafka3ConnectionServiceTest.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.nifi.kafka.service;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockConfigurationContext;
+import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.NoOpProcessor;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+class Kafka3ConnectionServiceTest {
+
+    private static final String SERVICE_ID = 
Kafka3ConnectionService.class.getSimpleName();
+
+    private static final String BOOTSTRAP_SERVERS = "localhost:9092";
+
+    private static final String MAX_PARTITION_FETCH_BYTES = "262144";
+
+    private static final String FETCH_MAX_BYTES = "10000000";
+
+    private TestRunner runner;
+
+    private Kafka3ConnectionService service;
+
+    @BeforeEach
+    void setRunner() throws InitializationException {
+        runner = TestRunners.newTestRunner(NoOpProcessor.class);
+        service = new Kafka3ConnectionService();
+        runner.addControllerService(SERVICE_ID, service);
+        runner.setProperty(service, Kafka3ConnectionService.BOOTSTRAP_SERVERS, 
BOOTSTRAP_SERVERS);
+    }
+
+    @Test
+    void testFetchSizeDefaultsInConsumerProperties() {
+        runner.assertValid(service);
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        
assertEquals(String.valueOf(ConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES), 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(String.valueOf(ConsumerConfig.DEFAULT_FETCH_MAX_BYTES), 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizeConfiguredInConsumerProperties() {
+        runner.setProperty(service, 
Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, Kafka3ConnectionService.FETCH_MAX_BYTES, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        assertEquals(MAX_PARTITION_FETCH_BYTES, 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(FETCH_MAX_BYTES, 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizePropertyNamesResolveToSupportedDescriptors() {
+        runner.setProperty(service, 
ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, ConsumerConfig.FETCH_MAX_BYTES_CONFIG, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final PropertyDescriptor maxPartitionFetchBytes = 
getConfiguredDescriptor(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG);
+        assertSame(Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, 
maxPartitionFetchBytes);
+        assertFalse(maxPartitionFetchBytes.isDynamic());
+
+        final PropertyDescriptor fetchMaxBytes = 
getConfiguredDescriptor(ConsumerConfig.FETCH_MAX_BYTES_CONFIG);
+        assertSame(Kafka3ConnectionService.FETCH_MAX_BYTES, fetchMaxBytes);
+        assertFalse(fetchMaxBytes.isDynamic());
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        assertEquals(MAX_PARTITION_FETCH_BYTES, 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(FETCH_MAX_BYTES, 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizeNotInProducerProperties() {
+        runner.setProperty(service, 
Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, Kafka3ConnectionService.FETCH_MAX_BYTES, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final MockConfigurationContext configurationContext = 
getConfigurationContext();
+        final Properties clientProperties = 
service.getClientProperties(configurationContext);
+        final Properties producerProperties = 
service.getProducerProperties(configurationContext, clientProperties);
+
+        
assertFalse(producerProperties.containsKey(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        
assertFalse(producerProperties.containsKey(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"-1", "1 MB", "unlimited"})
+    void testMaxPartitionFetchBytesNotValid(final String value) {

Review Comment:
   Removed both.



##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-service-shared/src/test/java/org/apache/nifi/kafka/service/Kafka3ConnectionServiceTest.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.nifi.kafka.service;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockConfigurationContext;
+import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.NoOpProcessor;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+class Kafka3ConnectionServiceTest {
+
+    private static final String SERVICE_ID = 
Kafka3ConnectionService.class.getSimpleName();
+
+    private static final String BOOTSTRAP_SERVERS = "localhost:9092";
+
+    private static final String MAX_PARTITION_FETCH_BYTES = "262144";
+
+    private static final String FETCH_MAX_BYTES = "10000000";
+
+    private TestRunner runner;
+
+    private Kafka3ConnectionService service;
+
+    @BeforeEach
+    void setRunner() throws InitializationException {
+        runner = TestRunners.newTestRunner(NoOpProcessor.class);
+        service = new Kafka3ConnectionService();
+        runner.addControllerService(SERVICE_ID, service);
+        runner.setProperty(service, Kafka3ConnectionService.BOOTSTRAP_SERVERS, 
BOOTSTRAP_SERVERS);
+    }
+
+    @Test
+    void testFetchSizeDefaultsInConsumerProperties() {
+        runner.assertValid(service);
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        
assertEquals(String.valueOf(ConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES), 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(String.valueOf(ConsumerConfig.DEFAULT_FETCH_MAX_BYTES), 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizeConfiguredInConsumerProperties() {
+        runner.setProperty(service, 
Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, Kafka3ConnectionService.FETCH_MAX_BYTES, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        assertEquals(MAX_PARTITION_FETCH_BYTES, 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(FETCH_MAX_BYTES, 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizePropertyNamesResolveToSupportedDescriptors() {
+        runner.setProperty(service, 
ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, ConsumerConfig.FETCH_MAX_BYTES_CONFIG, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final PropertyDescriptor maxPartitionFetchBytes = 
getConfiguredDescriptor(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG);
+        assertSame(Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, 
maxPartitionFetchBytes);
+        assertFalse(maxPartitionFetchBytes.isDynamic());
+
+        final PropertyDescriptor fetchMaxBytes = 
getConfiguredDescriptor(ConsumerConfig.FETCH_MAX_BYTES_CONFIG);
+        assertSame(Kafka3ConnectionService.FETCH_MAX_BYTES, fetchMaxBytes);
+        assertFalse(fetchMaxBytes.isDynamic());
+
+        final Properties consumerProperties = getConsumerProperties();
+
+        assertEquals(MAX_PARTITION_FETCH_BYTES, 
consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        assertEquals(FETCH_MAX_BYTES, 
consumerProperties.get(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @Test
+    void testFetchSizeNotInProducerProperties() {
+        runner.setProperty(service, 
Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, MAX_PARTITION_FETCH_BYTES);
+        runner.setProperty(service, Kafka3ConnectionService.FETCH_MAX_BYTES, 
FETCH_MAX_BYTES);
+        runner.assertValid(service);
+
+        final MockConfigurationContext configurationContext = 
getConfigurationContext();
+        final Properties clientProperties = 
service.getClientProperties(configurationContext);
+        final Properties producerProperties = 
service.getProducerProperties(configurationContext, clientProperties);
+
+        
assertFalse(producerProperties.containsKey(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
+        
assertFalse(producerProperties.containsKey(ConsumerConfig.FETCH_MAX_BYTES_CONFIG));
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"-1", "1 MB", "unlimited"})
+    void testMaxPartitionFetchBytesNotValid(final String value) {
+        runner.setProperty(service, 
Kafka3ConnectionService.MAX_PARTITION_FETCH_BYTES, value);
+
+        runner.assertNotValid(service);
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"-1", "1 MB", "unlimited"})
+    void testFetchMaxBytesNotValid(final String value) {
+        runner.setProperty(service, Kafka3ConnectionService.FETCH_MAX_BYTES, 
value);
+
+        runner.assertNotValid(service);
+    }
+
+    private PropertyDescriptor getConfiguredDescriptor(final String 
propertyName) {
+        final MockProcessContext processContext = (MockProcessContext) 
runner.getProcessContext();
+        return 
processContext.getConfiguration(SERVICE_ID).getProperties().keySet().stream()
+                .filter(descriptor -> 
descriptor.getName().equals(propertyName))
+                .findFirst()
+                .orElseThrow();
+    }
+
+    private Properties getConsumerProperties() {
+        final MockConfigurationContext configurationContext = 
getConfigurationContext();
+        final Properties clientProperties = 
service.getClientProperties(configurationContext);
+        return service.getConsumerProperties(configurationContext, 
clientProperties);
+    }
+
+    private MockConfigurationContext getConfigurationContext() {
+        final MockProcessContext processContext = (MockProcessContext) 
runner.getProcessContext();
+
+        // The framework provides default values for all supported properties, 
while the runner provides only configured values
+        final Map<PropertyDescriptor, String> properties = new 
LinkedHashMap<>();

Review Comment:
   The map is gone. With the fetch sizes now put in explicitly, the helper no 
longer needs to fill in defaults, because `MockConfigurationContext` already 
falls back to the descriptor defaults. It passes the runner's configured 
properties straight through.



##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-service-aws/src/test/java/org/apache/nifi/kafka/service/aws/AmazonMSKConnectionServiceTest.java:
##########
@@ -117,6 +125,34 @@ void testWebIdentityWithTokenProviderAddsProperty() throws 
InitializationExcepti
         assertInstanceOf(AwsCredentialsProvider.class, provider);
     }
 
+    @Test
+    void testFetchSizePropertiesSupported() {

Review Comment:
   Removed both tests, along with the constants and imports. The test file is 
back to its state on main.



-- 
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]

Reply via email to