nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbe...@apache.org
Subject [nifi] 01/02: NIFI-7929: connectionTimeout and readTimeout options are not exposed in the CLI
Date Tue, 27 Oct 2020 14:18:33 GMT
This is an automated email from the ASF dual-hosted git repository.

bbende pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit dc25d4c39e731a0170f3ad76e8700a2b7c72c30c
Author: Denes Arvay <denes@apache.org>
AuthorDate: Tue Oct 20 16:12:04 2020 +0200

    NIFI-7929: connectionTimeout and readTimeout options are not exposed in the CLI
    
    Signed-off-by: Bryan Bende <bbende@apache.org>
---
 .../client/JerseyExtendedNiFiRegistryClient.java   |   0
 .../impl/client/nifi/impl/JerseyNiFiClient.java    |   4 +-
 .../toolkit/cli/impl/command/AbstractCommand.java  |   3 +
 .../toolkit/cli/impl/client/TestClientTimeout.java | 129 +++++++++++++++++++++
 4 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/JerseyExtendedNiFiRegistryClient.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/JerseyExtendedNiFiRegistryClient.java
new file mode 100644
index 0000000..e69de29
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyNiFiClient.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyNiFiClient.java
index 1b7187e..377d28a 100644
--- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyNiFiClient.java
+++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyNiFiClient.java
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.toolkit.cli.impl.client.nifi.AccessClient;
 import org.apache.nifi.toolkit.cli.impl.client.nifi.ConnectionClient;
@@ -62,7 +63,8 @@ public class JerseyNiFiClient implements NiFiClient {
     static final int DEFAULT_CONNECT_TIMEOUT = 10000;
     static final int DEFAULT_READ_TIMEOUT = 10000;
 
-    private final Client client;
+    @VisibleForTesting
+    public final Client client;
     private final WebTarget baseTarget;
 
     private JerseyNiFiClient(final Builder builder) {
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/AbstractCommand.java
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/AbstractCommand.java
index 2d6735f..efb3a42 100644
--- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/AbstractCommand.java
+++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/AbstractCommand.java
@@ -66,6 +66,9 @@ public abstract class AbstractCommand<R extends Result> implements
Command<R> {
         options.addOption(CommandOption.URL.createOption());
         options.addOption(CommandOption.PROPERTIES.createOption());
 
+        options.addOption(CommandOption.CONNECTION_TIMEOUT.createOption());
+        options.addOption(CommandOption.READ_TIMEOUT.createOption());
+
         options.addOption(CommandOption.KEYSTORE.createOption());
         options.addOption(CommandOption.KEYSTORE_TYPE.createOption());
         options.addOption(CommandOption.KEYSTORE_PASSWORD.createOption());
diff --git a/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/client/TestClientTimeout.java
b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/client/TestClientTimeout.java
new file mode 100644
index 0000000..fb60d62
--- /dev/null
+++ b/nifi-toolkit/nifi-toolkit-cli/src/test/java/org/apache/nifi/toolkit/cli/impl/client/TestClientTimeout.java
@@ -0,0 +1,129 @@
+/*
+ * 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.toolkit.cli.impl.client;
+
+import org.apache.nifi.registry.client.NiFiRegistryClient;
+import org.apache.nifi.toolkit.cli.api.ClientFactory;
+import org.apache.nifi.toolkit.cli.api.Command;
+import org.apache.nifi.toolkit.cli.api.Context;
+import org.apache.nifi.toolkit.cli.api.Result;
+import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient;
+import org.apache.nifi.toolkit.cli.impl.client.nifi.impl.JerseyNiFiClient;
+import org.apache.nifi.toolkit.cli.impl.command.CommandProcessor;
+import org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand;
+import org.apache.nifi.toolkit.cli.impl.command.registry.AbstractNiFiRegistryCommand;
+import org.apache.nifi.toolkit.cli.impl.context.StandardContext;
+import org.apache.nifi.toolkit.cli.impl.session.InMemorySession;
+import org.glassfish.jersey.client.ClientProperties;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import javax.ws.rs.client.Client;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+
+public class TestClientTimeout {
+
+    private Context context;
+    private ClientFactory<NiFiClient> nifiClientFactory;
+    private ClientFactory<NiFiRegistryClient> nifiRegClientFactory;
+    private final Client[] client = new Client[1];
+
+    @Before
+    public void setUp() throws Exception {
+        nifiClientFactory = Mockito.spy(new NiFiClientFactory());
+        Mockito.doAnswer(invocationOnMock -> {
+            final JerseyNiFiClient nifiClient = Mockito.spy((JerseyNiFiClient) invocationOnMock.callRealMethod());
+            Mockito.doNothing().when(nifiClient).close(); // avoid closing the client before
getting the configuration in the test method
+            client[0] = nifiClient.client;
+            return nifiClient;
+        }).when(nifiClientFactory).createClient(Mockito.any(Properties.class));
+
+        nifiRegClientFactory = Mockito.spy(new NiFiRegistryClientFactory());
+        Mockito.doAnswer(invocationOnMock -> {
+            final JerseyExtendedNiFiRegistryClient nifiRegistryClient = Mockito.spy((JerseyExtendedNiFiRegistryClient)
invocationOnMock.callRealMethod());
+            Mockito.doNothing().when(nifiRegistryClient).close(); // avoid closing the client
before getting the configuration in the test method
+            client[0] = nifiRegistryClient.client;
+            return nifiRegistryClient;
+        }).when(nifiRegClientFactory).createClient(Mockito.any(Properties.class));
+
+        context = new StandardContext.Builder()
+                .output(System.out)
+                .session(new InMemorySession())
+                .nifiClientFactory(nifiClientFactory)
+                .nifiRegistryClientFactory(nifiRegClientFactory)
+                .interactive(false)
+                .build();
+    }
+
+    @After
+    public void tearDown() {
+        if (client[0] != null) {
+            try {
+                client[0].close();
+            } catch (Throwable th) {
+            }
+            client[0] = null;
+        }
+    }
+
+    @Test
+    public void testNiFiClientTimeoutSettings() {
+        testClientTimeoutSettings(new AbstractNiFiCommand<Result>("test", Result.class)
{
+            @Override
+            public Result doExecute(NiFiClient client, Properties properties) {
+                return null;
+            }
+
+            @Override
+            public String getDescription() {
+                return "";
+            }
+        });
+    }
+
+    @Test
+    public void testNiFiRegistryClientTimeoutSettings() {
+        testClientTimeoutSettings(new AbstractNiFiRegistryCommand<Result>("test", Result.class)
{
+            @Override
+            public Result doExecute(NiFiRegistryClient client, Properties properties) {
+                return null;
+            }
+
+            @Override
+            public String getDescription() {
+                return "";
+            }
+        });
+    }
+
+    private void testClientTimeoutSettings(Command<?> command) {
+        command.initialize(context);
+        final CommandProcessor processor = new CommandProcessor(Collections.singletonMap("test",
command), Collections.emptyMap(), context);
+        processor.process(new String[] { "test", "-cto", "1", "-rto", "2", "-baseUrl", "http://localhost:9999"
});
+
+        Assert.assertNotNull(client[0]);
+        final Map<String, Object> clientProperties = client[0].getConfiguration().getProperties();
+        Assert.assertEquals(1, clientProperties.get(ClientProperties.CONNECT_TIMEOUT));
+        Assert.assertEquals(2, clientProperties.get(ClientProperties.READ_TIMEOUT));
+    }
+
+}


Mime
View raw message