Updated Branches: refs/heads/blur-console-v2 629009eff -> 710e6c111
Added tests Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/337d8b5e Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/337d8b5e Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/337d8b5e Branch: refs/heads/blur-console-v2 Commit: 337d8b5e1e47047d5d6c0d193c28fb267ba1707a Parents: 629009e Author: Chris Rohr <[email protected]> Authored: Thu Oct 17 18:51:09 2013 -0400 Committer: Chris Rohr <[email protected]> Committed: Thu Oct 17 18:51:09 2013 -0400 ---------------------------------------------------------------------- contrib/blur-console/.gitignore | 1 + contrib/blur-console/pom.xml | 177 ++++++++++--------- .../blur/console/servlets/DashboardServlet.java | 8 +- .../org/apache/blur/console/util/Config.java | 1 + .../org/apache/blur/console/util/NodeUtil.java | 7 +- .../org/apache/blur/console/util/TableUtil.java | 6 +- .../apache/blur/console/ConsoleTestBase.java | 30 ++++ .../apache/blur/console/util/ConfigTest.java | 38 ++++ .../apache/blur/console/util/HttpUtilTest.java | 122 +++++++++++++ .../apache/blur/console/util/NodeUtilTest.java | 53 ++++++ .../apache/blur/console/util/TableUtilTest.java | 65 +++++++ .../src/test/resources/blur-site.properties | 27 +++ 12 files changed, 442 insertions(+), 93 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/.gitignore ---------------------------------------------------------------------- diff --git a/contrib/blur-console/.gitignore b/contrib/blur-console/.gitignore new file mode 100644 index 0000000..61faf4d --- /dev/null +++ b/contrib/blur-console/.gitignore @@ -0,0 +1 @@ +test-data http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/pom.xml ---------------------------------------------------------------------- diff --git a/contrib/blur-console/pom.xml b/contrib/blur-console/pom.xml index 521b3e3..83c82d5 100644 --- a/contrib/blur-console/pom.xml +++ b/contrib/blur-console/pom.xml @@ -1,90 +1,103 @@ <?xml version="1.0" encoding="UTF-8" ?> -<!-- -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 +<!-- 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. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - http://www.apache.org/licenses/LICENSE-2.0 + <modelVersion>4.0.0</modelVersion> -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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.apache.blur</groupId> + <artifactId>blur</artifactId> + <version>0.3.0-incubating-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.blur</groupId> - <artifactId>blur</artifactId> - <version>0.3.0-incubating-SNAPSHOT</version> - <relativePath>../../pom.xml</relativePath> - </parent> + <groupId>org.apache.blur</groupId> + <artifactId>blur-console</artifactId> + <packaging>jar</packaging> + <name>Blur Console</name> - <groupId>org.apache.blur</groupId> - <artifactId>blur-console</artifactId> - <packaging>jar</packaging> - <name>Blur Console</name> + <dependencies> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-thrift</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>1.8.1</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-core-asl</artifactId> + <version>1.8.1</version> + </dependency> - <dependencies> - <dependency> - <groupId>org.apache.blur</groupId> - <artifactId>blur-thrift</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.blur</groupId> - <artifactId>blur-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-mapper-asl</artifactId> - <version>1.8.1</version> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-core-asl</artifactId> - <version>1.8.1</version> - </dependency> - - </dependencies> + <!-- Test Dependancies --> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-core</artifactId> + <version>0.3.0-incubating-SNAPSHOT</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.blur</groupId> + <artifactId>blur-util</artifactId> + <version>0.3.0-incubating-SNAPSHOT</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-test</artifactId> + <version>1.2.1</version> + <scope>test</scope> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.5.1</version> - <inherited>true</inherited> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.2.1</version> - <executions> - <execution> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.apache.blur.console.Main</mainClass> - </configuration> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.5.1</version> + <inherited>true</inherited> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.2.1</version> + <executions> + <execution> + <goals> + <goal>java</goal> + </goals> + </execution> + </executions> + <configuration> + <mainClass>org.apache.blur.console.Main</mainClass> + </configuration> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java index cad5ab0..c813c0f 100644 --- a/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java +++ b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java @@ -67,7 +67,9 @@ public class DashboardServlet extends HttpServlet { nodeData.put("zookeepers", NodeUtil.getZookeeperStatus()); nodeData.put("controllers", NodeUtil.getControllerStatus()); nodeData.put("clusters", NodeUtil.getClusterStatus()); - } catch (JSONException e) { + } catch (IOException e) { + throw new IOException(e); + } catch (Exception e) { sendError(response, e); return; } @@ -76,7 +78,7 @@ public class DashboardServlet extends HttpServlet { } private void sendTableStatus(HttpServletResponse response) throws IOException { - String tableData = "{}"; + Map<String, Object> tableData = new HashMap<String, Object>(); try { tableData = TableUtil.getTableStatus(); @@ -87,7 +89,7 @@ public class DashboardServlet extends HttpServlet { return; } - HttpUtil.sendResponse(response, tableData.toString(), HttpUtil.JSON); + HttpUtil.sendResponse(response, new ObjectMapper().writeValueAsString(tableData), HttpUtil.JSON); } private void sendQueryStatus(HttpServletResponse response) throws IOException { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java index 563ea14..87dcbac 100644 --- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java +++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java @@ -43,6 +43,7 @@ public class Config { public static String getConnectionString() throws IOException { ZookeeperClusterStatus zk = new ZookeeperClusterStatus(blurConfig.get("blur.zookeeper.connection"), blurConfig); List<String> allControllers = zk.getControllerServerList(); + zk.close(); return StringUtils.join(allControllers, ","); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java index a0ac42c..93b133d 100644 --- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java +++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java @@ -34,11 +34,10 @@ import java.util.Set; import org.apache.blur.manager.clusterstatus.ZookeeperClusterStatus; import org.apache.commons.collections.CollectionUtils; -import org.json.JSONException; public class NodeUtil { @SuppressWarnings("unchecked") - public static Map<String, Object> getControllerStatus() throws JSONException, IOException { + public static Map<String, Object> getControllerStatus() throws IOException { ZookeeperClusterStatus zk = new ZookeeperClusterStatus(Config.getBlurConfig().get("blur.zookeeper.connection"), Config.getBlurConfig()); @@ -83,7 +82,7 @@ public class NodeUtil { return data; } - public static List<Map<String, Object>> getClusterStatus() throws IOException, JSONException { + public static List<Map<String, Object>> getClusterStatus() throws IOException { ZookeeperClusterStatus zk = new ZookeeperClusterStatus(Config.getBlurConfig().get("blur.zookeeper.connection"), Config.getBlurConfig()); @@ -129,7 +128,7 @@ public class NodeUtil { return data; } - public static Map<String, Object> getZookeeperStatus() throws IOException, JSONException { + public static Map<String, Object> getZookeeperStatus() throws IOException { String[] connections = Config.getBlurConfig().get("blur.zookeeper.connection").split(","); Set<String> onlineZookeepers = new HashSet<String>(); Set<String> offlineZookeepers = new HashSet<String>(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java index 7cc05bb..2e65ed5 100644 --- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java +++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/TableUtil.java @@ -27,11 +27,9 @@ import org.apache.blur.thirdparty.thrift_0_9_0.TException; import org.apache.blur.thrift.BlurClient; import org.apache.blur.thrift.generated.Blur.Iface; import org.apache.blur.thrift.generated.BlurException; -import org.codehaus.jackson.map.ObjectMapper; -import org.json.JSONException; public class TableUtil { - public static String getTableStatus() throws IOException, BlurException, TException, JSONException { + public static Map<String, Object> getTableStatus() throws IOException, BlurException, TException { Iface client = BlurClient.getClient(Config.getConnectionString()); List<String> clusters = client.shardClusterList(); @@ -102,6 +100,6 @@ public class TableUtil { data.put("chart", datasets); data.put("clusters", clusters); - return new ObjectMapper().writeValueAsString(data); + return data; } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/test/java/org/apache/blur/console/ConsoleTestBase.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/test/java/org/apache/blur/console/ConsoleTestBase.java b/contrib/blur-console/src/test/java/org/apache/blur/console/ConsoleTestBase.java new file mode 100644 index 0000000..e0f3a9e --- /dev/null +++ b/contrib/blur-console/src/test/java/org/apache/blur/console/ConsoleTestBase.java @@ -0,0 +1,30 @@ +package org.apache.blur.console; + +import java.io.File; +import java.io.IOException; + +import org.apache.blur.MiniCluster; +import org.apache.blur.console.util.Config; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class ConsoleTestBase { + protected static MiniCluster cluster; + + @BeforeClass + public static void startup() { + cluster = new MiniCluster(); + cluster.startBlurCluster(new File("./test-data").getAbsolutePath(), 1, 1); + } + + @AfterClass + public static void shutdown() { + cluster.shutdownBlurCluster(); + } + + protected void setupConfigIfNeeded() throws IOException { + if (Config.getBlurConfig() == null) { + Config.setupConfig(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/test/java/org/apache/blur/console/util/ConfigTest.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/test/java/org/apache/blur/console/util/ConfigTest.java b/contrib/blur-console/src/test/java/org/apache/blur/console/util/ConfigTest.java new file mode 100644 index 0000000..8569b1e --- /dev/null +++ b/contrib/blur-console/src/test/java/org/apache/blur/console/util/ConfigTest.java @@ -0,0 +1,38 @@ +package org.apache.blur.console.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.InetAddress; + +import org.apache.blur.BlurConfiguration; +import org.apache.blur.console.ConsoleTestBase; +import org.apache.commons.lang.StringUtils; +import org.junit.Before; +import org.junit.Test; + +public class ConfigTest extends ConsoleTestBase { + + @Before + public void setup() throws IOException { + Config.setupConfig(); + } + + @Test + public void testGetConsolePort() { + assertEquals(8080, Config.getConsolePort()); + } + + @Test + public void testGetBlurConfig() { + BlurConfiguration blurConfig = Config.getBlurConfig(); + assertNotNull(blurConfig); + } + + @Test + public void testGetConnectionString() throws IOException { + assertTrue(StringUtils.contains(Config.getConnectionString(), InetAddress.getLocalHost().getHostName())); + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/test/java/org/apache/blur/console/util/HttpUtilTest.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/test/java/org/apache/blur/console/util/HttpUtilTest.java b/contrib/blur-console/src/test/java/org/apache/blur/console/util/HttpUtilTest.java new file mode 100644 index 0000000..1e4c48a --- /dev/null +++ b/contrib/blur-console/src/test/java/org/apache/blur/console/util/HttpUtilTest.java @@ -0,0 +1,122 @@ +package org.apache.blur.console.util; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Test; + +public class HttpUtilTest { + + @Test + public void testSendResponse() throws IOException { + MockHttpServletResponse mockResponse = new MockHttpServletResponse(); + + HttpUtil.sendResponse(mockResponse, "Test content", "text/plain"); + + assertEquals("text/plain", mockResponse.getContentType()); + assertEquals(200, mockResponse.status); + assertEquals("Test content".getBytes().length, mockResponse.contentLength); + assertEquals("Test content", mockResponse.out.toString()); + } + + private class MockHttpServletResponse implements HttpServletResponse { + public String contentType; + public int contentLength; + public int status; + public ByteArrayOutputStream out; + + @Override + public void setContentType(String type) { + contentType = type; + } + + @Override + public void setContentLength(int len) { + contentLength = len; + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + out = new ByteArrayOutputStream(); + return new ServletOutputStream() { + @Override + public void write(int b) throws IOException { + out.write(b); + } + }; + } + + @Override + public String getContentType() { + return contentType; + } + + @Override + public void setStatus(int sc) { + status = sc; + } + + @Override + public void setLocale(Locale loc) {} + @Override + public void setCharacterEncoding(String charset) {} + @Override + public void setBufferSize(int size) {} + @Override + public void resetBuffer() {} + @Override + public void reset() {} + @Override + public boolean isCommitted() { return false; } + @Override + public PrintWriter getWriter() throws IOException { return null; } + @Override + public Locale getLocale() { return null; } + @Override + public String getCharacterEncoding() { return null; } + @Override + public int getBufferSize() { return 0; } + @Override + public void flushBuffer() throws IOException {} + @Override + public void setStatus(int sc, String sm) {} + @Override + public void setIntHeader(String name, int value) {} + @Override + public void setHeader(String name, String value) {} + @Override + public void setDateHeader(String name, long date) {} + @Override + public void sendRedirect(String location) throws IOException {} + @Override + public void sendError(int sc, String msg) throws IOException {} + @Override + public void sendError(int sc) throws IOException {} + @Override + public String encodeUrl(String url) { return null; } + @Override + public String encodeURL(String url) { return null; } + @Override + public String encodeRedirectUrl(String url) { return null; } + @Override + public String encodeRedirectURL(String url) { return null; } + @Override + public boolean containsHeader(String name) { return false; } + @Override + public void addIntHeader(String name, int value) {} + @Override + public void addHeader(String name, String value) {} + @Override + public void addDateHeader(String name, long date) {} + @Override + public void addCookie(Cookie cookie) {} + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/test/java/org/apache/blur/console/util/NodeUtilTest.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/test/java/org/apache/blur/console/util/NodeUtilTest.java b/contrib/blur-console/src/test/java/org/apache/blur/console/util/NodeUtilTest.java new file mode 100644 index 0000000..98fa004 --- /dev/null +++ b/contrib/blur-console/src/test/java/org/apache/blur/console/util/NodeUtilTest.java @@ -0,0 +1,53 @@ +package org.apache.blur.console.util; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.apache.blur.console.ConsoleTestBase; +import org.apache.blur.thirdparty.thrift_0_9_0.TException; +import org.apache.blur.thrift.generated.BlurException; +import org.junit.Before; +import org.junit.Test; + +public class NodeUtilTest extends ConsoleTestBase { + @Before + public void setup() throws BlurException, TException, IOException { + setupConfigIfNeeded(); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetControllerStatus() throws BlurException, IOException, TException { + Map<String, Object> nodeStatus = NodeUtil.getControllerStatus(); + + List<Map<String, int[][]>> chartData = (List<Map<String, int[][]>>) nodeStatus.get("chart"); + + assertEquals(1, chartData.get(0).get("data")[0][1]); + assertEquals(0, chartData.get(1).get("data")[0][1]); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetZookeeperStatus() throws BlurException, IOException, TException { + Map<String, Object> nodeStatus = NodeUtil.getZookeeperStatus(); + + List<Map<String, int[][]>> chartData = (List<Map<String, int[][]>>) nodeStatus.get("chart"); + + assertEquals(1, chartData.get(0).get("data")[0][1]); + assertEquals(0, chartData.get(1).get("data")[0][1]); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetClusterStatus() throws BlurException, IOException, TException { + List<Map<String, Object>> nodeStatus = NodeUtil.getClusterStatus(); + + List<Map<String, int[][]>> chartData = (List<Map<String, int[][]>>) nodeStatus.get(0).get("chart"); + + assertEquals(1, chartData.get(0).get("data")[0][1]); + assertEquals(0, chartData.get(1).get("data")[0][1]); + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/test/java/org/apache/blur/console/util/TableUtilTest.java ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/test/java/org/apache/blur/console/util/TableUtilTest.java b/contrib/blur-console/src/test/java/org/apache/blur/console/util/TableUtilTest.java new file mode 100644 index 0000000..713164a --- /dev/null +++ b/contrib/blur-console/src/test/java/org/apache/blur/console/util/TableUtilTest.java @@ -0,0 +1,65 @@ +package org.apache.blur.console.util; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.apache.blur.console.ConsoleTestBase; +import org.apache.blur.thirdparty.thrift_0_9_0.TException; +import org.apache.blur.thrift.BlurClient; +import org.apache.blur.thrift.generated.Blur.Iface; +import org.apache.blur.thrift.generated.BlurException; +import org.apache.blur.thrift.generated.TableDescriptor; +import org.junit.Before; +import org.junit.Test; + +public class TableUtilTest extends ConsoleTestBase { + + @Before + public void ensureCleanTables() throws BlurException, TException, IOException { + setupConfigIfNeeded(); + + Iface client = BlurClient.getClient(cluster.getControllerConnectionStr()); + List<String> tableList = client.tableList(); + if (!tableList.isEmpty()) { + for (String table : tableList) { + client.disableTable(table); + client.removeTable(table, true); + } + } + } + + @SuppressWarnings("unchecked") + @Test + public void testGetTableStatusNoTables() throws BlurException, IOException, TException { + Map<String, Object> tableStatus = TableUtil.getTableStatus(); + + List<Map<String, List<List<Integer>>>> chartData = (List<Map<String, List<List<Integer>>>>) tableStatus.get("chart"); + + assertEquals(0, chartData.get(0).get("data").get(0).get(1).intValue()); + assertEquals(0, chartData.get(1).get("data").get(0).get(1).intValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetTableStatus() throws BlurException, TException, IOException { + Iface client = BlurClient.getClient(cluster.getControllerConnectionStr()); + + TableDescriptor td = new TableDescriptor(); + td.setShardCount(11); + td.setTableUri("file:///tmp/unitTable"); + td.setCluster("default"); + td.setName("unitTable"); + td.setEnabled(true); + client.createTable(td); + + Map<String, Object> tableStatus = TableUtil.getTableStatus(); + + List<Map<String, List<List<Integer>>>> chartData = (List<Map<String, List<List<Integer>>>>) tableStatus.get("chart"); + + assertEquals(1, chartData.get(0).get("data").get(0).get(1).intValue()); + assertEquals(0, chartData.get(1).get("data").get(0).get(1).intValue()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/337d8b5e/contrib/blur-console/src/test/resources/blur-site.properties ---------------------------------------------------------------------- diff --git a/contrib/blur-console/src/test/resources/blur-site.properties b/contrib/blur-console/src/test/resources/blur-site.properties new file mode 100644 index 0000000..fcf9d38 --- /dev/null +++ b/contrib/blur-console/src/test/resources/blur-site.properties @@ -0,0 +1,27 @@ +# 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. + +blur.zookeeper.connection=0.0.0.0:21810 +blur.cluster.name=default + +# +# Sets the default table location in hdfs. If left null the table uri property in +# the table descriptor will be required for all tables. +# +# blur.cluster.<cluster name here>.table.uri=<hdfs uri> +# +# Example: +# blur.cluster.default.table.uri=hdfs://namenode/blur/tables +#
