You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2016/07/27 23:17:14 UTC

asterixdb git commit: ASTERIXDB-1552: Test Case for Sample Local Cluster

Repository: asterixdb
Updated Branches:
  refs/heads/master 6448824af -> 70908dfb4


ASTERIXDB-1552: Test Case for Sample Local Cluster

Change-Id: I2eacbd033a65661d22dc2a848afd83bbcc43677f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1028
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/70908dfb
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/70908dfb
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/70908dfb

Branch: refs/heads/master
Commit: 70908dfb463f70a7d50dcb94cfc14defd76fa720
Parents: 6448824
Author: Michael Blow <mb...@apache.org>
Authored: Wed Jul 27 14:48:17 2016 -0400
Committer: Michael Blow <mb...@apache.org>
Committed: Wed Jul 27 16:16:55 2016 -0700

----------------------------------------------------------------------
 .../apache/asterix/test/common/TestHelper.java  |  41 ++++++++
 .../server/test/SampleLocalClusterIT.java       | 105 +++++++++++++++++++
 2 files changed, 146 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/70908dfb/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
index 0804126..5661258 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
@@ -18,7 +18,18 @@
  */
 package org.apache.asterix.test.common;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
 import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 
 public final class TestHelper {
 
@@ -31,4 +42,34 @@ public final class TestHelper {
         return false;
     }
 
+    public static String joinPath(String... pathElements) {
+        return StringUtils.join(pathElements, File.separatorChar);
+    }
+
+    public static void unzip(String sourceFile, String outputDir) throws IOException {
+        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
+            try (ZipFile zipFile = new ZipFile(sourceFile)) {
+                Enumeration<? extends ZipEntry> entries = zipFile.entries();
+                while (entries.hasMoreElements()) {
+                    ZipEntry entry = entries.nextElement();
+                    File entryDestination = new File(outputDir,  entry.getName());
+                    if (!entry.isDirectory()) {
+                        entryDestination.getParentFile().mkdirs();
+                        try (InputStream in = zipFile.getInputStream(entry);
+                             OutputStream out = new FileOutputStream(entryDestination)) {
+                            IOUtils.copy(in, out);
+                        }
+                    }
+                }
+            }
+        } else {
+            Process process = new ProcessBuilder("unzip", "-d", outputDir, sourceFile).start();
+            try {
+                process.waitFor();
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                throw new IOException(e);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/70908dfb/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
new file mode 100644
index 0000000..e98262a
--- /dev/null
+++ b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
@@ -0,0 +1,105 @@
+/*
+ * 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.asterix.server.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.Collections;
+import java.util.logging.Logger;
+
+import org.apache.asterix.common.utils.ServletUtil.Servlets;
+import org.apache.asterix.test.aql.TestExecutor;
+import org.apache.asterix.test.common.TestHelper;
+import org.apache.asterix.testframework.context.TestCaseContext.OutputFormat;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import static org.apache.asterix.test.common.TestHelper.joinPath;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class SampleLocalClusterIT {
+
+    // Important paths and files for this test.
+
+    // The "target" subdirectory of asterix-server. All outputs go here.
+    private static final String TARGET_DIR = joinPath(/*System.getProperty("basedir"),*/ "target");
+
+    // Directory where the NCs create and store all data, as configured by
+    // src/test/resources/NCServiceExecutionIT/cc.conf.
+    private static final String OUTPUT_DIR = joinPath(TARGET_DIR, "sample-local-cluster");
+
+    private static final String LOCAL_SAMPLES_DIR = joinPath(OUTPUT_DIR, "samples", "local");
+
+    private static final Logger LOGGER = Logger.getLogger(SampleLocalClusterIT.class.getName());
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        // Create actual-results output directory.
+        File outDir = new File(OUTPUT_DIR);
+
+        // Remove any instance data from previous runs.
+        if (outDir.isDirectory()) {
+            FileUtils.deleteDirectory(outDir);
+        }
+        outDir.mkdirs();
+
+        String installerZip = joinPath(TARGET_DIR,
+                new File(TARGET_DIR).list((dir, name) -> name.matches("asterix-server.*-binary-assembly.zip"))[0]);
+
+        TestHelper.unzip(installerZip, OUTPUT_DIR);
+    }
+
+    @Test
+    public void test0_startCluster() throws Exception {
+        Process process = new ProcessBuilder(joinPath(LOCAL_SAMPLES_DIR, "bin/start-sample-cluster.sh"))
+                .inheritIO().start();
+        Assert.assertEquals(process.waitFor(), 0);
+    }
+
+    @Test
+    public void test1_sanityQuery() throws Exception {
+        TestExecutor testExecutor = new TestExecutor();
+        InputStream resultStream = testExecutor.executeQuery("1+1", OutputFormat.ADM,
+                "http://127.0.0.1:19002" + Servlets.AQL_QUERY.getPath(), Collections.emptyList());
+        StringWriter sw = new StringWriter();
+        IOUtils.copy(resultStream, sw);
+        Assert.assertEquals(sw.toString().trim(), "2");
+    }
+
+    @Test
+    public void test2_stopCluster() throws Exception {
+        Process process = new ProcessBuilder(joinPath(LOCAL_SAMPLES_DIR, "bin/stop-sample-cluster.sh"))
+                .inheritIO().start();
+        Assert.assertEquals(process.waitFor(), 0);
+        try {
+            new URL("http://127.0.0.1:19002").openConnection().connect();
+            Assert.assertTrue("Expected connection to be refused.", false);
+        } catch (IOException e) {
+            // expected
+        }
+    }
+}