From 64d5282e22b0a780b27767148c5ac9e8fda313bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=80=E1=85=A7=E1=86=BC?= =?UTF-8?q?=E1=84=90=E1=85=A2?= Date: Fri, 18 Oct 2024 15:42:21 +0900 Subject: [PATCH 1/5] [ZEPPELIN-6131] elasticsearch.port string handling modification --- .../apache/zeppelin/elasticsearch/client/HttpBasedClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java index 94f9282789f..63bfebcec50 100644 --- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java +++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java @@ -64,7 +64,7 @@ public class HttpBasedClient implements ElasticsearchClient { public HttpBasedClient(Properties props) { this.protocol = loadProtocol(props); this.host = props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_HOST); - this.port = Integer.parseInt(props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_PORT)); + this.port = Integer.parseInt(props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_PORT).split("\\.")[0]); this.username = props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_BASIC_AUTH_USERNAME); this.password = props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_BASIC_AUTH_PASSWORD); } From 1efa15e2364c1d9fa02b48f22e6a93f11d6bfb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=80=E1=85=A7=E1=86=BC?= =?UTF-8?q?=E1=84=90=E1=85=A2?= Date: Wed, 30 Oct 2024 07:36:44 +0900 Subject: [PATCH 2/5] [ZEPPELIN-6131] Store as an integer when modifying the interpreter --- .../UpdateInterpreterSettingRequest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequest.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequest.java index 79cc1e19b56..ca7e76a0b9e 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequest.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequest.java @@ -39,10 +39,55 @@ public UpdateInterpreterSettingRequest(Map properti this.option = option; } + /** + * Retrieves the properties of the interpreter and, if the property type is "number" + * and its value is a double that represents a whole number, converts that value to an integer. + * + * @return A map of the interpreter's properties with possible modifications to the numeric properties. + */ public Map getProperties() { + properties.forEach((key, property) -> { + if (isNumberType(property) && isWholeNumberDouble(property.getValue())) { + convertDoubleToInt(property); + } + }); return properties; } + /** + * Checks if the property type is "number". + * + * @param property The InterpreterProperty to check. + * @return true if the property type is "number", false otherwise. + */ + private boolean isNumberType(InterpreterProperty property) { + return "number".equals(property.getType()); + } + + /** + * Checks if the given value is a Double and represents a whole number. + * + * @param value The object to check. + * @return true if the value is a Double and a whole number, false otherwise. + */ + private boolean isWholeNumberDouble(Object value) { + if (value instanceof Double) { + Double doubleValue = (Double) value; + return doubleValue == Math.floor(doubleValue); + } + return false; + } + + /** + * Converts the value of the given property from a Double to an Integer if the Double represents a whole number. + * + * @param property The InterpreterProperty whose value will be converted. + */ + private void convertDoubleToInt(InterpreterProperty property) { + Double doubleValue = (Double) property.getValue(); + property.setValue(doubleValue.intValue()); + } + public List getDependencies() { return dependencies; } From d54bd43eb8f4974d6328473a236ec0b4721ac890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=80=E1=85=A7=E1=86=BC?= =?UTF-8?q?=E1=84=90=E1=85=A2?= Date: Wed, 30 Oct 2024 07:38:44 +0900 Subject: [PATCH 3/5] [ZEPPELIN-6131] Revert modifications --- .../apache/zeppelin/elasticsearch/client/HttpBasedClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java index 63bfebcec50..94f9282789f 100644 --- a/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java +++ b/elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/HttpBasedClient.java @@ -64,7 +64,7 @@ public class HttpBasedClient implements ElasticsearchClient { public HttpBasedClient(Properties props) { this.protocol = loadProtocol(props); this.host = props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_HOST); - this.port = Integer.parseInt(props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_PORT).split("\\.")[0]); + this.port = Integer.parseInt(props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_PORT)); this.username = props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_BASIC_AUTH_USERNAME); this.password = props.getProperty(ElasticsearchInterpreter.ELASTICSEARCH_BASIC_AUTH_PASSWORD); } From 9b2d0199990bd874f8d9869147c702e4976f08a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=80=E1=85=A7=E1=86=BC?= =?UTF-8?q?=E1=84=90=E1=85=A2?= Date: Sat, 2 Nov 2024 11:58:24 +0900 Subject: [PATCH 4/5] [ZEPPELIN-6131] add UpdateInterpreterSettingRequestTest --- .../UpdateInterpreterSettingRequestTest.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java new file mode 100644 index 00000000000..7e0aab92b7f --- /dev/null +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java @@ -0,0 +1,114 @@ +/* + * 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.zeppelin.rest.message; + +import org.apache.zeppelin.dep.Dependency; +import org.apache.zeppelin.interpreter.InterpreterOption; +import org.apache.zeppelin.interpreter.InterpreterProperty; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * Unit test class for the UpdateInterpreterSettingRequest. + * This class tests the behavior of UpdateInterpreterSettingRequest methods, + * especially focusing on property type handling and value conversions. + */ +class UpdateInterpreterSettingRequestTest { + + private Map properties; + private List dependencies; + private InterpreterOption option; + private UpdateInterpreterSettingRequest request; + + /** + * Setup method that initializes test fixtures before each test. + * Mocks dependencies and option objects to isolate UpdateInterpreterSettingRequest behavior. + */ + @BeforeEach + void setUp() { + properties = new HashMap<>(); + dependencies = mock(List.class); + option = mock(InterpreterOption.class); + request = new UpdateInterpreterSettingRequest(properties, dependencies, option); + } + + /** + * Tests getProperties method to verify that properties with "number" type + * and whole-number Double values are correctly converted to Integer. + * Verifies that only whole-number Doubles are converted and non-integer Doubles remain unchanged. + */ + @Test + void testGetPropertiesWithWholeNumberDoubleConversion() { + InterpreterProperty property1 = mock(InterpreterProperty.class); + when(property1.getType()).thenReturn("number"); + when(property1.getValue()).thenReturn(5.0); + + InterpreterProperty property2 = mock(InterpreterProperty.class); + when(property2.getType()).thenReturn("number"); + when(property2.getValue()).thenReturn(5.5); + + properties.put("property1", property1); + properties.put("property2", property2); + + Map resultProperties = request.getProperties(); + + verify(property1).setValue(5); + verify(property2, never()).setValue(any()); + assertEquals(properties, resultProperties); + } + + /** + * Tests getProperties method when the property type is not "number". + * Verifies that no conversion is performed on non-number types. + */ + @Test + void testGetPropertiesWithoutConversion() { + InterpreterProperty property = mock(InterpreterProperty.class); + when(property.getType()).thenReturn("string"); + when(property.getValue()).thenReturn("test"); + + properties.put("property", property); + + Map resultProperties = request.getProperties(); + + verify(property, never()).setValue(any()); + assertEquals(properties, resultProperties); + } + + /** + * Tests getDependencies method to confirm that it returns the correct dependencies list. + */ + @Test + void testGetDependencies() { + assertEquals(dependencies, request.getDependencies()); + } + + /** + * Tests getOption method to confirm that it returns the correct interpreter option. + */ + @Test + void testGetOption() { + assertEquals(option, request.getOption()); + } +} From 2e811181b62acf592d1953a21653569e428b7f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=80=E1=85=A7=E1=86=BC?= =?UTF-8?q?=E1=84=90=E1=85=A2?= Date: Mon, 11 Nov 2024 23:16:14 +0900 Subject: [PATCH 5/5] [ZEPPELIN-6131] Refactor dependencies initialization to use an empty list --- .../rest/message/UpdateInterpreterSettingRequestTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java index 7e0aab92b7f..1ecf555ad7e 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/message/UpdateInterpreterSettingRequestTest.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,7 +49,7 @@ class UpdateInterpreterSettingRequestTest { @BeforeEach void setUp() { properties = new HashMap<>(); - dependencies = mock(List.class); + dependencies = Collections.emptyList(); option = mock(InterpreterOption.class); request = new UpdateInterpreterSettingRequest(properties, dependencies, option); }