incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject git commit: merge in start of new tests stuffs blur-374
Date Fri, 19 Sep 2014 00:33:52 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master 532e3c884 -> dc0bb7ccb


merge in start of new tests stuffs blur-374


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/dc0bb7cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/dc0bb7cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/dc0bb7cc

Branch: refs/heads/master
Commit: dc0bb7ccbd651503cb7b29da98aee45f0e179a51
Parents: 532e3c8
Author: twilliams <twilliams@apache.org>
Authored: Thu Sep 18 20:33:38 2014 -0400
Committer: twilliams <twilliams@apache.org>
Committed: Thu Sep 18 20:33:38 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/thrift/BaseClusterTest.java |  63 ++++++++
 .../org/apache/blur/thrift/BlurClusterTest.java |  44 +-----
 .../java/org/apache/blur/thrift/FacetTests.java |  79 ++++++++++
 .../blur/thrift/IntegrationTestSuite.java       |  71 +++++++++
 .../org/apache/blur/thrift/QueryBuilder.java    |  66 ++++++++
 .../org/apache/blur/thrift/SuiteCluster.java    |  74 +++++++++
 .../java/org/apache/blur/thrift/TableGen.java   | 157 +++++++++++++++++++
 .../java/org/apache/blur/thrift/TermsTests.java |  47 ++++++
 8 files changed, 558 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/BaseClusterTest.java b/blur-core/src/test/java/org/apache/blur/thrift/BaseClusterTest.java
new file mode 100644
index 0000000..f32b58f
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/BaseClusterTest.java
@@ -0,0 +1,63 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class BaseClusterTest {
+	  protected static String TABLE_PATH = new File("./target/tmp/test-data/test-tables").getAbsolutePath();
+	  private static boolean _managing;
+
+	  @BeforeClass
+	  public static void startup() throws IOException {
+	    if (!SuiteCluster.isClusterSetup()) {
+	      SuiteCluster.setupMiniCluster();
+	      _managing = true;
+	    }
+	    File file = new File("test-data");
+	    if (file.exists()) {
+	      rmr(file);
+	    }
+	  }
+
+	  private static void rmr(File file) {
+	    if (!file.exists()) {
+	      return;
+	    }
+	    if (file.isDirectory()) {
+	      for (File f : file.listFiles()) {
+	        rmr(f);
+	      }
+	    }
+	    file.delete();
+	  }
+
+	  @AfterClass
+	  public static void shutdown() throws IOException {
+	    if (_managing) {
+	      SuiteCluster.shutdownMiniCluster();
+	    }
+	  }
+	  
+	  public Iface getClient() {
+	    return SuiteCluster.getClient();
+	  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java b/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
index 09a9be5..d66cf1a 100644
--- a/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
+++ b/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
@@ -466,37 +466,7 @@ public class BlurClusterTest {
 
   }
 
-  @Test
-  public void testQueryWithFacetsWithMins() throws BlurException, TException, IOException,
InterruptedException {
-    final String tableName = "testQueryWithFacetsWithMins";
-    createTable(tableName);
-    int pass = 1;
-    loadTable(tableName, pass);
-    Iface client = getClient();
-    BlurQuery blurQueryRow = new BlurQuery();
-    Query queryRow = new Query();
-    // queryRow.setQuery("test.test:value");
-    queryRow.setQuery("*");
-    blurQueryRow.setQuery(queryRow);
-    blurQueryRow.setUseCacheIfPresent(false);
-    blurQueryRow.setCacheResult(false);
-    blurQueryRow.setSelector(new Selector());
-    blurQueryRow.addToFacets(new Facet("test.facetFixed:test", 50));
-
-    BlurResults resultsRow = client.query(tableName, blurQueryRow);
-    // assertRowResults(resultsRow);
-    System.out.println("Pass [" + pass + "]");
-    assertEquals(numberOfDocs * pass, resultsRow.getTotalResults());
-
-    List<Long> facetCounts = resultsRow.getFacetCounts();
-    for (Long l : facetCounts) {
-      System.out.println("Count [" + l + "]");
-      assertTrue(l >= 50);
-    }
-    pass++;
-
-  }
-
+ 
   @Test
   public void testBatchFetch() throws BlurException, TException, InterruptedException, IOException
{
     String tableName = "testBatchFetch";
@@ -776,18 +746,6 @@ public class BlurClusterTest {
   }
 
   @Test
-  public void testTermsList() throws BlurException, TException, IOException, InterruptedException
{
-    final String tableName = "testTermsList";
-    createTable(tableName);
-    loadTable(tableName);
-    Iface client = getClient();
-    List<String> terms = client.terms(tableName, "test", "test", null, (short) 10);
-    List<String> list = new ArrayList<String>();
-    list.add("value");
-    assertEquals(list, terms);
-  }
-
-  @Test
   public void testTrucateRaceCondition() throws BlurException, TException, IOException, InterruptedException
{
     String tableName = "testTrucateRaceCondition";
     createTable(tableName);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/FacetTests.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/FacetTests.java b/blur-core/src/test/java/org/apache/blur/thrift/FacetTests.java
new file mode 100644
index 0000000..433fa16
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/FacetTests.java
@@ -0,0 +1,79 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.BlurQuery;
+import org.apache.blur.thrift.generated.BlurResults;
+import org.apache.blur.thrift.generated.Facet;
+import org.apache.blur.thrift.generated.Query;
+import org.apache.blur.thrift.generated.Selector;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class FacetTests extends BaseClusterTest {
+
+  @Test
+  public void testQueryWithFacets() throws BlurException, TException, IOException, InterruptedException
{
+    String table = "testQueryWithFacets";
+    TableGen.define(table)
+      .cols("test", "string:facet")
+      .addRow(20, "r1", "rec###", "value-###")
+      .build(getClient());
+    
+    QueryBuilder qb = QueryBuilder.define("*");
+    for (int i = 0; i < 250; i++) {
+      qb.withFacet("test.facet:" + i, Long.MAX_VALUE);
+    }
+
+    BlurResults resultsRow = qb.run(table, getClient());
+    assertEquals(1, resultsRow.getTotalResults());
+  }
+
+  
+  @Test
+  public void testQueryWithFacetsWithMins() throws BlurException, TException, IOException,
InterruptedException {
+    final String tableName = "testQueryWithFacetsWithMins";
+    int numberOfRows = 100;
+    
+    TableGen.define(tableName)
+    .cols("test", "string:facet", "string:facetFixed")
+    .addRows(numberOfRows, 20, "r1", "rec###", "value-###", "test")
+    .build(getClient());
+    
+    
+    BlurResults resultsRow = QueryBuilder.define("*")
+        .withFacet("test.facetFixed:test", 50)
+        .run(tableName, getClient());
+
+    assertEquals(numberOfRows, resultsRow.getTotalResults());
+
+    List<Long> facetCounts = resultsRow.getFacetCounts();
+    for (Long l : facetCounts) {
+      assertTrue(l >= 50);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/IntegrationTestSuite.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/IntegrationTestSuite.java b/blur-core/src/test/java/org/apache/blur/thrift/IntegrationTestSuite.java
new file mode 100644
index 0000000..0c10f39
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/IntegrationTestSuite.java
@@ -0,0 +1,71 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.junit.After;
+import org.junit.ClassRule;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ TermsTests.class, FacetTests.class })
+public class IntegrationTestSuite {
+  @ClassRule
+  public static ExternalResource testCluster = new ExternalResource() {
+
+    private boolean _managing;
+
+    @Override
+    protected void after() {
+      if (_managing) {
+        try {
+          SuiteCluster.shutdownMiniCluster();
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        }
+      }
+    }
+
+    @Override
+    protected void before() throws Throwable {
+      if (!SuiteCluster.isClusterSetup()) {
+        _managing = true;
+        try {
+          SuiteCluster.setupMiniCluster();
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        }
+      }
+    }
+  };
+  
+  @After
+  public void tearDown() throws BlurException, TException {
+    Iface client = SuiteCluster.getClient();
+    List<String> tableList = client.tableList();
+    for (String table : tableList) {
+      client.disableTable(table);
+      client.removeTable(table, true);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/QueryBuilder.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/QueryBuilder.java b/blur-core/src/test/java/org/apache/blur/thrift/QueryBuilder.java
new file mode 100644
index 0000000..8ed8d27
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/QueryBuilder.java
@@ -0,0 +1,66 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import java.util.List;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.BlurQuery;
+import org.apache.blur.thrift.generated.BlurResults;
+import org.apache.blur.thrift.generated.Facet;
+import org.apache.blur.thrift.generated.Query;
+import org.apache.blur.thrift.generated.Selector;
+
+import com.google.common.collect.Lists;
+
+public class QueryBuilder {
+  private String queryString;
+  private Selector selector = new Selector();
+  private List<Facet> facets = Lists.newArrayList();
+ 
+  
+  private QueryBuilder(String queryString) {
+    this.queryString = queryString;
+  }
+  
+  public static QueryBuilder define(String q) {
+    return new QueryBuilder(q);
+  }
+  
+  public QueryBuilder withFacet(String facetQuery, long facetCount) {
+    facets.add(new Facet(facetQuery, facetCount));
+    return this;
+  }
+  
+  public BlurQuery build() {
+    BlurQuery blurQuery = new BlurQuery();
+    Query queryRow = new Query();
+    queryRow.setQuery(queryString);
+    blurQuery.setQuery(queryRow);
+    blurQuery.setUseCacheIfPresent(false);
+    blurQuery.setCacheResult(false);
+    blurQuery.setSelector(selector);
+    blurQuery.setFacets(facets);
+    
+    return blurQuery;
+  }
+
+  public BlurResults run(String table, Iface client) throws BlurException, TException {
+    return client.query(table, build());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/SuiteCluster.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/SuiteCluster.java b/blur-core/src/test/java/org/apache/blur/thrift/SuiteCluster.java
new file mode 100644
index 0000000..db823a7
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/SuiteCluster.java
@@ -0,0 +1,74 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import java.io.File;
+import java.io.IOException;
+
+
+import org.apache.blur.MiniCluster;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SuiteCluster {
+  private static final Log log = LogFactory.getLog(SuiteCluster.class);
+  private static final File TMPDIR = new File(System.getProperty("blur.tmp.dir", "./target/tmp_SuiteCluster"));
+  private static MiniCluster cluster;
+
+  public static void shutdownMiniCluster() throws IOException {
+    if (cluster != null) {
+      cluster.shutdownBlurCluster();
+      File file = new File(TMPDIR, "blur-cluster-test");
+      if (file.exists()) {
+        FileUtils.deleteDirectory(file);
+      }
+    }
+  }
+
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  public static void setupMiniCluster() throws IOException {
+    File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
+    testDirectory.mkdirs();
+
+    testDirectory.delete();
+    if (cluster == null) {
+      cluster = new MiniCluster();
+      cluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3,
true);
+
+      System.out.println("MiniCluster started at " + cluster.getControllerConnectionStr());
+
+    }
+  }
+
+  public static Iface getClient() {
+    return BlurClient.getClient(cluster.getControllerConnectionStr());
+  }
+
+  public static boolean isClusterSetup() {
+    return cluster != null;
+  }
+
+  public static String getFileSystemUri() {
+    try {
+      return cluster.getFileSystemUri().toString();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/TableGen.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/TableGen.java b/blur-core/src/test/java/org/apache/blur/thrift/TableGen.java
new file mode 100644
index 0000000..b925ce4
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/TableGen.java
@@ -0,0 +1,157 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import java.util.List;
+import java.util.Map;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.Column;
+import org.apache.blur.thrift.generated.ColumnDefinition;
+import org.apache.blur.thrift.generated.Record;
+import org.apache.blur.thrift.generated.RecordMutation;
+import org.apache.blur.thrift.generated.RecordMutationType;
+import org.apache.blur.thrift.generated.RowMutation;
+import org.apache.blur.thrift.generated.RowMutationType;
+import org.apache.blur.thrift.generated.TableDescriptor;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class TableGen {
+  private static final String NUM_PATTERN = "###";
+  private static final int RECORD_ID_COUNTER = -1;
+  private String table;
+  private int shardCount = 1;
+  private String uri;
+  private List<ColumnDefinition> cols = Lists.newArrayList();
+  private Map<String, List<RecordMutation>> vals = Maps.newHashMap();
+
+  private TableGen(String tableName) {
+    this.table = tableName;
+  }
+
+  public static TableGen define(String name) {
+    return new TableGen(name);
+  }
+
+  public TableGen at(String uri) {
+    this.uri = uri;
+    return this;
+  }
+
+  public TableGen cols(String family, String... columns) {
+    for (String c : columns) {
+      ColumnDefinition cd = new ColumnDefinition();
+      String colName = c;
+
+      if (c.contains(":")) {
+        String[] colInfo = c.split(":");
+        cd.setFieldType(colInfo[0]);
+        colName = colInfo[1];
+      }
+
+      cd.setFamily(family);
+      cd.setColumnName(colName);
+      cols.add(cd);
+    }
+
+    return this;
+  }
+  
+  public TableGen addRows(int rowCount, int recordCount, String row, String rec, Object...
values) {
+    
+    for(int i = 0; i < rowCount; i++) {
+      String rowId = row + "-" + i;
+      if(row.contains(NUM_PATTERN)) {
+        rowId = row.replace(NUM_PATTERN, Integer.toString(i));
+      }
+      addRow(recordCount, rowId, rec, values);
+    }
+    
+    return this;
+  }
+
+  public TableGen addRow(int number, String row, String rec, Object... values) {
+    Map<Integer, Integer> counters = Maps.newHashMap();
+    counters.put(RECORD_ID_COUNTER, 0);
+
+    for (int i = 0; i < values.length; i++) {
+      if (values[i].toString().contains(NUM_PATTERN)) {
+        counters.put(i, 0);
+      }
+    }
+
+    for (int i = 0; i < number; i++) {
+      Object[] genValues = new Object[values.length];
+      for (int j = 0; j < values.length; j++) {
+        Integer counter = counters.get(j);
+        if (counter != null) {
+          genValues[j] = ((String) values[j]).replace(NUM_PATTERN, Integer.toString(counter));
+          counters.put(j, counter + 1);
+        } else {
+          genValues[j] = values[j].toString();
+        }
+      }
+      int recordCounter = counters.get(-1);
+      addRecord(row, rec.replace(NUM_PATTERN, Integer.toString(recordCounter)), genValues);
+      counters.put(RECORD_ID_COUNTER, recordCounter + 1);
+    }
+    
+    return this;
+  }
+
+  public TableGen addRecord(String row, String rec, Object... values) {
+    List<RecordMutation> records = vals.get(row);
+    if (records == null) {
+      records = Lists.newArrayList();
+      vals.put(row, records);
+    }
+
+    Record record = new Record();
+    record.setRecordId(rec);
+
+    for (int i = 0; i < cols.size(); i++) {
+      ColumnDefinition cd = cols.get(i);
+
+      record.setFamily(cd.getFamily());
+      record.addToColumns(new Column(cd.getColumnName(), values[i].toString()));
+    }
+    
+    records.add(new RecordMutation(RecordMutationType.REPLACE_ENTIRE_RECORD, record));
+
+    return this;
+  }
+
+  public void build(Iface client) throws BlurException, TException {
+    TableDescriptor tbl = new TableDescriptor();
+    tbl.setName(table);
+    tbl.setShardCount(shardCount);
+    if (uri == null) {
+      tbl.setTableUri(SuiteCluster.getFileSystemUri().toString() + "/blur/" + table);
+    } else {
+      tbl.setTableUri(uri);
+    }
+    client.createTable(tbl);
+
+    for (String rowId : vals.keySet()) {
+      client.mutate(new RowMutation(table, rowId, RowMutationType.REPLACE_ROW, vals.get(rowId)));
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dc0bb7cc/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java b/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
new file mode 100644
index 0000000..2048b7c
--- /dev/null
+++ b/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
@@ -0,0 +1,47 @@
+package org.apache.blur.thrift;
+/**
+ * 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.
+ */
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.BlurException;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class TermsTests extends BaseClusterTest {
+
+  @Test
+  public void testTermsList() throws BlurException, TException, IOException, InterruptedException
{
+    final String tableName = "testTermsList";
+    TableGen.define(tableName).cols("test", "col1")
+        .addRows(100, 20, "r1", "rec-###", "value").build(getClient());
+
+    List<String> terms = getClient().terms(tableName, "test", "col1", null, (short)
10);
+    List<String> list = Lists.newArrayList("value");
+    
+    assertEquals(list, terms);
+  }
+  @Test(expected=BlurException.class)
+  public void termsShouldFailOnUnknownTable() throws BlurException, TException {
+    getClient().terms("termsShouldFailOnUnknownTable", "test","col1", null, (short)10);
+  }
+
+}


Mime
View raw message