Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8792109DC for ; Thu, 23 Jan 2014 14:23:40 +0000 (UTC) Received: (qmail 69474 invoked by uid 500); 23 Jan 2014 14:23:40 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 69381 invoked by uid 500); 23 Jan 2014 14:23:39 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 69050 invoked by uid 99); 23 Jan 2014 14:23:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jan 2014 14:23:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 54E0E8ACBFE; Thu, 23 Jan 2014 14:23:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mdrob@apache.org To: commits@accumulo.apache.org Date: Thu, 23 Jan 2014 14:23:30 -0000 Message-Id: <92ab32be03264e8590fdb5db887bc3bc@git.apache.org> In-Reply-To: <85b9c6c3068147c39e29d2197c24df7a@git.apache.org> References: <85b9c6c3068147c39e29d2197c24df7a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/6] git commit: Merge branch '1.4.5-SNAPSHOT' into 1.5.1-SNAPSHOT Merge branch '1.4.5-SNAPSHOT' into 1.5.1-SNAPSHOT Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/fbed7afa Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/fbed7afa Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/fbed7afa Branch: refs/heads/1.6.0-SNAPSHOT Commit: fbed7afab4ff024872a04a3a4dae76558380ab02 Parents: c4cd3b1 de7d198 Author: Mike Drob Authored: Thu Jan 23 09:22:44 2014 -0500 Committer: Mike Drob Committed: Thu Jan 23 09:22:44 2014 -0500 ---------------------------------------------------------------------- .../test/java/org/apache/accumulo/fate/util/AddressUtilTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/fbed7afa/fate/src/test/java/org/apache/accumulo/fate/util/AddressUtilTest.java ---------------------------------------------------------------------- diff --cc fate/src/test/java/org/apache/accumulo/fate/util/AddressUtilTest.java index aca4571,0000000..7d43381 mode 100644,000000..100644 --- a/fate/src/test/java/org/apache/accumulo/fate/util/AddressUtilTest.java +++ b/fate/src/test/java/org/apache/accumulo/fate/util/AddressUtilTest.java @@@ -1,95 -1,0 +1,95 @@@ +/* + * 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.accumulo.fate.util; + +import java.security.Security; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; + +/** + * Test the AddressUtil class. + * + */ +public class AddressUtilTest extends TestCase { + + private static final Logger log = Logger.getLogger(AddressUtilTest.class); + + public void testGetNegativeTtl() { + log.info("Checking that we can get the ttl on dns failures."); + int expectedTtl = 20; + boolean expectException = false; - /* TODO replace all of this with Powermock on the Security class */ ++ /* TODO ACCUMULO-2242 replace all of this with Powermock on the Security class */ + try { + Security.setProperty("networkaddress.cache.negative.ttl", Integer.toString(expectedTtl)); + } catch (SecurityException exception) { + log.warn("We can't set the DNS cache period, so we're only testing fetching the system value."); + expectedTtl = 10; + } + try { + expectedTtl = Integer.parseInt(Security.getProperty("networkaddress.cache.negative.ttl")); + } catch (SecurityException exception) { + log.debug("Security manager won't let us fetch the property, testing default path."); + expectedTtl = 10; + } catch (NumberFormatException exception) { + log.debug("property isn't a number, testing default path."); + expectedTtl = 10; + } + if (-1 == expectedTtl) { + log.debug("property is set to 'forever', testing exception path"); + expectException = true; + } + if (0 > expectedTtl) { + log.debug("property is a negative value other than 'forever', testing default path."); + expectedTtl = 10; + } + try { + if (expectException) { + log.info("AddressUtil is (hopefully) going to spit out an error about DNS lookups. you can ignore it."); + } + int result = AddressUtil.getAddressCacheNegativeTtl(null); + if (expectException) { + fail("The JVM Security settings cache DNS failures forever. In this case we expect an exception but didn't get one."); + } + assertEquals("Didn't get the ttl we expected", expectedTtl, result); + } catch (IllegalArgumentException exception) { + if (!expectException) { + log.error("Got an exception when we weren't expecting.", exception); + fail("We only expect to throw an IllegalArgumentException when the JVM caches DNS failures forever."); + } + } + } + + public void testGetNegativeTtlThrowsOnForever() { + log.info("When DNS is cached forever, we should throw."); - /* TODO replace all of this with Powermock on the Security class */ ++ /* TODO ACCUMULO-2242 replace all of this with Powermock on the Security class */ + try { + Security.setProperty("networkaddress.cache.negative.ttl", "-1"); + } catch (SecurityException exception) { + log.error("We can't set the DNS cache period, so this test is effectively ignored."); + return; + } + try { + log.info("AddressUtil is (hopefully) going to spit out an error about DNS lookups. you can ignore it."); + int result = AddressUtil.getAddressCacheNegativeTtl(null); + fail("The JVM Security settings cache DNS failures forever, this should cause an exception."); + } catch(IllegalArgumentException exception) { + assertTrue(true); + } + } +}