Return-Path: X-Original-To: apmail-incubator-accumulo-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-accumulo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2E4B594F0 for ; Tue, 25 Oct 2011 20:08:23 +0000 (UTC) Received: (qmail 69021 invoked by uid 500); 25 Oct 2011 20:08:23 -0000 Delivered-To: apmail-incubator-accumulo-commits-archive@incubator.apache.org Received: (qmail 68997 invoked by uid 500); 25 Oct 2011 20:08:23 -0000 Mailing-List: contact accumulo-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: accumulo-dev@incubator.apache.org Delivered-To: mailing list accumulo-commits@incubator.apache.org Received: (qmail 68990 invoked by uid 99); 25 Oct 2011 20:08:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Oct 2011 20:08:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Oct 2011 20:08:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 06808238890A; Tue, 25 Oct 2011 20:07:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1188884 - in /incubator/accumulo/trunk/src/start/src: main/java/org/apache/accumulo/start/classloader/AccumuloClassLoader.java test/java/org/apache/accumulo/start/Test.java Date: Tue, 25 Oct 2011 20:07:58 -0000 To: accumulo-commits@incubator.apache.org From: vines@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111025200759.06808238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vines Date: Tue Oct 25 20:07:58 2011 New Revision: 1188884 URL: http://svn.apache.org/viewvc?rev=1188884&view=rev Log: fixes ACCUMULO-64 we now test this Modified: incubator/accumulo/trunk/src/start/src/main/java/org/apache/accumulo/start/classloader/AccumuloClassLoader.java incubator/accumulo/trunk/src/start/src/test/java/org/apache/accumulo/start/Test.java Modified: incubator/accumulo/trunk/src/start/src/main/java/org/apache/accumulo/start/classloader/AccumuloClassLoader.java URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/start/src/main/java/org/apache/accumulo/start/classloader/AccumuloClassLoader.java?rev=1188884&r1=1188883&r2=1188884&view=diff ============================================================================== --- incubator/accumulo/trunk/src/start/src/main/java/org/apache/accumulo/start/classloader/AccumuloClassLoader.java (original) +++ incubator/accumulo/trunk/src/start/src/main/java/org/apache/accumulo/start/classloader/AccumuloClassLoader.java Tue Oct 25 20:07:58 2011 @@ -274,11 +274,11 @@ public class AccumuloClassLoader { return classpath; } - private static String getAccumuloDynamicClasspathStrings() throws IllegalStateException { + public static String getAccumuloDynamicClasspathStrings() throws IllegalStateException { return getAccumuloString(DYNAMIC_CLASSPATH_PROPERTY_NAME, DEFAULT_DYNAMIC_CLASSPATH_VALUE); } - private static String getAccumuloClasspathStrings() throws IllegalStateException { + public static String getAccumuloClasspathStrings() throws IllegalStateException { return getAccumuloString(CLASSPATH_PROPERTY_NAME, ACCUMULO_CLASSPATH_VALUE); } Modified: incubator/accumulo/trunk/src/start/src/test/java/org/apache/accumulo/start/Test.java URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/start/src/test/java/org/apache/accumulo/start/Test.java?rev=1188884&r1=1188883&r2=1188884&view=diff ============================================================================== --- incubator/accumulo/trunk/src/start/src/test/java/org/apache/accumulo/start/Test.java (original) +++ incubator/accumulo/trunk/src/start/src/test/java/org/apache/accumulo/start/Test.java Tue Oct 25 20:07:58 2011 @@ -22,6 +22,15 @@ import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import java.util.Random; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import junit.framework.TestCase; @@ -30,6 +39,10 @@ import org.apache.commons.io.IOUtils; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; public class Test extends TestCase { @@ -43,12 +56,14 @@ public class Test extends TestCase { @Override public void setUp() { - String aHome = System.getenv("ACCUMULO_HOME"); if (aHome == null) fail("ACCUMULO_HOME must be set"); - tmpDir = new File(aHome + "/lib/ext"); - if (!tmpDir.exists()) - tmpDir.mkdir(); + + String dynamicExpr = AccumuloClassLoader.getAccumuloDynamicClasspathStrings().split(";", 2)[0]; + File f = new File(dynamicExpr.replace("$ACCUMULO_HOME", aHome)); + + tmpDir = f.getParentFile(); + if (!tmpDir.exists()) tmpDir.mkdirs(); destJar = new File(tmpDir, "Test.jar"); if (destJar.exists()) { destJar.delete(); @@ -150,7 +165,6 @@ public class Test extends TestCase { assertTrue(false); } catch (ClassNotFoundException cnfe) {} - // uncomment this block when #2987 is fixed if (log.isDebugEnabled()) log.debug("Test with Jar C"); copyJar(jarC); test.Test e = create(); @@ -158,4 +172,59 @@ public class Test extends TestCase { } + public void testChangingDirectory() throws Exception { + String configFile = System.getProperty("org.apache.accumulo.config.file", "accumulo-site.xml"); + String SITE_CONF = System.getenv("ACCUMULO_HOME") + "/conf/" + configFile; + File oldConf = new File(SITE_CONF); + String siteBkp = SITE_CONF + ".bkp"; + if (oldConf.exists()) + { + oldConf.renameTo(new File(siteBkp)); + } + oldConf = new File(siteBkp); + String randomFolder = System.getenv("ACCUMULO_HOME") + "/lib/notExt" + new Random().nextInt(); + + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document d = db.parse(siteBkp); + + NodeList pnodes = d.getElementsByTagName("property"); + for (int i = pnodes.getLength() - 1; i >= 0; i--) { + Element current_property = (Element) pnodes.item(i); + Node cname = current_property.getElementsByTagName("name").item(0); + if (cname != null && cname.getTextContent().compareTo(AccumuloClassLoader.DYNAMIC_CLASSPATH_PROPERTY_NAME) == 0) { + Node cvalue = current_property.getElementsByTagName("value").item(0); + if (cvalue != null) { + cvalue.setTextContent(randomFolder+"/.*"); + } else { + cvalue = d.createElement("value"); + cvalue.setTextContent(randomFolder+"/.*"); + current_property.appendChild(cvalue); + } + break; + } + } + + TransformerFactory cybertron = TransformerFactory.newInstance(); + Transformer optimusPrime = cybertron.newTransformer(); + Result result = new StreamResult(new File(SITE_CONF)); + + optimusPrime.transform(new DOMSource(d), result); + + setUp(); + testReloadingClassLoader(); + + } finally { + new File(SITE_CONF).delete(); + if (oldConf.exists()) + oldConf.renameTo(new File(SITE_CONF)); + File rf = new File(randomFolder); + for (File deleteMe : rf.listFiles()) + deleteMe.delete(); + rf.delete(); + } + } + }