[ 
https://issues.apache.org/jira/browse/STORM-1255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15152750#comment-15152750
 ] 

ASF GitHub Bot commented on STORM-1255:
---------------------------------------

Github user revans2 commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1114#discussion_r53355813
  
    --- Diff: storm-core/test/jvm/org/apache/storm/utils/UtilsTest.java ---
    @@ -0,0 +1,213 @@
    +/**
    + * 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.storm.utils;
    +
    +import java.util.Arrays;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.HashMap;
    +import org.junit.Test;
    +import org.junit.Assert;
    +
    +import org.apache.curator.ensemble.exhibitor.ExhibitorEnsembleProvider;
    +import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
    +import org.apache.curator.framework.AuthInfo;
    +import org.apache.curator.framework.CuratorFramework;
    +import org.apache.curator.framework.CuratorFrameworkFactory;
    +
    +import org.apache.storm.Config;
    +import org.apache.thrift.transport.TTransportException;
    +
    +public class UtilsTest {
    +    @Test
    +    public void newCuratorUsesExponentialBackoffTest() throws 
InterruptedException {
    +        final int expectedInterval = 2400;
    +        final int expectedRetries = 10;
    +        final int expectedCeiling = 3000;
    +
    +        Map<String, Object> config = Utils.readDefaultConfig();
    +        config.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL, 
expectedInterval); 
    +        config.put(Config.STORM_ZOOKEEPER_RETRY_TIMES, expectedRetries); 
    +        config.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL_CEILING, 
expectedCeiling); 
    +
    +        CuratorFramework curator = Utils.newCurator(config, 
Arrays.asList("bogus_server"), 42 /*port*/, "");
    +        StormBoundedExponentialBackoffRetry policy = 
    +            (StormBoundedExponentialBackoffRetry) 
curator.getZookeeperClient().getRetryPolicy();
    +        Assert.assertEquals(policy.getBaseSleepTimeMs(), expectedInterval);
    +        Assert.assertEquals(policy.getN(), expectedRetries);
    +        Assert.assertEquals(policy.getSleepTimeMs(10, 0), expectedCeiling);
    +    }
    +
    +    @Test(expected = RuntimeException.class)
    +    public void getConfiguredClientThrowsRuntimeExceptionOnBadArgsTest () 
throws RuntimeException, TTransportException {
    +        Map config = ConfigUtils.readStormConfig();
    +        config.put(Config.STORM_NIMBUS_RETRY_TIMES, 0);
    +        new NimbusClient(config, "", 65535);
    +    }
    +
    +    private Map mockMap(String key, String value) {
    +        Map<String, Object> map = new HashMap<String, Object>();
    +        map.put(key, value);
    +        return map;
    +    }
    +
    +    private Map topologyMockMap(String value) {
    +        return mockMap(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_SCHEME, value);
    +    }
    +
    +    private Map serverMockMap(String value) {
    +        return mockMap(Config.STORM_ZOOKEEPER_AUTH_SCHEME, value);
    +    }
    +
    +    private Map emptyMockMap() {
    +        return new HashMap<String, Object>();
    +    }
    +
    +    @Test
    +    public void isZkAuthenticationConfiguredTopologyTest() {
    +        Assert.assertFalse(
    +            "Returns null if given null config", 
    +            Utils.isZkAuthenticationConfiguredTopology(null));
    +
    +        Assert.assertFalse(
    +            "Returns false if scheme key is missing", 
    +            Utils.isZkAuthenticationConfiguredTopology(emptyMockMap()));
    +
    +        Assert.assertFalse(
    +            "Returns false if scheme value is null", 
    +            
Utils.isZkAuthenticationConfiguredTopology(topologyMockMap(null)));
    +
    +        Assert.assertTrue(
    +            "Returns true if scheme value is string", 
    +            
Utils.isZkAuthenticationConfiguredTopology(topologyMockMap("foobar")));
    +    }
    +
    +    @Test
    +    public void isZkAuthenticationConfiguredStormServerTest() {
    +        Assert.assertFalse(
    +            "Returns false if given null config",
    +            Utils.isZkAuthenticationConfiguredStormServer(null));
    +
    +        Assert.assertFalse(
    +            "Returns false if scheme key is missing",
    +            Utils.isZkAuthenticationConfiguredStormServer(emptyMockMap()));
    +
    +        Assert.assertFalse(
    +            "Returns false if scheme value is null",
    +            
Utils.isZkAuthenticationConfiguredStormServer(serverMockMap(null)));
    +
    +        Assert.assertTrue(
    +            "Returns true if scheme value is string",
    +            
Utils.isZkAuthenticationConfiguredStormServer(serverMockMap("foobar")));
    +    }
    +
    +    @Test
    +    public void isZkAuthenticationConfiguredStormServerWithPropertyTest() {
    +        String key = "java.security.auth.login.config";
    +        String oldValue = System.getProperty(key);
    +        try {
    +            System.setProperty("java.security.auth.login.config", 
"anything");
    +            
Assert.assertTrue(Utils.isZkAuthenticationConfiguredStormServer(emptyMockMap()));
    +        } catch (Exception ignore) {
    --- End diff --
    
    We don't want to ignore this exception.  Let it fail the test if need be.


> port backtype.storm.utils-test to java
> --------------------------------------
>
>                 Key: STORM-1255
>                 URL: https://issues.apache.org/jira/browse/STORM-1255
>             Project: Apache Storm
>          Issue Type: New Feature
>          Components: rm-core, storm-core
>            Reporter: Robert Joseph Evans
>            Assignee: Alessandro Bellina
>              Labels: java-migration, jstorm-merger
>
> junit test migration



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to