You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/02/17 08:05:48 UTC

[GitHub] [ignite] l4ndsc4pe commented on a change in pull request #7394: IGNITE-10698: Get rid of @MXBeanParametersNames and @MXBeanParametersDescriptions

l4ndsc4pe commented on a change in pull request #7394: IGNITE-10698: Get rid of @MXBeanParametersNames and @MXBeanParametersDescriptions
URL: https://github.com/apache/ignite/pull/7394#discussion_r380030387
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/mxbean/IgniteStandardMXBeanTest.java
 ##########
 @@ -0,0 +1,576 @@
+/*
+ * 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.ignite.internal.mxbean;
+
+import java.lang.reflect.Method;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.NotCompliantMBeanException;
+import org.apache.ignite.mxbean.MXBeanParameterInfo;
+import org.apache.ignite.mxbean.MXBeanParametersDescriptions;
+import org.apache.ignite.mxbean.MXBeanParametersNames;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Contains tests for IgniteStandardMXBean methods.
+ */
+public class IgniteStandardMXBeanTest {
+
+    /** */
+    private static final String NAME = "Name";
+
+    /** */
+    private static final String TYPE = "Type";
+
+    /** */
+    private static final String OPERATION_INFO_DESCRIPTION = "Operation info description";
+
+    /** */
+    private static final String PARAMETER_INFO_DESCRIPTION = "Parameter info description";
+
+    /** */
+    private static final String EMPTY_STRING = "";
+
+    /** */
+    private static final String TEST_METHOD_1 = "testMethod1";
+
+    /** */
+    private static final String TEST_METHOD_2 = "testMethod2";
+
+    /** */
+    private static final String TEST_METHOD_3 = "testMethod3";
+
+    /** */
+    private static final String TEST_METHOD_4 = "testMethod4";
+
+    /** */
+    private static final String TEST_METHOD_5 = "testMethod5";
+
+    /** */
+    private static final String TEST_METHOD_6 = "testMethod6";
+
+    /** */
+    private static final String TEST_METHOD_7 = "testMethod7";
+
+    /** */
+    private static final String TEST_METHOD_8 = "testMethod8";
+
+    /** */
+    private static final String TEST_METHOD_9 = "testMethod9";
+
+    /** */
+    private static final String TEST_METHOD_10 = "testMethod10";
+
+    /** */
+    private static final String FIRST_DESCRIPTION_PARAM_ANNOTATION = "First description parameter annotation.";
+
+    /** */
+    private static final String FIRST_DESCRIPTION_METHOD_ANNOTATION = "First description method annotation.";
+
+    /** */
+    private static final String SECOND_DESCRIPTION_PARAM_ANNOTATION = "Second description parameter annotation.";
+
+    /** */
+    private static final String SECOND_DESCRIPTION_METHOD_ANNOTATION = "Second description method annotation.";
+
+    /** */
+    private static final String FIRST_NAME_PARAM_ANNOTATION = "First name parameter annotation";
+
+    /** */
+    private static final String FIRST_NAME_METHOD_ANNOTATION = "First name method annotation";
+
+    /** */
+    private static final String SECOND_NAME_PARAM_ANNOTATION = "Second name parameter annotation";
+
+    /** */
+    private static final String SECOND_NAME_METHOD_ANNOTATION = "Second name method annotation";
+
+    /** */
+    private static final String FIRST_LOWERCASE_LETTER = "first lowercase letter.";
+
+    /** */
+    private static final String NO_DOT_AT_THE_END_OF_THE_STRING = "No dot at the end of the string";
+
+    /** */
+    private static final int ZERO_INDEX = 0;
+
+    /** */
+    private static final int FIRST_INDEX = 1;
+
+    /**
+     * Instance of IgniteStandardMXBean.
+     */
+    private final IgniteStandardMXBean igniteStandardMXBean;
+
+    /**
+     * Instance of MBeanParameterInfo.
+     */
+    private final MBeanParameterInfo parameterInfo;
+
+    /**
+     * Public constructor that initializes instances of IgniteStandardMXBean and MBeanParameterInfo classes.
+     */
+    public IgniteStandardMXBeanTest() throws NotCompliantMBeanException {
+        TestInterfaceImpl testInterfaceImpl = new TestInterfaceImpl();
+        igniteStandardMXBean = new IgniteStandardMXBean(testInterfaceImpl, TestInterface.class);
+        parameterInfo = new MBeanParameterInfo(NAME, TYPE, PARAMETER_INFO_DESCRIPTION);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * All annotation parameters are valid.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getDescription_OldAnnotation() throws NoSuchMethodException {
+        String actualResult = getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_1, FIRST_INDEX);
+
+        assertEquals(SECOND_DESCRIPTION_METHOD_ANNOTATION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * An empty array is used as parameters in the annotation resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_OldAnnotationEmptyValueArray() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_2, FIRST_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * An array whose length is less than transmitted parameter index is used as a parameter
+     * resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_OldAnnotationValueLengthLessThenParamIndex() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_3, FIRST_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * Empty description parameter value resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_OldAnnotationEmptyParamValue() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_4, ZERO_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * Description parameter without a dot at the end of the sentence resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_OldAnnotationNoDotAtTheEndOfTheString() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_5, ZERO_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * Description parameter starts with a lowercase letter resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_OldAnnotationFirstLowercaseLetter() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_5, FIRST_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only new annotations.
+     * All annotation parameters are valid.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getDescription_NewAnnotation() throws NoSuchMethodException {
+        String actualResult = getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_6, FIRST_INDEX);
+
+        assertEquals(SECOND_DESCRIPTION_PARAM_ANNOTATION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only new annotations.
+     * Empty description parameter value resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_NewAnnotationEmptyParamValue() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_7, ZERO_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only new annotation.
+     * Description parameter without a dot at the end of the sentence resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_NewAnnotationNoDotAtTheEndOfTheString() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_8, ZERO_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only new annotations.
+     * Description parameter starts with a lowercase letter resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getDescription_NewAnnotationFirstLowercaseLetter() throws NoSuchMethodException {
+        getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_8, FIRST_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has both old and new annotations.
+     * All annotations parameters are valid.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getDescription_BothOldAndNewAnnotations() throws NoSuchMethodException {
+        String actualResult = getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_9, FIRST_INDEX);
+
+        assertEquals(SECOND_DESCRIPTION_METHOD_ANNOTATION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has no annotations at all.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getDescription_NoAnnotations() throws NoSuchMethodException {
+        String actualResult = getDescriptionWithMethodNameAndParamIndex(TEST_METHOD_10, FIRST_INDEX);
+
+        assertEquals(PARAMETER_INFO_DESCRIPTION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only the old annotation.
+     * All annotation parameters are valid.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getParameterName_OldAnnotation() throws NoSuchMethodException {
+        String actualResult = getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_1, FIRST_INDEX);
+
+        assertEquals(SECOND_NAME_METHOD_ANNOTATION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * An empty array is used as parameters in the annotation resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getParameterName_OldAnnotationEmptyValueArray() throws NoSuchMethodException {
+        getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_2, FIRST_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * An array whose length is less than transmitted parameter index is used as a parameter
+     * resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getParameterName_OldAnnotationValueLengthLessThenParamIndex() throws NoSuchMethodException {
+        getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_3, FIRST_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only old annotation.
+     * Empty parameter name value resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getParameterName_OldAnnotationEmptyParamValue() throws NoSuchMethodException {
+        getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_4, ZERO_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only new annotations.
+     * All annotation parameters are valid.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getParameterName_NewAnnotation() throws NoSuchMethodException {
+        String actualResult = getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_6, FIRST_INDEX);
+
+        assertEquals(SECOND_NAME_PARAM_ANNOTATION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has only new annotations.
+     * Empty parameter name value resulting in an AssertionError.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test(expected = AssertionError.class)
+    public void getParameterName_NewAnnotationEmptyParamValue() throws NoSuchMethodException {
+        getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_7, ZERO_INDEX);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has both old and new annotations.
+     * All annotations parameters are valid.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getParameterName_BothOldAndNewAnnotations() throws NoSuchMethodException {
+        String actualResult = getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_9, FIRST_INDEX);
+
+        assertEquals(SECOND_NAME_METHOD_ANNOTATION, actualResult);
+    }
+
+    /**
+     * A test method that represents a situation in which the method has no annotations at all.
+     *
+     * @throws NoSuchMethodException if method is not found.
+     */
+    @Test
+    public void getParameterName_NoAnnotations() throws NoSuchMethodException {
+        String actualResult = getParameterNameWithMethodNameAndParamIndex(TEST_METHOD_10, FIRST_INDEX);
+
+        assertEquals(NAME, actualResult);
+    }
+
+    /**
+     * Utility method that returns the description for method argument by method name and parameter index.
+     *
+     * @param methodName method name from interface TestInterface.
+     * @param paramIndex the sequence number of the argument considered.
+     * @return the description for method argument.
+     * @throws NoSuchMethodException if a matching method is not found.
+     */
+    private String getDescriptionWithMethodNameAndParamIndex(String methodName, int paramIndex)
+        throws NoSuchMethodException {
+        MBeanOperationInfo operationInfo = getMBeanOperationInfoWithMehtodName(methodName);
+        return igniteStandardMXBean.getDescription(operationInfo, parameterInfo, paramIndex);
+    }
+
+    /**
+     * Utility method that returns the name for method argument by method name and parameter index.
+     *
+     * @param methodName method name from interface TestInterface.
+     * @param paramIndex the sequence number of the argument considered.
+     * @return the name for method argument.
+     * @throws NoSuchMethodException if a matching method is not found.
+     */
+    private String getParameterNameWithMethodNameAndParamIndex(String methodName, int paramIndex)
+        throws NoSuchMethodException {
+        MBeanOperationInfo operationInfo = getMBeanOperationInfoWithMehtodName(methodName);
+        return igniteStandardMXBean.getParameterName(operationInfo, parameterInfo, paramIndex);
+    }
+
+    /**
+     * Utility method for getting instance of MBeanOperationInfo constructed with default description from TestInterface
+     * by its method name.
+     *
+     * @param methodName method name from interface TestInterface.
+     * @return MBeanOperationInfo.
+     * @throws NoSuchMethodException if a matching method is not found.
+     */
+    private MBeanOperationInfo getMBeanOperationInfoWithMehtodName(String methodName) throws NoSuchMethodException {
+        Method method = TestInterfaceImpl.class.getDeclaredMethod(methodName, String.class, String.class);
+        return new MBeanOperationInfo(OPERATION_INFO_DESCRIPTION, method);
+    }
+
+    /**
+     * Interface used for testing.
+     */
+    public static interface TestInterface {
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        @MXBeanParametersNames({FIRST_NAME_METHOD_ANNOTATION, SECOND_NAME_METHOD_ANNOTATION})
+        @MXBeanParametersDescriptions({FIRST_DESCRIPTION_METHOD_ANNOTATION, SECOND_DESCRIPTION_METHOD_ANNOTATION})
+        void testMethod1(String firstParam, String secondParam);
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        @MXBeanParametersNames({})
+        @MXBeanParametersDescriptions({})
+        void testMethod2(String firstParam, String secondParam);
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        @MXBeanParametersNames({FIRST_NAME_METHOD_ANNOTATION})
+        @MXBeanParametersDescriptions({FIRST_DESCRIPTION_METHOD_ANNOTATION})
+        void testMethod3(String firstParam, String secondParam);
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        @MXBeanParametersNames({EMPTY_STRING})
+        @MXBeanParametersDescriptions({EMPTY_STRING})
+        void testMethod4(String firstParam, String secondParam);
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        @MXBeanParametersNames({FIRST_NAME_METHOD_ANNOTATION, SECOND_NAME_METHOD_ANNOTATION})
+        @MXBeanParametersDescriptions({NO_DOT_AT_THE_END_OF_THE_STRING, FIRST_LOWERCASE_LETTER})
+        void testMethod5(String firstParam, String secondParam);
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        void testMethod6(
+            @MXBeanParameterInfo(name = FIRST_NAME_PARAM_ANNOTATION, description = FIRST_DESCRIPTION_PARAM_ANNOTATION)
+                String firstParam,
+            @MXBeanParameterInfo(name = SECOND_NAME_PARAM_ANNOTATION, description = SECOND_DESCRIPTION_PARAM_ANNOTATION)
+                String secondParam
+        );
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        void testMethod7(
+            @MXBeanParameterInfo(name = EMPTY_STRING, description = EMPTY_STRING)
+                String firstParam,
+            @MXBeanParameterInfo(name = SECOND_NAME_PARAM_ANNOTATION, description = SECOND_DESCRIPTION_PARAM_ANNOTATION)
+                String secondParam
+        );
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        void testMethod8(
+            @MXBeanParameterInfo(name = FIRST_NAME_PARAM_ANNOTATION, description = NO_DOT_AT_THE_END_OF_THE_STRING)
+                String firstParam,
+            @MXBeanParameterInfo(name = SECOND_NAME_PARAM_ANNOTATION, description = FIRST_LOWERCASE_LETTER)
+                String secondParam
+        );
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        @MXBeanParametersNames({FIRST_NAME_METHOD_ANNOTATION, SECOND_NAME_METHOD_ANNOTATION})
+        @MXBeanParametersDescriptions({FIRST_DESCRIPTION_METHOD_ANNOTATION, SECOND_DESCRIPTION_METHOD_ANNOTATION})
+        void testMethod9(
+            @MXBeanParameterInfo(name = FIRST_NAME_PARAM_ANNOTATION, description = NO_DOT_AT_THE_END_OF_THE_STRING)
+                String firstParam,
+            @MXBeanParameterInfo(name = SECOND_NAME_PARAM_ANNOTATION, description = FIRST_LOWERCASE_LETTER)
+                String secondParam
+        );
+
+        /**
+         * Method used for testing.
+         *
+         * @param firstParam first string method parameter.
+         * @param secondParam second string method parameter.
+         */
+        void testMethod10(String firstParam, String secondParam);
+    }
+
+    /**
+     * Test interface implementation.
+     */
+    private static class TestInterfaceImpl implements TestInterface {
+
+        /** {@inheritDoc} */
+        @Override public void testMethod1(String firstParam, String secondParam) {
 
 Review comment:
   Done.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services