http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBadArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBadArgs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBadArgs.java deleted file mode 100644 index 7b0586e..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBadArgs.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * 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.slider.client; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.hadoop.yarn.service.client.params.Arguments; -import org.apache.hadoop.yarn.service.client.params.SliderActions; -import org.apache.slider.core.exceptions.BadCommandArgumentsException; -import org.apache.slider.core.exceptions.ErrorStrings; -import org.apache.slider.core.exceptions.UsageException; -import org.apache.slider.utils.SliderTestBase; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; - -/** - * Test the argument parsing/validation logic. - */ -public class TestClientBadArgs extends SliderTestBase { - private static final Logger LOG = - LoggerFactory.getLogger(TestClientBadArgs.class); - - //@Test - public void testNoAction() throws Throwable { - launchExpectingException(SliderClient.class, - createTestConfig(), - "Usage: slider COMMAND", - EMPTY_LIST); - - } - - //@Test - public void testUnknownAction() throws Throwable { - launchExpectingException(SliderClient.class, - createTestConfig(), - "not-a-known-action", - Arrays.asList("not-a-known-action")); - } - - //@Test - public void testActionWithoutOptions() throws Throwable { - launchExpectingException(SliderClient.class, - createTestConfig(), - "Usage: slider build <application>", - Arrays.asList(SliderActions.ACTION_BUILD)); - } - - //@Test - public void testActionWithoutEnoughArgs() throws Throwable { - launchExpectingException(SliderClient.class, - createTestConfig(), - ErrorStrings.ERROR_NOT_ENOUGH_ARGUMENTS, - Arrays.asList(SliderActions.ACTION_START)); - } - - //@Test - public void testActionWithTooManyArgs() throws Throwable { - launchExpectingException(SliderClient.class, - createTestConfig(), - ErrorStrings.ERROR_TOO_MANY_ARGUMENTS, - Arrays.asList(SliderActions.ACTION_HELP, - "hello, world")); - } - - //@Test - public void testBadImageArg() throws Throwable { - launchExpectingException(SliderClient.class, - createTestConfig(), - "Unknown option: --image", - Arrays.asList(SliderActions.ACTION_HELP, - Arguments.ARG_IMAGE)); - } - - //@Test - public void testRegistryUsage() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "org.apache.slider.core.exceptions.UsageException: Argument --name " + - "missing", - Arrays.asList(SliderActions.ACTION_REGISTRY)); - assertTrue(exception instanceof UsageException); - LOG.info(exception.toString()); - } - - //@Test - public void testRegistryExportBadUsage1() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "Expected a value after parameter --getexp", - Arrays.asList(SliderActions.ACTION_REGISTRY, - Arguments.ARG_NAME, - "cl1", - Arguments.ARG_GETEXP)); - assertTrue(exception instanceof BadCommandArgumentsException); - LOG.info(exception.toString()); - } - - //@Test - public void testRegistryExportBadUsage2() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "Expected a value after parameter --getexp", - Arrays.asList(SliderActions.ACTION_REGISTRY, - Arguments.ARG_NAME, - "cl1", - Arguments.ARG_LISTEXP, - Arguments.ARG_GETEXP)); - assertTrue(exception instanceof BadCommandArgumentsException); - LOG.info(exception.toString()); - } - - //@Test - public void testRegistryExportBadUsage3() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "Usage: registry", - Arrays.asList(SliderActions.ACTION_REGISTRY, - Arguments.ARG_NAME, - "cl1", - Arguments.ARG_LISTEXP, - Arguments.ARG_GETEXP, - "export1")); - assertTrue(exception instanceof UsageException); - LOG.info(exception.toString()); - } - - //@Test - public void testUpgradeUsage() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "org.apache.slider.core.exceptions.BadCommandArgumentsException: Not " + - "enough arguments for action: upgrade Expected minimum 1 but got 0", - Arrays.asList(SliderActions.ACTION_UPGRADE)); - assertTrue(exception instanceof BadCommandArgumentsException); - LOG.info(exception.toString()); - } - - public Configuration createTestConfig() { - Configuration configuration = new Configuration(); - configuration.set(YarnConfiguration.RM_ADDRESS, "127.0.0.1:8032"); - return configuration; - } - - @Ignore - //@Test - public void testUpgradeWithTemplateResourcesAndContainersOption() throws - Throwable { - //TODO test upgrade args - String appName = "test_hbase"; - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "BadCommandArgumentsException: Option --containers cannot be " - + "specified with --appdef", - Arrays.asList(SliderActions.ACTION_UPGRADE, - appName, - Arguments.ARG_APPDEF, - "/tmp/app.json", - Arguments.ARG_CONTAINERS, - "container_1" - )); - assertTrue(exception instanceof BadCommandArgumentsException); - LOG.info(exception.toString()); - } - - @Ignore - //@Test - public void testUpgradeWithTemplateResourcesAndComponentsOption() throws - Throwable { - //TODO test upgrade args - String appName = "test_hbase"; - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "BadCommandArgumentsException: Option --components cannot be " - + "specified with --appdef", - Arrays.asList(SliderActions.ACTION_UPGRADE, - appName, - Arguments.ARG_APPDEF, - "/tmp/app.json", - Arguments.ARG_COMPONENTS, - "HBASE_MASTER" - )); - assertTrue(exception instanceof BadCommandArgumentsException); - LOG.info(exception.toString()); - } - - //@Test - public void testNodesMissingFile() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - createTestConfig(), - "after parameter --out", - Arrays.asList(SliderActions.ACTION_NODES, Arguments.ARG_OUTPUT)); - assertTrue(exception instanceof BadCommandArgumentsException); - } - - //@Test - public void testFlexWithNoComponents() throws Throwable { - Throwable exception = launchExpectingException(SliderClient.class, - new Configuration(), - "Usage: slider flex <application>", - Arrays.asList( - SliderActions.ACTION_FLEX, - "flex1", - Arguments.ARG_DEFINE, - YarnConfiguration.RM_ADDRESS + "=127.0.0.1:8032" - )); - assertTrue(exception instanceof UsageException); - LOG.info(exception.toString()); - } -}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBasicArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBasicArgs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBasicArgs.java deleted file mode 100644 index b29c581..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestClientBasicArgs.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.slider.client; - -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.hadoop.yarn.service.client.params.Arguments; -import org.apache.hadoop.yarn.service.client.params.ClientArgs; -import org.apache.slider.common.tools.SliderUtils; -import org.apache.slider.core.main.ServiceLauncher; -import org.apache.slider.utils.SliderTestBase; -import org.junit.Test; - -import java.net.UnknownHostException; -import java.util.Arrays; - -/** - * Test bad argument handling. - */ -public class TestClientBasicArgs extends SliderTestBase { - - /** - * Help should print out help string and then succeed. - * @throws Throwable - */ - //@Test - public void testHelp() throws Throwable { - ServiceLauncher launcher = launch(SliderClient.class, - SliderUtils.createConfiguration(), - Arrays.asList(ClientArgs.ACTION_HELP)); - assertEquals(0, launcher.getServiceExitCode()); - } - - //@Test - public void testNoArgs() throws Throwable { - launchExpectingException(SliderClient.class, - SliderUtils.createConfiguration(), - "Usage: slider COMMAND", - EMPTY_LIST); - } - - //@Test - public void testListUnknownRM() throws Throwable { - try { - YarnConfiguration conf = SliderUtils.createConfiguration(); - conf.setLong(YarnConfiguration.RESOURCEMANAGER_CONNECT_MAX_WAIT_MS, - 1000); - conf.setLong(YarnConfiguration - .RESOURCEMANAGER_CONNECT_RETRY_INTERVAL_MS, 1000); - ServiceLauncher launcher = launch(SliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_LIST, - "cluster", - Arguments.ARG_MANAGER, - "badhost:8888")); - fail("expected an exception, got a launcher with exit code " + - launcher.getServiceExitCode()); - } catch (UnknownHostException expected) { - //expected - } - - } - - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestCommonArgParsing.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestCommonArgParsing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestCommonArgParsing.java deleted file mode 100644 index 72960fa..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestCommonArgParsing.java +++ /dev/null @@ -1,522 +0,0 @@ -/* - * 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.slider.client; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.slider.api.ResourceKeys; -import org.apache.slider.api.RoleKeys; -import org.apache.hadoop.yarn.service.conf.SliderXmlConfKeys; -import org.apache.slider.common.params.AbstractClusterBuildingActionArgs; -import org.apache.hadoop.yarn.service.client.params.ActionBuildArgs; -import org.apache.hadoop.yarn.service.client.params.ActionCreateArgs; -import org.apache.hadoop.yarn.service.client.params.ActionDestroyArgs; -import org.apache.slider.common.params.ActionExistsArgs; -import org.apache.hadoop.yarn.service.client.params.ActionFlexArgs; -import org.apache.slider.common.params.ActionFreezeArgs; -import org.apache.slider.common.params.ActionListArgs; -import org.apache.slider.common.params.ActionStatusArgs; -import org.apache.slider.common.params.ActionThawArgs; -import org.apache.slider.common.params.ActionUpdateArgs; -import org.apache.hadoop.yarn.service.client.params.ArgOps; -import org.apache.hadoop.yarn.service.client.params.Arguments; -import org.apache.hadoop.yarn.service.client.params.ClientArgs; -import org.apache.hadoop.yarn.service.client.params.SliderActions; -import org.apache.slider.common.tools.SliderUtils; -import org.apache.slider.core.exceptions.BadCommandArgumentsException; -import org.apache.slider.core.exceptions.ErrorStrings; -import org.apache.slider.core.exceptions.SliderException; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * Test handling of common arguments, specifically how things get split up. - */ -public class TestCommonArgParsing implements SliderActions, Arguments { - - - public static final String CLUSTERNAME = "clustername"; - - //@Test - public void testCreateActionArgs() throws Throwable { - ClientArgs clientArgs = createClientArgs(Arrays.asList(ACTION_CREATE, - "cluster1")); - assertEquals("cluster1", clientArgs.getClusterName()); - } - - //@Test - public void testCreateFailsNoClustername() throws Throwable { - assertParseFails(Arrays.asList(ACTION_CREATE)); - } - - //@Test - public void testCreateFailsTwoClusternames() throws Throwable { - assertParseFails(Arrays.asList( - ACTION_CREATE, - "c1", - "c2" - )); - } - - //@Test - public void testHelp() throws Throwable { - ClientArgs clientArgs = createClientArgs(Arrays.asList(ACTION_HELP)); - assertNull(clientArgs.getClusterName()); - } - - //@Test - public void testSliderBasePath() throws Throwable { - ClientArgs clientArgs = createClientArgs(Arrays.asList(ACTION_LIST, - ARG_BASE_PATH, "/projects/slider/clusters")); - assertEquals(new Path("/projects/slider/clusters"), - clientArgs.getBasePath()); - } - - //@Test - public void testNoSliderBasePath() throws Throwable { - ClientArgs clientArgs = createClientArgs(Arrays.asList(ACTION_LIST)); - assertNull(clientArgs.getBasePath()); - } - - //@Test - public void testListNoClusternames() throws Throwable { - ClientArgs clientArgs = createClientArgs(Arrays.asList(ACTION_LIST)); - assertNull(clientArgs.getClusterName()); - } - - //@Test - public void testListNoClusternamesDefinition() throws Throwable { - ClientArgs clientArgs = createClientArgs(Arrays.asList( - ACTION_LIST, - ARG_DEFINE, - "fs.default.FS=file://localhost" - )); - assertNull(clientArgs.getClusterName()); - } - - //@Test - public void testList1Clustername() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList(ACTION_LIST, "cluster1")); - assertEquals("cluster1", ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionListArgs); - } - - //@Test - public void testListFailsTwoClusternames() throws Throwable { - assertParseFails(Arrays.asList( - ACTION_LIST, - "c1", - "c2" - )); - } - - //@Test - public void testDefinitions() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_CREATE, - CLUSTERNAME, - "-D", "yarn.resourcemanager.principal=yarn/server@LOCAL", - "-D", "dfs.datanode.kerberos.principal=hdfs/server@LOCAL" - )); - Configuration conf = new Configuration(false); - ca.applyDefinitions(conf); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertNull(conf.get(SliderXmlConfKeys.KEY_SLIDER_BASE_PATH)); - SliderUtils.verifyPrincipalSet(conf, YarnConfiguration.RM_PRINCIPAL); - SliderUtils.verifyPrincipalSet( - conf, - SliderXmlConfKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY); - - } - - //@Test - public void testDefinitionsSettingBaseSliderDir() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_CREATE, - CLUSTERNAME, - "--basepath", "/projects/slider/clusters", - "-D", "yarn.resourcemanager.principal=yarn/server@LOCAL", - "-D", "dfs.datanode.kerberos.principal=hdfs/server@LOCAL" - )); - Configuration conf = new Configuration(false); - ca.applyDefinitions(conf); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertEquals("/projects/slider/clusters", conf.get(SliderXmlConfKeys - .KEY_SLIDER_BASE_PATH)); - SliderUtils.verifyPrincipalSet(conf, YarnConfiguration.RM_PRINCIPAL); - SliderUtils.verifyPrincipalSet(conf, SliderXmlConfKeys - .DFS_DATANODE_KERBEROS_PRINCIPAL_KEY); - - } - - /** - * Test a start command. - * @throws Throwable - */ - //@Test - public void testComplexThaw() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_START, - "--manager", "rhel:8032", - "--filesystem", "hdfs://rhel:9090", - "-S", "java.security.krb5.realm=LOCAL", - "-S", "java.security.krb5.kdc=rhel", - "-D", "yarn.resourcemanager.principal=yarn/rhel@LOCAL", - "-D", "namenode.resourcemanager.principal=hdfs/rhel@LOCAL", - "cl1" - )); - assertEquals("cl1", ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionThawArgs); - } - - /** - * Test a force kill command where the app comes at the end of the line. - * @throws Throwable - * - */ - //@Test - public void testStatusSplit() throws Throwable { - - String appId = "application_1381252124398_0013"; - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_STATUS, - "--manager", "rhel:8032", - "--filesystem", "hdfs://rhel:9090", - "-S", "java.security.krb5.realm=LOCAL", - "-S", "java.security.krb5.kdc=rhel", - "-D", "yarn.resourcemanager.principal=yarn/rhel@LOCAL", - "-D", "namenode.resourcemanager.principal=hdfs/rhel@LOCAL", - appId - )); - assertEquals(appId, ca.getClusterName()); - } - - //@Test - public void testFreezeFailsNoArg() throws Throwable { - assertParseFails(Arrays.asList( - ACTION_STOP - )); - } - - //@Test - public void testFreezeWorks1Arg() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_STOP, - CLUSTERNAME - )); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionFreezeArgs); - } - - //@Test - public void testFreezeFails2Arg() throws Throwable { - assertParseFails(Arrays.asList( - ACTION_STOP, "cluster", "cluster2" - )); - } - - //@Test - public void testFreezeForceWaitAndMessage() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_STOP, CLUSTERNAME, - ARG_FORCE, - ARG_WAIT, "0", - ARG_MESSAGE, "explanation" - )); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionFreezeArgs); - ActionFreezeArgs freezeArgs = (ActionFreezeArgs) ca.getCoreAction(); - assertEquals("explanation", freezeArgs.message); - assertTrue(freezeArgs.force); - } - - //@Test - public void testGetStatusWorks1Arg() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_STATUS, - CLUSTERNAME - )); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionStatusArgs); - } - - //@Test - public void testExistsWorks1Arg() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_EXISTS, - CLUSTERNAME, - ARG_LIVE - )); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionExistsArgs); - assertTrue(ca.getActionExistsArgs().live); - } - - //@Test - public void testDestroy1Arg() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_DESTROY, - CLUSTERNAME - )); - assertEquals(CLUSTERNAME, ca.getClusterName()); - assertTrue(ca.getCoreAction() instanceof ActionDestroyArgs); - } - - /** - * Assert that a pass fails with a BadCommandArgumentsException. - * @param argsList - */ - - private void assertParseFails(List argsList) throws SliderException { - try { - ClientArgs clientArgs = createClientArgs(argsList); - Assert.fail("exected an exception, got " + clientArgs); - } catch (BadCommandArgumentsException ignored) { - //expected - } - } - - /** - * Build and parse client args, after adding the base args list. - * @param argsList - */ - public ClientArgs createClientArgs(List<String> argsList) - throws SliderException { - ClientArgs serviceArgs = new ClientArgs(argsList); - serviceArgs.parse(); - return serviceArgs; - } - - public ActionCreateArgs createAction(List<String> argsList) - throws SliderException { - ClientArgs ca = createClientArgs(argsList); - assertEquals(ACTION_CREATE, ca.getAction()); - ActionCreateArgs args = ca.getActionCreateArgs(); - assertNotNull(args); - return args; - } - - //@Test - public void testSingleRoleArg() throws Throwable { - ActionCreateArgs createArgs = createAction(Arrays.asList( - ACTION_CREATE, "cluster1", - ARG_COMPONENT, "master", "5" - )); - List<String> tuples = createArgs.getComponentTuples(); - assertEquals(2, tuples.size()); - Map<String, String> roleMap = ArgOps.convertTupleListToMap("roles", tuples); - assertEquals("5", roleMap.get("master")); - } - - //@Test - public void testNoRoleArg() throws Throwable { - ActionCreateArgs createArgs = createAction(Arrays.asList( - ACTION_CREATE, "cluster1" - )); - List<String> tuples = createArgs.getComponentTuples(); - Map<String, String> roleMap = ArgOps.convertTupleListToMap("roles", tuples); - assertNull(roleMap.get("master")); - } - - - //@Test - public void testMultiRoleArgBuild() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_BUILD, "cluster1", - ARG_COMPONENT, "master", "1", - ARG_COMPONENT, "worker", "2" - )); - assertEquals(ACTION_BUILD, ca.getAction()); - assertTrue(ca.getCoreAction() instanceof ActionBuildArgs); - assertTrue(ca.getBuildingActionArgs() instanceof ActionBuildArgs); - AbstractClusterBuildingActionArgs args = ca.getActionBuildArgs(); - List<String> tuples = args.getComponentTuples(); - assertEquals(4, tuples.size()); - Map<String, String> roleMap = ArgOps.convertTupleListToMap("roles", tuples); - assertEquals("1", roleMap.get("master")); - assertEquals("2", roleMap.get("worker")); - } - - //@Test - public void testArgUpdate() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_UPDATE, "cluster1", - ARG_APPDEF, "app.json" - )); - assertEquals(ACTION_UPDATE, ca.getAction()); - assertTrue(ca.getCoreAction() instanceof ActionUpdateArgs); - assertTrue(ca.getActionUpdateArgs() instanceof ActionUpdateArgs); - AbstractClusterBuildingActionArgs args = ca.getActionUpdateArgs(); - assertNotNull(args.appDef); - } - - //@Test - public void testFlexArgs() throws Throwable { - ClientArgs ca = createClientArgs(Arrays.asList( - ACTION_FLEX, "cluster1", - ARG_COMPONENT, "master", "1", - ARG_COMPONENT, "worker", "2" - )); - assertTrue(ca.getCoreAction() instanceof ActionFlexArgs); - List<String> tuples = ca.getActionFlexArgs().getComponentTuples(); - assertEquals(4, tuples.size()); - Map<String, String> roleMap = ArgOps.convertTupleListToMap("roles", tuples); - assertEquals("1", roleMap.get("master")); - assertEquals("2", roleMap.get("worker")); - } - - //@Test - public void testDuplicateRole() throws Throwable { - ActionCreateArgs createArgs = createAction(Arrays.asList( - ACTION_CREATE, "cluster1", - ARG_COMPONENT, "master", "1", - ARG_COMPONENT, "master", "2" - )); - List<String> tuples = createArgs.getComponentTuples(); - assertEquals(4, tuples.size()); - try { - Map<String, String> roleMap = ArgOps.convertTupleListToMap( - "roles", - tuples); - Assert.fail("got a role map $roleMap not a failure"); - } catch (BadCommandArgumentsException expected) { - assertTrue(expected.getMessage().contains(ErrorStrings - .ERROR_DUPLICATE_ENTRY)); - } - } - - //@Test - public void testOddRoleCount() throws Throwable { - ActionCreateArgs createArgs = createAction(Arrays.asList( - ACTION_CREATE, "cluster1", - ARG_COMPONENT, "master", "1", - ARG_COMPONENT, "master", "2" - )); - List<String> tuples = createArgs.getComponentTuples(); - tuples.add("loggers"); - assertEquals(5, tuples.size()); - try { - Map<String, String> roleMap = ArgOps.convertTupleListToMap("roles", - tuples); - Assert.fail("got a role map " + roleMap + " not a failure"); - } catch (BadCommandArgumentsException expected) { - assertTrue(expected.getMessage().contains(ErrorStrings - .ERROR_PARSE_FAILURE)); - } - } - - /** - * Create some role-opt client args, so that multiple tests can use it. - * @return the args - */ - public ActionCreateArgs createRoleOptClientArgs() throws SliderException { - ActionCreateArgs createArgs = createAction(Arrays.asList( - ACTION_CREATE, "cluster1", - ARG_COMPONENT, "master", "1", - ARG_COMP_OPT, "master", "cheese", "swiss", - ARG_COMP_OPT, "master", "env.CHEESE", "cheddar", - ARG_COMP_OPT, "master", ResourceKeys.YARN_CORES, "3", - - ARG_COMPONENT, "worker", "2", - ARG_COMP_OPT, "worker", ResourceKeys.YARN_CORES, "2", - ARG_COMP_OPT, "worker", RoleKeys.JVM_HEAP, "65536", - ARG_COMP_OPT, "worker", "env.CHEESE", "stilton" - )); - return createArgs; - } - - //@Test - public void testRoleOptionParse() throws Throwable { - ActionCreateArgs createArgs = createRoleOptClientArgs(); - Map<String, Map<String, String>> tripleMaps = createArgs.getCompOptionMap(); - Map<String, String> workerOpts = tripleMaps.get("worker"); - assertEquals(3, workerOpts.size()); - assertEquals("2", workerOpts.get(ResourceKeys.YARN_CORES)); - assertEquals("65536", workerOpts.get(RoleKeys.JVM_HEAP)); - - Map<String, String> masterOpts = tripleMaps.get("master"); - assertEquals(3, masterOpts.size()); - assertEquals("3", masterOpts.get(ResourceKeys.YARN_CORES)); - - } - - //@Test - public void testRoleOptionsMerge() throws Throwable { - ActionCreateArgs createArgs = createRoleOptClientArgs(); - - Map<String, Map<String, String>> roleOpts = createArgs.getCompOptionMap(); - - Map<String, Map<String, String>> clusterRoleMap = createEnvMap(); - SliderUtils.applyCommandLineRoleOptsToRoleMap(clusterRoleMap, roleOpts); - - Map<String, String> masterOpts = clusterRoleMap.get("master"); - assertEquals("swiss", masterOpts.get("cheese")); - - Map<String, String> workerOpts = clusterRoleMap.get("worker"); - assertEquals("stilton", workerOpts.get("env.CHEESE")); - } - - //@Test - public void testEnvVariableApply() throws Throwable { - ActionCreateArgs createArgs = createRoleOptClientArgs(); - - - Map<String, Map<String, String>> roleOpts = createArgs.getCompOptionMap(); - - Map<String, Map<String, String>> clusterRoleMap = createEnvMap(); - SliderUtils.applyCommandLineRoleOptsToRoleMap(clusterRoleMap, roleOpts); - - Map<String, String> workerOpts = clusterRoleMap.get("worker"); - assertEquals("stilton", workerOpts.get("env.CHEESE")); - - Map<String, String> envmap = SliderUtils.buildEnvMap(workerOpts); - assertEquals("stilton", envmap.get("CHEESE")); - - } - - /** - * Static compiler complaining about matching LinkedHashMap with Map, - * so some explicit creation here. - * @return a map of maps - */ - public Map<String, Map<String, String>> createEnvMap() { - - Map<String, String> cheese = new HashMap<>(); - cheese.put("cheese", "french"); - Map<String, String> envCheese = new HashMap<>(); - envCheese.put("env.CHEESE", "french"); - Map<String, Map<String, String>> envMap = new HashMap<>(); - envMap.put("master", cheese); - envMap.put("worker", envCheese); - return envMap; - } - - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestKeytabCommandOptions.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestKeytabCommandOptions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestKeytabCommandOptions.java deleted file mode 100644 index 11f8c38..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestKeytabCommandOptions.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * 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.slider.client; - -import org.apache.commons.io.FileUtils; -import org.apache.hadoop.fs.FileUtil; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.RawLocalFileSystem; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.hadoop.yarn.service.client.params.Arguments; -import org.apache.hadoop.yarn.service.client.params.ClientArgs; -import org.apache.slider.common.tools.SliderFileSystem; -import org.apache.slider.common.tools.SliderUtils; -import org.apache.slider.core.exceptions.BadCommandArgumentsException; -import org.apache.slider.core.exceptions.SliderException; -import org.apache.slider.core.main.ServiceLauncher; -import org.apache.slider.utils.SliderTestBase; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -/** - * Test a keytab installation. - */ -public class TestKeytabCommandOptions extends SliderTestBase { - - private static SliderFileSystem testFileSystem; - private File testFolderDir; - - @Before - public void setupFilesystem() throws IOException { - org.apache.hadoop.fs.FileSystem fileSystem = new RawLocalFileSystem(); - YarnConfiguration configuration = SliderUtils.createConfiguration(); - fileSystem.setConf(configuration); - testFileSystem = new SliderFileSystem(fileSystem, configuration); - testFolderDir = new File(testFileSystem - .buildKeytabInstallationDirPath("").toUri().getPath()); - FileUtils.deleteDirectory(testFolderDir); - } - - @After - public void cleanup() throws IOException { - if (testFolderDir != null && testFolderDir.exists()) { - FileUtils.deleteDirectory(testFolderDir); - } - } - - //@Test - public void testInstallKeytab() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder")); - Path installedPath = new Path(testFileSystem - .buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()); - File installedKeytab = new File(installedPath.toUri().getPath()); - assertTrue(installedKeytab.exists()); - assertEquals(FileUtils.readFileToString(installedKeytab), - FileUtils.readFileToString(localKeytab)); - } - - //@Test - public void testInstallThenDeleteKeytab() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder")); - Path installedPath = new Path(testFileSystem - .buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()); - File installedKeytab = new File(installedPath.toUri().getPath()); - assertTrue(installedKeytab.exists()); - assertEquals(FileUtils.readFileToString(installedKeytab), - FileUtils.readFileToString(localKeytab)); - - launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABDELETE, - ClientArgs.ARG_KEYTAB, - localKeytab.getName(), - Arguments.ARG_FOLDER, - "testFolder")); - - assertFalse(installedKeytab.exists()); - - } - - //@Test - public void testInstallThenListKeytab() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder")); - Path installedPath = new Path(testFileSystem - .buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()); - File installedKeytab = new File(installedPath.toUri().getPath()); - assertTrue(installedKeytab.exists()); - assertEquals(FileUtils.readFileToString(installedKeytab), - FileUtils.readFileToString(localKeytab)); - - // install an additional copy into another folder to test listing - launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder2")); - - TestAppender testAppender = new TestAppender(); - - Logger.getLogger(SliderClient.class).addAppender(testAppender); - - try { - launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABLIST) - ); - assertEquals(3, testAppender.events.size()); - String msg = (String) testAppender.events.get(1).getMessage(); - assertTrue(msg.contains("/.slider/keytabs/testFolder")); - assertTrue(msg.endsWith(installedKeytab.getName())); - msg = (String) testAppender.events.get(2).getMessage(); - assertTrue(msg.contains("/.slider/keytabs/testFolder")); - assertTrue(msg.endsWith(installedKeytab.getName())); - } finally { - Logger.getLogger(SliderClient.class).removeAppender(testAppender); - } - - // now listing while specifying the folder name - testAppender = new TestAppender(); - - Logger.getLogger(SliderClient.class).addAppender(testAppender); - - try { - launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABLIST, - Arguments.ARG_FOLDER, - "testFolder")); - assertEquals(2, testAppender.events.size()); - String msg = (String) testAppender.events.get(1).getMessage(); - assertTrue(msg.contains("/.slider/keytabs/testFolder/" + - installedKeytab.getName())); - } finally { - Logger.getLogger(SliderClient.class).removeAppender(testAppender); - } - } - - //@Test - public void testDeleteNonExistentKeytab() throws Throwable { - // create a mock keytab file - YarnConfiguration conf = SliderUtils.createConfiguration(); - try { - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABDELETE, - ClientArgs.ARG_KEYTAB, - "HeyIDontExist.keytab", - Arguments.ARG_FOLDER, - "testFolder")); - fail("expected BadCommandArgumentsException from launch"); - } catch (BadCommandArgumentsException e) { - // expected - } - } - - //@Test - public void testInstallKeytabWithNoFolder() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - try { - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath())); - fail("expected BadCommandArgumentsException from launch"); - } catch (BadCommandArgumentsException e) { - // expected - } - } - - //@Test - public void testInstallKeytabWithNoKeytab() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - try { - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_FOLDER, - "testFolder")); - fail("expected BadCommandArgumentsException from launch"); - } catch (BadCommandArgumentsException e) { - // expected - } - } - - //@Test - public void testInstallKeytabAllowingOverwrite() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder")); - Path installedPath = new Path(testFileSystem - .buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()); - File installedKeytab = new File(installedPath.toUri().getPath()); - assertTrue(installedKeytab.exists()); - assertEquals(FileUtils.readFileToString(installedKeytab), FileUtils - .readFileToString(localKeytab)); - launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder", - Arguments.ARG_OVERWRITE) - ); - assertTrue(installedKeytab.exists()); - assertEquals(FileUtils.readFileToString(installedKeytab), - FileUtils.readFileToString(localKeytab)); - } - - //@Test - public void testInstallKeytabNotAllowingOverwrite() throws Throwable { - // create a mock keytab file - File localKeytab = - FileUtil.createLocalTempFile(getTempLocation(), "test", true); - String contents = UUID.randomUUID().toString(); - FileUtils.write(localKeytab, contents); - YarnConfiguration conf = SliderUtils.createConfiguration(); - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder")); - Path installedPath = new Path(testFileSystem - .buildKeytabInstallationDirPath("testFolder"), localKeytab.getName()); - File installedKeytab = new File(installedPath.toUri().getPath()); - assertTrue(installedKeytab.exists()); - assertEquals(FileUtils.readFileToString(installedKeytab), - FileUtils.readFileToString(localKeytab)); - try { - launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - localKeytab.getAbsolutePath(), - Arguments.ARG_FOLDER, - "testFolder")); - fail("expected BadCommandArgumentsException from launch"); - } catch (BadCommandArgumentsException e) { - // expected - } - } - - //@Test - public void testInstallKeytabWithMissingKeytab() throws Throwable { - // create a mock keytab file - YarnConfiguration conf = SliderUtils.createConfiguration(); - try { - ServiceLauncher launcher = launch(TestSliderClient.class, - conf, - Arrays.asList( - ClientArgs.ACTION_KEYTAB, - ClientArgs.ARG_KEYTABINSTALL, - ClientArgs.ARG_KEYTAB, - "HeyIDontExist.keytab", - Arguments.ARG_FOLDER, - "testFolder")); - fail("expected BadCommandArgumentsException from launch"); - } catch (BadCommandArgumentsException e) { - // expected - } - } - - private File getTempLocation() { - return new File(System.getProperty("user.dir") + "/target"); - } - - /** - * Test SliderClient with overridden filesystem. - */ - public static class TestSliderClient extends SliderClient { - public TestSliderClient() { - super(); - } - - @Override - protected void initHadoopBinding() throws IOException, SliderException { - sliderFileSystem = testFileSystem; - } - - } - - /** - * Appender that captures logging events. - */ - public static class TestAppender extends AppenderSkeleton { - private List<LoggingEvent> events = new ArrayList<>(); - - public void close() {} - - public boolean requiresLayout() { - return false; - } - - @Override - protected void append(LoggingEvent event) { - events.add(event); - } - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderClientMethods.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderClientMethods.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderClientMethods.java deleted file mode 100644 index 66aa7b8..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderClientMethods.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.slider.client; - -import org.apache.hadoop.util.Shell; -import org.apache.hadoop.yarn.api.records.ApplicationId; -import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.service.conf.SliderXmlConfKeys; -import org.apache.slider.common.tools.SliderUtils; -import org.apache.slider.server.appmaster.model.mock.MockApplicationId; -import org.apache.slider.utils.SliderTestBase; -import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Map; - -/** - * Test slider client methods. - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(SliderUtils.class) -public class TestSliderClientMethods extends SliderTestBase { - protected static final Logger LOG = - LoggerFactory.getLogger(TestSliderClientMethods.class); - - static final String AM_ENV = "LD_LIBRARY_PATH"; - static final String PLACEHOLDER_KEY = "${distro.version}"; - static final String PLACEHOLDER_SYSTEM_KEY = "DISTRO_VERSION"; - static final String PLACEHOLDER_VALUE = "1.0.0"; - static final String AM_ENV_2 = "PATH"; - static final String PLACEHOLDER_KEY_2 = "${native.version}"; - static final String PLACEHOLDER_SYSTEM_KEY_2 = "NATIVE_VERSION"; - static final String PLACEHOLDER_VALUE_2 = "2.0.0"; - - //@Test - public void testGeneratePlaceholderKeyValueMap() throws Throwable { - TestSliderClient testSliderClient = new TestSliderClient(); - - PowerMock.mockStatic(System.class); - EasyMock.expect(SliderUtils.getSystemEnv(PLACEHOLDER_SYSTEM_KEY)) - .andReturn(PLACEHOLDER_VALUE).anyTimes(); - PowerMock.replayAll(); - - Map<String, String> placeholders = testSliderClient - .generatePlaceholderKeyValueMap(AM_ENV + "=/usr/lib/" + - PLACEHOLDER_KEY); - Assert.assertTrue(placeholders.containsKey(PLACEHOLDER_KEY)); - Assert.assertEquals("Should be equal", PLACEHOLDER_VALUE, - placeholders.get(PLACEHOLDER_KEY)); - - PowerMock.verifyAll(); - LOG.info("Placeholders = {}", placeholders); - } - - //@Test - public void testSetAmLaunchEnv() throws Throwable { - TestSliderClient testSliderClient = new TestSliderClient(); - YarnConfiguration conf = SliderUtils.createConfiguration(); - conf.set(SliderXmlConfKeys.KEY_AM_LAUNCH_ENV, AM_ENV + "=/usr/lib/" - + PLACEHOLDER_KEY); - - PowerMock.mockStatic(System.class); - EasyMock.expect(SliderUtils.getSystemEnv(PLACEHOLDER_SYSTEM_KEY)) - .andReturn(PLACEHOLDER_VALUE); - PowerMock.replayAll(); - - Map<String, String> amLaunchEnv = testSliderClient.getAmLaunchEnv(conf); - Assert.assertNotNull(amLaunchEnv); - Assert.assertNotNull(amLaunchEnv.get(AM_ENV)); - Assert.assertEquals("Should be equal", amLaunchEnv.get(AM_ENV), - (Shell.WINDOWS ? "%" + AM_ENV + "%;" : "$" + AM_ENV + ":") + - "/usr/lib/" + PLACEHOLDER_VALUE); - - PowerMock.verifyAll(); - LOG.info("amLaunchEnv = {}", amLaunchEnv); - } - - //@Test - public void testSetAmLaunchEnvMulti() throws Throwable { - TestSliderClient testSliderClient = new TestSliderClient(); - YarnConfiguration conf = SliderUtils.createConfiguration(); - conf.set(SliderXmlConfKeys.KEY_AM_LAUNCH_ENV, AM_ENV + "=/usr/lib/" - + PLACEHOLDER_KEY + "," + AM_ENV_2 + "=/usr/bin/" + PLACEHOLDER_KEY_2); - - PowerMock.mockStatic(System.class); - EasyMock.expect(SliderUtils.getSystemEnv(PLACEHOLDER_SYSTEM_KEY)) - .andReturn(PLACEHOLDER_VALUE); - EasyMock.expect(SliderUtils.getSystemEnv(PLACEHOLDER_SYSTEM_KEY_2)) - .andReturn(PLACEHOLDER_VALUE_2); - PowerMock.replayAll(); - - Map<String, String> amLaunchEnv = testSliderClient.getAmLaunchEnv(conf); - Assert.assertNotNull(amLaunchEnv); - Assert.assertEquals("Should have 2 envs", amLaunchEnv.size(), 2); - Assert.assertNotNull(amLaunchEnv.get(AM_ENV)); - Assert.assertEquals("Should be equal", amLaunchEnv.get(AM_ENV), - (Shell.WINDOWS ? "%" + AM_ENV + "%;" : "$" + AM_ENV + ":") + - "/usr/lib/" + PLACEHOLDER_VALUE); - Assert.assertNotNull(amLaunchEnv.get(AM_ENV_2)); - Assert.assertEquals("Should be equal", amLaunchEnv.get(AM_ENV_2), - (Shell.WINDOWS ? "%" + AM_ENV_2 + "%;" : "$" + AM_ENV_2 + ":") + - "/usr/bin/" + PLACEHOLDER_VALUE_2); - - PowerMock.verifyAll(); - LOG.info("amLaunchEnv = " + amLaunchEnv); - } - - static class TestSliderClient extends SliderClient { - @Override - public ApplicationId submitApplication(ApplicationSubmissionContext - context) - throws YarnException, IOException { - return new MockApplicationId(1); - } - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderTokensCommand.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderTokensCommand.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderTokensCommand.java deleted file mode 100644 index d140521..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/client/TestSliderTokensCommand.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.slider.client; - -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.slider.common.params.ActionTokensArgs; -import org.apache.hadoop.yarn.service.client.params.Arguments; -import org.apache.hadoop.yarn.service.client.params.SliderActions; -import org.apache.slider.core.exceptions.BadClusterStateException; -import org.apache.slider.core.exceptions.NotFoundException; -import org.apache.slider.utils.SliderTestBase; -import org.junit.Test; - -import java.util.Arrays; - -/** - * Test the argument parsing/validation logic. - */ -public class TestSliderTokensCommand extends SliderTestBase { - - private static YarnConfiguration config = createTestConfig(); - - public static YarnConfiguration createTestConfig() { - YarnConfiguration configuration = new YarnConfiguration(); - configuration.set(YarnConfiguration.RM_ADDRESS, "127.0.0.1:8032"); - return configuration; - } - - //@Test - public void testBadSourceArgs() throws Throwable { - launchExpectingException(SliderClient.class, - config, - ActionTokensArgs.DUPLICATE_ARGS, - Arrays.asList(SliderActions.ACTION_TOKENS, - Arguments.ARG_SOURCE, "target/tokens.bin", - Arguments.ARG_OUTPUT, "target/tokens.bin" - )); - } - - //@Test - public void testKTNoPrincipal() throws Throwable { - launchExpectingException(SliderClient.class, - config, - ActionTokensArgs.MISSING_KT_PROVIDER, - Arrays.asList(SliderActions.ACTION_TOKENS, - Arguments.ARG_KEYTAB, "target/keytab" - )); - } - - //@Test - public void testPrincipalNoKT() throws Throwable { - launchExpectingException(SliderClient.class, - config, - ActionTokensArgs.MISSING_KT_PROVIDER, - Arrays.asList(SliderActions.ACTION_TOKENS, - Arguments.ARG_PRINCIPAL, "bob@REALM" - )); - } - - /** - * A missing keytab is an error. - * @throws Throwable - */ - //@Test - public void testMissingKT() throws Throwable { - Throwable ex = launchExpectingException(SliderClient.class, - config, - TokensOperation.E_NO_KEYTAB, - Arrays.asList(SliderActions.ACTION_TOKENS, - Arguments.ARG_PRINCIPAL, "bob@REALM", - Arguments.ARG_KEYTAB, "target/keytab" - )); - if (!(ex instanceof NotFoundException)) { - throw ex; - } - } - - //@Test - public void testMissingSourceFile() throws Throwable { - Throwable ex = launchExpectingException(SliderClient.class, - config, - TokensOperation.E_MISSING_SOURCE_FILE, - Arrays.asList(SliderActions.ACTION_TOKENS, - Arguments.ARG_SOURCE, "target/tokens.bin" - )); - if (!(ex instanceof NotFoundException)) { - throw ex; - } - } - - //@Test - public void testListHarmlessWhenInsecure() throws Throwable { - execSliderCommand(0, config, Arrays.asList(SliderActions.ACTION_TOKENS)); - } - - //@Test - public void testCreateFailsWhenInsecure() throws Throwable { - Throwable ex = launchExpectingException(SliderClient.class, - config, - TokensOperation.E_INSECURE, - Arrays.asList(SliderActions.ACTION_TOKENS, - Arguments.ARG_OUTPUT, "target/tokens.bin" - )); - if (!(ex instanceof BadClusterStateException)) { - throw ex; - } - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelper.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelper.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelper.java deleted file mode 100644 index b452aba..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelper.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.slider.common.tools; - -import org.apache.hadoop.conf.Configuration; -import org.apache.slider.utils.YarnMiniClusterTestBase; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Map; - -/** - * Test config helper. - */ -public class TestConfigHelper extends YarnMiniClusterTestBase { - - //@Test - public void testConfigLoaderIteration() throws Throwable { - - String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" " + - "standalone=\"no\"?><configuration><property><name>key</name>" + - "<value>value</value><source>programatically</source></property>" + - "</configuration>"; - InputStream ins = new ByteArrayInputStream(xml.getBytes("UTF8")); - Configuration conf = new Configuration(false); - conf.addResource(ins); - Configuration conf2 = new Configuration(false); - for (Map.Entry<String, String> entry : conf) { - conf2.set(entry.getKey(), entry.getValue(), "src"); - } - - } - - //@Test - public void testConfigDeprecation() throws Throwable { - ConfigHelper.registerDeprecatedConfigItems(); - Configuration conf = new Configuration(false); - // test deprecated items here - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelperHDFS.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelperHDFS.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelperHDFS.java deleted file mode 100644 index 1853c84..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestConfigHelperHDFS.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.slider.common.tools; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.slider.utils.YarnMiniClusterTestBase; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; - -/** - * Test config helper loading configuration from HDFS. - */ -public class TestConfigHelperHDFS extends YarnMiniClusterTestBase { - private static final Logger LOG = - LoggerFactory.getLogger(TestConfigHelperHDFS.class); - - //@Test - public void testConfigHelperHDFS() throws Throwable { - YarnConfiguration config = getConfiguration(); - createMiniHDFSCluster("testConfigHelperHDFS", config); - - Configuration conf = new Configuration(false); - conf.set("key", "value"); - URI fsURI = new URI(getFsDefaultName()); - Path root = new Path(fsURI); - Path confPath = new Path(root, "conf.xml"); - FileSystem dfs = FileSystem.get(fsURI, config); - ConfigHelper.saveConfig(dfs, confPath, conf); - //load time - Configuration loaded = ConfigHelper.loadConfiguration(dfs, confPath); - LOG.info(ConfigHelper.dumpConfigToString(loaded)); - assertEquals("value", loaded.get("key")); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestExecutionEnvironment.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestExecutionEnvironment.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestExecutionEnvironment.java deleted file mode 100644 index f08bf31..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestExecutionEnvironment.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.slider.common.tools; - -import org.apache.slider.utils.SliderTestBase; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Test execution environment. - */ -public class TestExecutionEnvironment extends SliderTestBase { - protected static final Logger LOG = - LoggerFactory.getLogger(TestExecutionEnvironment.class); - - //@Test - public void testClientEnv() throws Throwable { - SliderUtils.validateSliderClientEnvironment(LOG); - } - - //@Test - public void testWinutils() throws Throwable { - SliderUtils.maybeVerifyWinUtilsValid(); - } - - //@Test - public void testServerEnv() throws Throwable { - SliderUtils.validateSliderServerEnvironment(LOG, true); - } - - //@Test - public void testServerEnvNoDependencies() throws Throwable { - SliderUtils.validateSliderServerEnvironment(LOG, false); - } - - //@Test - public void testopenSSLEnv() throws Throwable { - SliderUtils.validateOpenSSLEnv(LOG); - } - - //@Test - public void testValidatePythonEnv() throws Throwable { - SliderUtils.validatePythonEnv(LOG); - } - - //@Test - public void testNativeLibs() throws Throwable { - assertNativeLibrariesPresent(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestPortScan.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestPortScan.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestPortScan.java deleted file mode 100644 index a161779..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestPortScan.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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.slider.common.tools; - -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.core.exceptions.SliderException; -import org.junit.Test; - -import java.net.ServerSocket; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; - -/** - * Test finding a port in a range. - */ -public class TestPortScan { - - //@Test - public void testScanPorts() throws Throwable { - - ServerSocket server = new ServerSocket(0); - - try { - int serverPort = server.getLocalPort(); - assertFalse(SliderUtils.isPortAvailable(serverPort)); - int port = SliderUtils.findFreePort(serverPort, 10); - assertTrue(port > 0 && serverPort < port); - } finally { - server.close(); - } - } - - //@Test - public void testRequestedPortsLogic() throws Throwable { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("5,6,8-10, 11,14 ,20 - 22"); - List<Integer> ports = portScanner.getRemainingPortsToCheck(); - List<Integer> expectedPorts = - Arrays.asList(5, 6, 8, 9, 10, 11, 14, 20, 21, 22); - assertEquals(expectedPorts, ports); - } - - //@Test - public void testRequestedPortsOutOfOrder() throws Throwable { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("8-10,5,6, 11,20 - 22, 14 "); - List<Integer> ports = portScanner.getRemainingPortsToCheck(); - List<Integer> expectedPorts = - Arrays.asList(5, 6, 8, 9, 10, 11, 14, 20, 21, 22); - assertEquals(expectedPorts, ports); - } - - //@Test - public void testFindAvailablePortInRange() throws Throwable { - ServerSocket server = new ServerSocket(0); - try { - int serverPort = server.getLocalPort(); - - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("" + (serverPort-1) + "-" + (serverPort + 3)); - int port = portScanner.getAvailablePort(); - assertNotEquals(port, serverPort); - assertTrue(port >= serverPort -1 && port <= serverPort + 3); - } finally { - server.close(); - } - } - - //@Test - public void testFindAvailablePortInList() throws Throwable { - ServerSocket server = new ServerSocket(0); - try { - int serverPort = server.getLocalPort(); - - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("" + (serverPort-1) + ", " + (serverPort + 1)); - int port = portScanner.getAvailablePort(); - assertNotEquals(port, serverPort); - assertTrue(port == serverPort -1 || port == serverPort + 1); - } finally { - server.close(); - } - } - - //@Test - public void testNoAvailablePorts() throws Throwable { - ServerSocket server1 = new ServerSocket(0); - ServerSocket server2 = new ServerSocket(0); - try { - int serverPort1 = server1.getLocalPort(); - int serverPort2 = server2.getLocalPort(); - - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("" + serverPort1+ ", " + serverPort2); - try { - portScanner.getAvailablePort(); - fail("expected SliderException"); - } catch (SliderException e) { - // expected - } - } finally { - server1.close(); - server2.close(); - } - } - - //@Test - public void testPortRemovedFromRange() throws Throwable { - ServerSocket server = new ServerSocket(0); - try { - int serverPort = server.getLocalPort(); - - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("" + (serverPort-1) + "-" + (serverPort + 3)); - int port = portScanner.getAvailablePort(); - assertNotEquals(port, serverPort); - assertTrue(port >= serverPort -1 && port <= serverPort + 3); - assertFalse(portScanner.getRemainingPortsToCheck().contains(port)); - } finally { - server.close(); - } - } - - //@Test(expected = BadConfigException.class) - public void testBadRange() throws BadConfigException { - PortScanner portScanner = new PortScanner(); - // note the em dash - portScanner.setPortRange("2000â2010"); - } - - //@Test(expected = BadConfigException.class) - public void testEndBeforeStart() throws BadConfigException { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("2001-2000"); - } - - //@Test(expected = BadConfigException.class) - public void testEmptyRange() throws BadConfigException { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange(""); - } - - //@Test(expected = BadConfigException.class) - public void testBlankRange() throws BadConfigException { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange(" "); - } - - //@Test - public void testExtraComma() throws BadConfigException { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("2000-2001, "); - List<Integer> ports = portScanner.getRemainingPortsToCheck(); - List<Integer> expectedPorts = Arrays.asList(2000, 2001); - assertEquals(expectedPorts, ports); - } - - //@Test - public void testExtraCommas() throws BadConfigException { - PortScanner portScanner = new PortScanner(); - portScanner.setPortRange("2000-2001,, ,2003,"); - List<Integer> ports = portScanner.getRemainingPortsToCheck(); - List<Integer> expectedPorts = Arrays.asList(2000, 2001, 2003); - assertEquals(expectedPorts, ports); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderFileSystem.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderFileSystem.java deleted file mode 100644 index 755a4c6..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderFileSystem.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.slider.common.tools; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.yarn.service.conf.SliderXmlConfKeys; -import org.apache.slider.utils.SliderTestBase; -import org.junit.Test; - -/** - * Test slider file system. - */ -public class TestSliderFileSystem extends SliderTestBase { - private static Configuration defaultConfiguration() { - return new Configuration(); - } - - private static Configuration createConfigurationWithKV(String key, String - value) { - Configuration conf = defaultConfiguration(); - conf.set(key, value); - return conf; - } - - //@Test - public void testSliderBasePathDefaultValue() throws Throwable { - Configuration configuration = defaultConfiguration(); - FileSystem fileSystem = FileSystem.get(configuration); - - SliderFileSystem fs2 = new SliderFileSystem(fileSystem, configuration); - assertEquals(fs2.getBaseApplicationPath(), new Path(fileSystem - .getHomeDirectory(), ".slider")); - } - - //@Test - public void testSliderBasePathCustomValue() throws Throwable { - Configuration configuration = createConfigurationWithKV(SliderXmlConfKeys - .KEY_SLIDER_BASE_PATH, "/slider/cluster"); - FileSystem fileSystem = FileSystem.get(configuration); - SliderFileSystem fs2 = new SliderFileSystem(fileSystem, configuration); - - assertEquals(fs2.getBaseApplicationPath(), new Path("/slider/cluster")); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderTestUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderTestUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderTestUtils.java deleted file mode 100644 index e19e33f..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/common/tools/TestSliderTestUtils.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.slider.common.tools; - -import org.apache.hadoop.conf.Configuration; -import org.apache.slider.utils.SliderTestUtils; -import org.junit.Test; -import org.junit.internal.AssumptionViolatedException; - -/** - * Test slider test utils. - */ -public class TestSliderTestUtils extends SliderTestUtils { - - //@Test - public void testAssumeTrue() throws Throwable { - - try { - assume(true, "true"); - } catch (AssumptionViolatedException e) { - throw new Exception(e); - } - } - - //@Test - public void testAssumeFalse() throws Throwable { - - try { - assume(false, "false"); - fail("expected an exception"); - } catch (AssumptionViolatedException ignored) { - //expected - } - } - - //@Test - public void testAssumeBoolOptionSetInConf() throws Throwable { - Configuration conf = new Configuration(false); - conf.set("key", "true"); - try { - assumeBoolOption(conf, "key", false); - } catch (AssumptionViolatedException e) { - throw new Exception(e); - } - } - - //@Test - public void testAssumeBoolOptionUnsetInConf() throws Throwable { - Configuration conf = new Configuration(false); - try { - assumeBoolOption(conf, "key", true); - } catch (AssumptionViolatedException e) { - throw new Exception(e); - } - } - - - //@Test - public void testAssumeBoolOptionFalseInConf() throws Throwable { - Configuration conf = new Configuration(false); - conf.set("key", "false"); - try { - assumeBoolOption(conf, "key", true); - fail("expected an exception"); - } catch (AssumptionViolatedException ignored) { - //expected - } - } - - //@Test - public void testAssumeBoolOptionFalseUnsetInConf() throws Throwable { - Configuration conf = new Configuration(false); - try { - assumeBoolOption(conf, "key", false); - fail("expected an exception"); - } catch (AssumptionViolatedException ignored) { - //expected - } - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org