incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [20/50] [abbrv] Finished Server side of the console
Date Sat, 31 May 2014 14:21:53 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6cdce8ec/contrib/blur-console/src/test/java/org/apache/blur/console/util/QueryUtilTest.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/test/java/org/apache/blur/console/util/QueryUtilTest.java
b/contrib/blur-console/src/test/java/org/apache/blur/console/util/QueryUtilTest.java
index 5c2d564..0077cc8 100644
--- a/contrib/blur-console/src/test/java/org/apache/blur/console/util/QueryUtilTest.java
+++ b/contrib/blur-console/src/test/java/org/apache/blur/console/util/QueryUtilTest.java
@@ -17,8 +17,12 @@
 
 package org.apache.blur.console.util;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import org.apache.blur.console.ConsoleTestBase;
@@ -44,48 +48,41 @@ public class QueryUtilTest extends ConsoleTestBase {
 	public void setup() throws IOException, BlurException, TException {
 		setupConfigIfNeeded();
 		
-		Iface client = BlurClient.getClient(cluster.getControllerConnectionStr());
-		
-		TableDescriptor td = new TableDescriptor();
-		td.setShardCount(11);
-		td.setTableUri("file://" + TABLE_PATH + "/queryUnitTable");
-		td.setCluster("default");
-		td.setName("queryUnitTable");
-		td.setEnabled(true);
-		client.createTable(td);
+		Iface client = BlurClient.getClient(Config.getConnectionString());
 		
-//		Record record = new Record();
-//	    record.setRecordId("abcd");
-//	    record.setFamily("fam0");
-//	    List<Column> columns = new ArrayList<Column>();
-//	    columns.add(new Column("col0", "testvalue"));
-//	    record.setColumns(columns);
-//
-//	    RecordMutation recordMutation = new RecordMutation();
-//	    recordMutation.setRecord(record);
-//	    recordMutation.setRecordMutationType(RecordMutationType.REPLACE_ENTIRE_RECORD);
-//
-//	    List<RecordMutation> recordMutations = new ArrayList<RecordMutation>();
-//	    recordMutations.add(recordMutation);
-//
-//	    RowMutation mutation = new RowMutation();
-//	    mutation.setTable("unitTable);
-//	    mutation.setRowId(rowid);
-//	    mutation.setRowMutationType(RowMutationType.UPDATE_ROW);
-//	    mutation.setRecordMutations(recordMutations);
-//
-//	    client.mutate(mutation);
+		if (!client.tableList().contains("queryUnitTable")) {
+			TableDescriptor td = new TableDescriptor();
+			td.setShardCount(11);
+			td.setTableUri("file://" + TABLE_PATH + "/queryUnitTable");
+			td.setCluster("default");
+			td.setName("queryUnitTable");
+			td.setEnabled(true);
+			client.createTable(td);
+			
+			Record record = new Record("abcd", "fam0", Arrays.asList(new Column[]{ new Column("col0",
"testvalue")}));
+			RecordMutation recordMutation = new RecordMutation(RecordMutationType.REPLACE_ENTIRE_RECORD,
record);
+			RowMutation rowMutation = new RowMutation("queryUnitTable", "12345", RowMutationType.REPLACE_ROW,
Arrays.asList(new RecordMutation[]{ recordMutation }));
+			client.mutate(rowMutation);
+		}
+	}
+	
+	@Test
+	public void testGetCurrentQueryCount() throws BlurException, IOException, TException {
+		Iface client = BlurClient.getClient(Config.getConnectionString());
+		BlurQuery query = new BlurQuery(
+				new Query("fam0.col0:*", true, ScoreType.SUPER, null, null), 
+				null, 
+				null, //new Selector(false, null, null, null, null, null, 0, 10, null), 
+				false, 0, 10, 1, 2000, UUID.randomUUID().toString(), "testUser", false, System.currentTimeMillis(),null,null);
+		client.query("queryUnitTable", query);
 		
-		Record record = new Record("abcd", "fam0", Arrays.asList(new Column[]{ new Column("col0",
"testvalue")}));
-		RecordMutation recordMutation = new RecordMutation(RecordMutationType.REPLACE_ENTIRE_RECORD,
record);
-		RowMutation rowMutation = new RowMutation("queryUnitTable", "12345", RowMutationType.REPLACE_ROW,
Arrays.asList(new RecordMutation[]{ recordMutation }));
-		client.mutate(rowMutation);
+		assertEquals(1, QueryUtil.getCurrentQueryCount());
 	}
 	
+	@SuppressWarnings("unchecked")
 	@Test
-	public void testGetQueryStatus() throws BlurException, IOException, TException {
-		Iface client = BlurClient.getClient(cluster.getControllerConnectionStr());
-		QueryUtil.getQueryStatus();
+	public void testGetQueries() throws IOException, BlurException, TException {
+		Iface client = BlurClient.getClient(Config.getConnectionString());
 		BlurQuery query = new BlurQuery(
 				new Query("fam0.col0:*", true, ScoreType.SUPER, null, null), 
 				null, 
@@ -93,6 +90,10 @@ public class QueryUtilTest extends ConsoleTestBase {
 				false, 0, 10, 1, 2000, UUID.randomUUID().toString(), "testUser", false, System.currentTimeMillis(),null,null);
 		client.query("queryUnitTable", query);
 		
-		QueryUtil.getQueryStatus();
+		Map<String, Object> queries = QueryUtil.getQueries();
+		
+		assertEquals(0, queries.get("slowQueries"));
+		assertEquals(2, ((List<Map<String, Object>>) queries.get("queries")).size());
+		assertEquals("testUser", ((List<Map<String, Object>>)queries.get("queries")).get(0).get("user"));
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6cdce8ec/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
index 7a84b0d..17a3109 100644
--- 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
@@ -37,7 +37,7 @@ public class TableUtilTest extends ConsoleTestBase {
 	public void ensureCleanTables() throws BlurException, TException, IOException {
 		setupConfigIfNeeded();
 		
-		Iface client = BlurClient.getClient(cluster.getControllerConnectionStr());
+		Iface client = BlurClient.getClient(Config.getConnectionString());
 		List<String> tableList = client.tableList();
 		if (!tableList.isEmpty()) {
 			for (String table : tableList) {
@@ -47,21 +47,17 @@ public class TableUtilTest extends ConsoleTestBase {
 		}
 	}
 	
-	@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");
+	public void testGetTableSummariesNoTables() throws BlurException, IOException, TException
{
+		List<Map<String, Object>> summaries = TableUtil.getTableSummaries();
 		
-		assertEquals(0, chartData.get(0).get("data").get(0).get(1).intValue());
-		assertEquals(0, chartData.get(1).get("data").get(0).get(1).intValue());
+		assertEquals(0, summaries.size());
 	}
 	
 	@SuppressWarnings("unchecked")
 	@Test
-	public void testGetTableStatus() throws BlurException, TException, IOException {
-		Iface client = BlurClient.getClient(cluster.getControllerConnectionStr());
+	public void testGetTableSummaries() throws BlurException, TException, IOException {
+		Iface client = BlurClient.getClient(Config.getConnectionString());
 		
 		TableDescriptor td = new TableDescriptor();
 		td.setShardCount(11);
@@ -71,11 +67,13 @@ public class TableUtilTest extends ConsoleTestBase {
 		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");
+		List<Map<String, Object>> summaries = TableUtil.getTableSummaries();
 		
-		assertEquals(1, chartData.get(0).get("data").get(0).get(1).intValue());
-		assertEquals(0, chartData.get(1).get("data").get(0).get(1).intValue());
+		assertEquals(1, summaries.size());
+		assertEquals(0l, summaries.get(0).get("rows"));
+		assertEquals(0l, summaries.get(0).get("records"));
+		assertEquals("default", summaries.get(0).get("cluster"));
+		assertEquals("tableUnitTable", summaries.get(0).get("name"));
+		assertEquals(0, ((List<String>) summaries.get(0).get("families")).size());
 	}
 }


Mime
View raw message