Repository: vxquery Updated Branches: refs/heads/master 5b0e2ac0b -> 9f458dcb2
VXQUERY-213 Fixed Open File Test Error Now Test Suites each use a single cluster instance for all tests Created a Utility for starting and stopping the cluster Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/9f458dcb Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/9f458dcb Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/9f458dcb Branch: refs/heads/master Commit: 9f458dcb2f8d4b6e570e3f687e9aa5f810541b3b Parents: 5b0e2ac Author: Steven Glenn Jacobs <[email protected]> Authored: Tue Jun 28 10:45:03 2016 -0700 Committer: Steven Glenn Jacobs <[email protected]> Committed: Tue Jun 28 10:45:03 2016 -0700 ---------------------------------------------------------------------- .../apache/vxquery/xtest/TestClusterUtil.java | 99 ++++++++++++++++++++ .../org/apache/vxquery/xtest/TestRunner.java | 37 +------- .../vxquery/xtest/AbstractXQueryTest.java | 83 ++++++++++++---- .../org/apache/vxquery/xtest/VXQueryTest.java | 32 ------- 4 files changed, 167 insertions(+), 84 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/vxquery/blob/9f458dcb/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java new file mode 100644 index 0000000..9f5bb76 --- /dev/null +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java @@ -0,0 +1,99 @@ +/* + * 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.vxquery.xtest; + +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.apache.hyracks.control.cc.ClusterControllerService; +import org.apache.hyracks.control.common.controllers.CCConfig; +import org.apache.hyracks.control.common.controllers.NCConfig; +import org.apache.hyracks.control.nc.NodeControllerService; + +public class TestClusterUtil { + + private static int clientNetPort = 39000; + private static int clusterNetPort = 39001; + private static int profileDumpPeriod = 10000; + private static String ccHost = "localhost"; + private static String nodeId = "nc1"; + + public static CCConfig createCCConfig() throws UnknownHostException { + String publicAddress = InetAddress.getLocalHost().getHostAddress(); + CCConfig ccConfig = new CCConfig(); + ccConfig.clientNetIpAddress = publicAddress; + ccConfig.clientNetPort = clientNetPort; + ccConfig.clusterNetIpAddress = publicAddress; + ccConfig.clusterNetPort = clusterNetPort; + ccConfig.profileDumpPeriod = profileDumpPeriod; + return ccConfig; + } + + public static NCConfig createNCConfig() throws UnknownHostException { + String publicAddress = InetAddress.getLocalHost().getHostAddress(); + NCConfig ncConfig1 = new NCConfig(); + ncConfig1.ccHost = ccHost; + ncConfig1.ccPort = clusterNetPort; + ncConfig1.clusterNetIPAddress = publicAddress; + ncConfig1.dataIPAddress = publicAddress; + ncConfig1.resultIPAddress = publicAddress; + ncConfig1.nodeId = nodeId; + return ncConfig1; + } + + public static ClusterControllerService startCC() throws IOException { + CCConfig ccConfig = createCCConfig(); + File outDir = new File("target/ClusterController"); + outDir.mkdirs(); + File ccRoot = File.createTempFile(TestRunner.class.getName(), ".data", outDir); + ccRoot.delete(); + ccRoot.mkdir(); + ccConfig.ccRoot = ccRoot.getAbsolutePath(); + try { + ClusterControllerService cc = new ClusterControllerService(ccConfig); + cc.start(); + return cc; + } catch (Exception e) { + throw new IOException(e); + } + + } + + public static NodeControllerService startNC() throws IOException { + NCConfig ncConfig = createNCConfig(); + try { + NodeControllerService nc = new NodeControllerService(ncConfig); + nc.start(); + return nc; + } catch (Exception e) { + throw new IOException(e); + } + } + + public static void stopCluster(ClusterControllerService cc, NodeControllerService nc) throws IOException { + try { + nc.stop(); + cc.stop(); + } catch (Exception e) { + throw new IOException(e); + } + } + +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/9f458dcb/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java index 4f7962e..8cf65b4 100644 --- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java @@ -14,11 +14,9 @@ */ package org.apache.vxquery.xtest; -import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.Reader; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.EnumSet; import java.util.Map; @@ -40,10 +38,7 @@ import org.apache.hyracks.api.job.JobFlag; import org.apache.hyracks.api.job.JobId; import org.apache.hyracks.api.job.JobSpecification; import org.apache.hyracks.client.dataset.HyracksDataset; -import org.apache.hyracks.control.cc.ClusterControllerService; import org.apache.hyracks.control.common.controllers.CCConfig; -import org.apache.hyracks.control.common.controllers.NCConfig; -import org.apache.hyracks.control.nc.NodeControllerService; import org.apache.hyracks.control.nc.resources.memory.FrameManager; import org.apache.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor; import org.apache.vxquery.compiler.CompilerControlBlock; @@ -63,43 +58,15 @@ public class TestRunner { .compile("org\\.apache\\.vxquery\\.exceptions\\.SystemException: (\\p{javaUpperCase}{4}\\d{4})"); private XTestOptions opts; - private ClusterControllerService cc; - private NodeControllerService nc1; private IHyracksClientConnection hcc; private IHyracksDataset hds; - private final String publicAddress; public TestRunner(XTestOptions opts) throws UnknownHostException { this.opts = opts; - this.publicAddress = InetAddress.getLocalHost().getHostAddress(); } public void open() throws Exception { - CCConfig ccConfig = new CCConfig(); - ccConfig.clientNetIpAddress = publicAddress; - ccConfig.clientNetPort = 39000; - ccConfig.clusterNetIpAddress = publicAddress; - ccConfig.clusterNetPort = 39001; - ccConfig.profileDumpPeriod = 10000; - File outDir = new File("target/ClusterController"); - outDir.mkdirs(); - File ccRoot = File.createTempFile(TestRunner.class.getName(), ".data", outDir); - ccRoot.delete(); - ccRoot.mkdir(); - ccConfig.ccRoot = ccRoot.getAbsolutePath(); - cc = new ClusterControllerService(ccConfig); - cc.start(); - - NCConfig ncConfig1 = new NCConfig(); - ncConfig1.ccHost = "localhost"; - ncConfig1.ccPort = 39001; - ncConfig1.clusterNetIPAddress = publicAddress; - ncConfig1.dataIPAddress = publicAddress; - ncConfig1.resultIPAddress = publicAddress; - ncConfig1.nodeId = "nc1"; - nc1 = new NodeControllerService(ncConfig1); - nc1.start(); - + CCConfig ccConfig = TestClusterUtil.createCCConfig(); hcc = new HyracksConnection(ccConfig.clientNetIpAddress, ccConfig.clientNetPort); } @@ -208,7 +175,5 @@ public class TestRunner { } public void close() throws Exception { - nc1.stop(); - cc.stop(); } } http://git-wip-us.apache.org/repos/asf/vxquery/blob/9f458dcb/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/AbstractXQueryTest.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/AbstractXQueryTest.java b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/AbstractXQueryTest.java index bf65631..c6b339b 100644 --- a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/AbstractXQueryTest.java +++ b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/AbstractXQueryTest.java @@ -1,25 +1,33 @@ /* -* 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. -*/ + * 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.vxquery.xtest; import static org.junit.Assert.fail; +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.apache.hyracks.control.cc.ClusterControllerService; +import org.apache.hyracks.control.nc.NodeControllerService; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -28,6 +36,10 @@ import org.junit.runners.Parameterized; public abstract class AbstractXQueryTest { private TestCase tc; private TestRunner tr; + private static MiniDFS dfs; + private final static String TMP = "target/tmp"; + private static NodeControllerService nc; + private static ClusterControllerService cc; protected abstract XTestOptions getTestOptions(); @@ -61,7 +73,8 @@ public abstract class AbstractXQueryTest { case EXPECTED_RESULT_GOT_DIFFERENT_RESULT: case EXPECTED_RESULT_GOT_ERROR: case EXPECTED_RESULT_GOT_FAILURE: - fail(result.state + " (" + result.time + " ms): " + result.testCase.getXQueryDisplayName() + " " + result.error); + fail(result.state + " (" + result.time + " ms): " + result.testCase.getXQueryDisplayName() + " " + + result.error); break; case EXPECTED_ERROR_GOT_SAME_ERROR: case EXPECTED_RESULT_GOT_SAME_RESULT: @@ -76,4 +89,42 @@ public abstract class AbstractXQueryTest { tr.close(); } + @BeforeClass + public static void setup() throws IOException { + cc = TestClusterUtil.startCC(); + nc = TestClusterUtil.startNC(); + setupFS(); + } + + public static void setupFS() throws IOException { + File tmp = new File(TMP); + if (tmp.exists()) { + FileUtils.deleteDirectory(tmp); + } + new File(TMP.concat("/indexFolder")).mkdirs(); + String HDFSFolder = TMP.concat("/hdfsFolder"); + new File(HDFSFolder).mkdirs(); + dfs = new MiniDFS(); + try { + dfs.startHDFS(HDFSFolder); + } catch (IOException e) { + throw new IOException(e); + } + } + + @AfterClass + public static void shutdown() throws IOException { + removeFS(); + TestClusterUtil.stopCluster(cc, nc); + + } + + public static void removeFS() throws IOException { + File tmp = new File(TMP); + if (tmp.exists()) { + FileUtils.deleteDirectory(tmp); + } + dfs.shutdownHDFS(); + } + } http://git-wip-us.apache.org/repos/asf/vxquery/blob/9f458dcb/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java index 1b76e16..84349af 100644 --- a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java +++ b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java @@ -17,21 +17,15 @@ package org.apache.vxquery.xtest; import java.io.File; -import java.io.IOException; import java.util.Collection; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class VXQueryTest extends AbstractXQueryTest { - private static MiniDFS dfs; - private final static String TMP = "target/tmp"; private static String VXQUERY_CATALOG = StringUtils .join(new String[] { "src", "test", "resources", "VXQueryCatalog.xml" }, File.separator); @@ -58,30 +52,4 @@ public class VXQueryTest extends AbstractXQueryTest { return getOptions(); } - @BeforeClass - public static void setup() throws IOException { - File tmp = new File(TMP); - if (tmp.exists()) { - FileUtils.deleteDirectory(tmp); - } - new File(TMP.concat("/indexFolder")).mkdirs(); - String HDFSFolder = TMP.concat("/hdfsFolder"); - new File(HDFSFolder).mkdirs(); - dfs = new MiniDFS(); - try { - dfs.startHDFS(HDFSFolder); - } catch (IOException e) { - System.err.println(e); - } - } - - @AfterClass - public static void shutdown() throws IOException { - File tmp = new File(TMP); - if (tmp.exists()) { - FileUtils.deleteDirectory(tmp); - } - dfs.shutdownHDFS(); - } - }
