incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [18/51] [partial] Initial repackage to org.apache.
Date Mon, 03 Sep 2012 03:17:11 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java b/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
new file mode 100644
index 0000000..1045c7a
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
@@ -0,0 +1,156 @@
+package org.apache.blur.search;
+
+/**
+ * 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 junit.framework.Assert.assertTrue;
+import static org.apache.blur.lucene.LuceneConstant.LUCENE_VERSION;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+
+import org.apache.blur.analysis.BlurAnalyzer;
+import org.apache.blur.index.IndexWriter;
+import org.apache.blur.lucene.search.SuperParser;
+import org.apache.blur.thrift.generated.Column;
+import org.apache.blur.thrift.generated.Record;
+import org.apache.blur.thrift.generated.Row;
+import org.apache.blur.thrift.generated.ScoreType;
+import org.apache.blur.utils.RowIndexWriter;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.QueryWrapperFilter;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+
+public class RandomSuperQueryTest {
+
+  private static final int MOD_COLS_USED_FOR_SKIPPING = 3;
+  private static final int MAX_NUM_OF_DOCS = 10000;// 10000
+  private static final int MIN_NUM_COL_FAM = 3;// 3
+  private static final int MAX_NUM_COL_FAM = 20;// 20
+  private static final int MAX_NUM_DOCS_PER_COL_FAM = 25;// 25
+  private static final int MAX_NUM_COLS = 21;// 21
+  private static final int MIN_NUM_COLS = 3;// 3
+  private static final int MAX_NUM_OF_WORDS = 1000;
+  private static final int MOD_USED_FOR_SAMPLING = 1;//
+
+  private Random seedGen = new Random(1);
+
+  @Test
+  public void testRandomSuperQuery() throws CorruptIndexException, IOException, InterruptedException, ParseException {
+    long seed = seedGen.nextLong();
+
+    Filter filter = new QueryWrapperFilter(new MatchAllDocsQuery());
+
+    Random random = new Random(seed);
+    Collection<String> sampler = new HashSet<String>();
+    System.out.print("Creating index... ");
+    System.out.flush();
+    Directory directory = createIndex(random, sampler);
+    IndexReader reader = IndexReader.open(directory);
+    System.out.print("Running searches [" + sampler.size() + "]... ");
+    System.out.flush();
+    assertTrue(!sampler.isEmpty());
+    IndexSearcher searcher = new IndexSearcher(reader);
+    long s = System.currentTimeMillis();
+    for (String str : sampler) {
+      Query query = new SuperParser(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION), true, filter, ScoreType.AGGREGATE).parse(str);
+      TopDocs topDocs = searcher.search(query, 10);
+      assertTrue("seed [" + seed + "] {" + query + "} {" + s + "}", topDocs.totalHits > 0);
+    }
+    long e = System.currentTimeMillis();
+    System.out.println("Finished in [" + (e - s) + "] ms");
+  }
+
+  private Directory createIndex(Random random, Collection<String> sampler) throws CorruptIndexException, LockObtainFailedException, IOException {
+    Directory directory = new RAMDirectory();
+    String[] columnFamilies = genWords(random, MIN_NUM_COL_FAM, MAX_NUM_COL_FAM, "colfam");
+    Map<String, String[]> columns = new HashMap<String, String[]>();
+    for (int i = 0; i < columnFamilies.length; i++) {
+      columns.put(columnFamilies[i], genWords(random, MIN_NUM_COLS, MAX_NUM_COLS, "col"));
+    }
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
+    RowIndexWriter indexWriter = new RowIndexWriter(writer, new BlurAnalyzer(new StandardAnalyzer(LUCENE_VERSION)));
+    int numberOfDocs = random.nextInt(MAX_NUM_OF_DOCS) + 1;
+    for (int i = 0; i < numberOfDocs; i++) {
+      indexWriter.replace(false, generatSuperDoc(random, columns, sampler));
+    }
+    writer.close();
+    return directory;
+  }
+
+  private String[] genWords(Random random, int min, int max, String prefix) {
+    int numberOfColFam = random.nextInt(max - min) + min;
+    String[] str = new String[numberOfColFam];
+    for (int i = 0; i < numberOfColFam; i++) {
+      str[i] = genWord(random, prefix);
+    }
+    return str;
+  }
+
+  private Row generatSuperDoc(Random random, Map<String, String[]> columns, Collection<String> sampler) {
+    Row row = new Row().setId(Long.toString(random.nextLong()));
+    StringBuilder builder = new StringBuilder();
+    for (String colFam : columns.keySet()) {
+      String[] cols = columns.get(colFam);
+      for (int i = 0; i < random.nextInt(MAX_NUM_DOCS_PER_COL_FAM); i++) {
+        Record record = new Record();
+        record.setFamily(colFam);
+        record.setRecordId(Long.toString(random.nextLong()));
+        int staringLength = builder.length();
+        for (String column : cols) {
+          if (random.nextInt() % MOD_COLS_USED_FOR_SKIPPING == 0) {
+            String word = genWord(random, "word");
+            record.addToColumns(new Column(column, word));
+            if (random.nextInt() % MOD_USED_FOR_SAMPLING == 0) {
+              builder.append(" +" + colFam + "." + column + ":" + word);
+            }
+          }
+        }
+        if (builder.length() != staringLength) {
+          builder.append(" nojoin.nojoin ");
+        }
+        row.addToRecords(record);
+      }
+    }
+    String string = builder.toString().trim();
+    if (!string.isEmpty()) {
+      sampler.add(string);
+    }
+    return row;
+  }
+
+  private String genWord(Random random, String prefix) {
+    return prefix + random.nextInt(MAX_NUM_OF_WORDS);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java b/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java
new file mode 100644
index 0000000..9acccfe
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/search/SuperQueryTest.java
@@ -0,0 +1,215 @@
+package org.apache.blur.search;
+
+/**
+ * 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 junit.framework.Assert.assertEquals;
+import static org.apache.blur.lucene.LuceneConstant.LUCENE_VERSION;
+import static org.apache.blur.utils.BlurConstants.PRIME_DOC;
+import static org.apache.blur.utils.BlurConstants.PRIME_DOC_VALUE;
+import static org.apache.blur.utils.BlurConstants.ROW_ID;
+import static org.apache.blur.utils.BlurUtil.newColumn;
+import static org.apache.blur.utils.BlurUtil.newRecord;
+import static org.apache.blur.utils.BlurUtil.newRow;
+
+import java.io.IOException;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLongArray;
+
+import org.apache.blur.analysis.BlurAnalyzer;
+import org.apache.blur.index.IndexWriter;
+import org.apache.blur.lucene.search.FacetQuery;
+import org.apache.blur.lucene.search.SuperQuery;
+import org.apache.blur.thrift.generated.ScoreType;
+import org.apache.blur.utils.RowIndexWriter;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+
+public class SuperQueryTest {
+
+  private static final String PERSON_NAME = "person.name";
+  private static final String ADDRESS_STREET = "address.street";
+
+  private static final String STREET = "street";
+  private static final String ADDRESS = "address";
+  private static final String PERSON = "person";
+  private static final String NAME = "name";
+
+  private static final String NAME1 = "jon";
+  private static final String NAME2 = "jane";
+  private static final String STREET2 = "main st";
+  private static final String STREET1 = "main";
+
+  @Test
+  public void testSimpleSuperQuery() throws CorruptIndexException, IOException, InterruptedException {
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(new TermQuery(new Term(PERSON_NAME, NAME1))), Occur.MUST);
+    booleanQuery.add(wrapSuper(new TermQuery(new Term(ADDRESS_STREET, STREET1))), Occur.MUST);
+
+    Directory directory = createIndex();
+    IndexReader reader = IndexReader.open(directory);
+    printAll(new Term(PERSON_NAME, NAME1), reader);
+    printAll(new Term(ADDRESS_STREET, STREET1), reader);
+    printAll(new Term(PRIME_DOC, PRIME_DOC_VALUE), reader);
+    IndexSearcher searcher = new IndexSearcher(reader);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(2, topDocs.totalHits);
+    assertEquals("1", searcher.doc(topDocs.scoreDocs[0].doc).get(ROW_ID));
+    assertEquals("3", searcher.doc(topDocs.scoreDocs[1].doc).get(ROW_ID));
+  }
+
+  @Test
+  public void testAggregateScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.AGGREGATE), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.AGGREGATE), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    printTopDocs(topDocs);
+    assertEquals(3, topDocs.totalHits);
+    assertEquals(3.30, topDocs.scoreDocs[0].score, 0.01);
+    assertEquals(2.20, topDocs.scoreDocs[1].score, 0.01);
+    assertEquals(0.55, topDocs.scoreDocs[2].score, 0.01);
+  }
+
+  @Test
+  public void testBestScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.BEST), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.BEST), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+    assertEquals(2.20, topDocs.scoreDocs[0].score, 0.01);
+    assertEquals(2.20, topDocs.scoreDocs[1].score, 0.01);
+    assertEquals(0.55, topDocs.scoreDocs[2].score, 0.01);
+  }
+
+  private void printTopDocs(TopDocs topDocs) {
+    for (int i = 0; i < topDocs.totalHits; i++) {
+      System.out.println("doc " + i + " score " + topDocs.scoreDocs[i].score);
+    }
+
+  }
+
+  @Test
+  public void testConstantScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.CONSTANT), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.CONSTANT), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+    assertEquals(2.0, topDocs.scoreDocs[0].score, 0.01);
+    assertEquals(2.0, topDocs.scoreDocs[1].score, 0.01);
+    assertEquals(0.5, topDocs.scoreDocs[2].score, 0.01);
+  }
+
+  @Test
+  public void testSuperScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+    assertEquals(3.10, topDocs.scoreDocs[0].score, 0.01);
+    assertEquals(3.00, topDocs.scoreDocs[1].score, 0.01);
+    assertEquals(0.75, topDocs.scoreDocs[2].score, 0.01);
+  }
+
+  @Test
+  public void testSuperScoreTypesWithFacet() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
+
+    BooleanQuery f1 = new BooleanQuery();
+    f1.add(new TermQuery(new Term(PERSON_NAME, NAME1)), Occur.MUST);
+    f1.add(new TermQuery(new Term(PERSON_NAME, NAME2)), Occur.MUST);
+
+    Query[] facets = new Query[] { new SuperQuery(f1, ScoreType.CONSTANT) };
+    AtomicLongArray counts = new AtomicLongArray(facets.length);
+    FacetQuery query = new FacetQuery(booleanQuery, facets, counts);
+
+    TopDocs topDocs = searcher.search(query, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+    assertEquals(3.10, topDocs.scoreDocs[0].score, 0.01);
+    assertEquals(3.00, topDocs.scoreDocs[1].score, 0.01);
+    assertEquals(0.75, topDocs.scoreDocs[2].score, 0.01);
+  }
+
+  private void printAll(Term term, IndexReader reader) throws IOException {
+    TermDocs termDocs = reader.termDocs(term);
+    while (termDocs.next()) {
+      System.out.println(term + "=>" + termDocs.doc());
+    }
+  }
+
+  private static IndexSearcher createSearcher() throws Exception {
+    Directory directory = createIndex();
+    IndexReader reader = IndexReader.open(directory);
+    return new IndexSearcher(reader);
+  }
+
+  public static Directory createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
+    Directory directory = new RAMDirectory();
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
+    BlurAnalyzer analyzer = new BlurAnalyzer(new StandardAnalyzer(LUCENE_VERSION));
+    RowIndexWriter indexWriter = new RowIndexWriter(writer, analyzer);
+    indexWriter.replace(
+        false,
+        newRow("1", newRecord(PERSON, UUID.randomUUID().toString(), newColumn(NAME, NAME1)), newRecord(PERSON, UUID.randomUUID().toString(), newColumn(NAME, NAME1)),
+            newRecord(ADDRESS, UUID.randomUUID().toString(), newColumn(STREET, STREET1))));
+    indexWriter.replace(false,
+        newRow("2", newRecord(PERSON, UUID.randomUUID().toString(), newColumn(NAME, NAME2)), newRecord(ADDRESS, UUID.randomUUID().toString(), newColumn(STREET, STREET1))));
+    indexWriter.replace(false,
+        newRow("3", newRecord(PERSON, UUID.randomUUID().toString(), newColumn(NAME, NAME1)), newRecord(ADDRESS, UUID.randomUUID().toString(), newColumn(STREET, STREET2))));
+    ;
+    writer.close();
+    return directory;
+  }
+
+  private Query wrapSuper(Query query) {
+    return new SuperQuery(query, ScoreType.AGGREGATE);
+  }
+
+  private Query wrapSuper(String field, String value, ScoreType scoreType) {
+    return new SuperQuery(new TermQuery(new Term(field, value)), scoreType);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java b/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
new file mode 100644
index 0000000..76300f4
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
@@ -0,0 +1,84 @@
+package org.apache.blur.search;
+
+/**
+ * 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.apache.blur.lucene.LuceneConstant.LUCENE_VERSION;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.blur.lucene.search.IterablePaging;
+import org.apache.blur.lucene.search.IterablePaging.ProgressRef;
+import org.apache.blur.lucene.search.IterablePaging.TotalHitsRef;
+import org.apache.lucene.analysis.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+
+/**
+ * Testing the paging collector.
+ * 
+ * @author Aaron McCurry
+ */
+public class TestingPagingCollector {
+
+  @Test
+  public void testNothingYet() {
+
+  }
+
+  public static void main(String[] args) throws Exception {
+    IndexReader reader = getReaderFlatScore(13245);
+    IndexSearcher searcher = new IndexSearcher(reader);
+
+    TotalHitsRef totalHitsRef = new TotalHitsRef();
+    ProgressRef progressRef = new ProgressRef();
+
+    TermQuery query = new TermQuery(new Term("f1", "value"));
+    IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query, 100);
+
+    for (ScoreDoc sd : paging.skipTo(90).gather(20).totalHits(totalHitsRef).progress(progressRef)) {
+
+      System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits() + "] " + "searches [" + progressRef.searchesPerformed() + "] "
+          + "position [" + progressRef.currentHitPosition() + "] " + "doc id [" + sd.doc + "] " + "score [" + sd.score + "]");
+    }
+  }
+
+  private static IndexReader getReaderFlatScore(int length) throws Exception {
+    RAMDirectory directory = new RAMDirectory();
+    IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer()));
+    for (int i = 0; i < length; i++) {
+      Document document = new Document();
+      document.add(new Field("f1", "value", Store.NO, Index.ANALYZED_NO_NORMS));
+      indexWriter.addDocument(document);
+    }
+    indexWriter.close();
+    return IndexReader.open(directory);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java b/src/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
new file mode 100644
index 0000000..0ae3b25
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
@@ -0,0 +1,94 @@
+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.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.blur.MiniCluster;
+import org.apache.blur.thrift.BlurClient;
+import org.apache.blur.thrift.generated.Blur;
+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.RecordMutation;
+import org.apache.blur.thrift.generated.RowMutation;
+import org.apache.blur.thrift.generated.SimpleQuery;
+import org.apache.blur.thrift.generated.TableDescriptor;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.utils.BlurUtil;
+import org.apache.thrift.TException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class BlurClusterTest {
+
+  @BeforeClass
+  public static void startCluster() {
+    MiniCluster.startBlurCluster("./tmp/cluster", 2, 3);
+  }
+
+  @AfterClass
+  public static void shutdownCluster() {
+    MiniCluster.shutdownBlurCluster();
+  }
+
+  @Test
+  public void testCreateTable() throws BlurException, TException, IOException {
+    Blur.Iface client = getClient();
+    TableDescriptor tableDescriptor = new TableDescriptor();
+    tableDescriptor.setName("test");
+    tableDescriptor.setShardCount(5);
+    tableDescriptor.setTableUri(MiniCluster.getFileSystemUri().toString() + "/blur/test");
+    client.createTable(tableDescriptor);
+    List<String> tableList = client.tableList();
+    assertEquals(Arrays.asList("test"), tableList);
+  }
+
+  private Iface getClient() {
+    return BlurClient.getClient(MiniCluster.getControllerConnectionStr());
+  }
+
+  @Test
+  public void testLoadTable() throws BlurException, TException, InterruptedException {
+    Iface client = getClient();
+    int length = 100;
+    List<RowMutation> mutations = new ArrayList<RowMutation>();
+    for (int i = 0; i < length; i++) {
+      String rowId = UUID.randomUUID().toString();
+      RecordMutation mutation = BlurUtil.newRecordMutation("test", rowId, BlurUtil.newColumn("test", "value"));
+      RowMutation rowMutation = BlurUtil.newRowMutation("test", rowId, mutation);
+      rowMutation.setWaitToBeVisible(true);
+      mutations.add(rowMutation);
+    }
+    client.mutateBatch(mutations);
+    BlurQuery blurQuery = new BlurQuery();
+    SimpleQuery simpleQuery = new SimpleQuery();
+    simpleQuery.setQueryStr("test.test:value");
+    blurQuery.setSimpleQuery(simpleQuery);
+    BlurResults results = client.query("test", blurQuery);
+    assertEquals(length, results.getTotalResults());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/thrift/BlurControllerServerTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/thrift/BlurControllerServerTest.java b/src/blur-core/src/test/java/org/apache/blur/thrift/BlurControllerServerTest.java
new file mode 100644
index 0000000..c6f69f6
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/thrift/BlurControllerServerTest.java
@@ -0,0 +1,334 @@
+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 org.junit.Test;
+
+public class BlurControllerServerTest {
+
+  @Test
+  public void testNothing() {
+    // do nothing
+  }
+
+  // private static final String TABLE = "test";
+  // private static Map<String, Iface> shardServers = new HashMap<String,
+  // Iface>();
+  // private static BlurControllerServer server;
+  // private static Thread daemonService;
+  //
+  // @BeforeClass
+  // public static void zkServerStartup() throws InterruptedException,
+  // KeeperException, IOException, BlurException, TException {
+  // rm(new File("../zk-tmp"));
+  // daemonService = new Thread(new Runnable() {
+  // @Override
+  // public void run() {
+  // QuorumPeerMain.main(new
+  // String[]{"./src/test/resources/com/nearinfinity/blur/thrift/zoo.cfg"});
+  // }
+  // });
+  // daemonService.start();
+  // Thread.sleep(1000);
+  //
+  // ZooKeeper zookeeper = new ZooKeeper("127.0.0.1:10101", 30000, new Watcher()
+  // {
+  // @Override
+  // public void process(WatchedEvent event) {
+  //
+  // }
+  // });
+  //
+  // addShardServer("shard-00000000");
+  // addShardServer("shard-00000001");
+  // addShardServer("shard-00000002");
+  // BlurQueryChecker queryChecker = new BlurQueryChecker(new
+  // BlurConfiguration());
+  // server = new BlurControllerServer();
+  // server.setClient(getClient());
+  // server.setClusterStatus(new ZookeeperClusterStatus(zookeeper));
+  // server.setQueryChecker(queryChecker);
+  // server.setZookeeper(zookeeper);
+  // server.init();
+  //
+  // File file = new File("./tmp-data/test");
+  // rm(file);
+  //
+  // TableDescriptor tableDescriptor = new TableDescriptor();
+  // tableDescriptor.name = "test";
+  // tableDescriptor.shardCount = 3;
+  // tableDescriptor.tableUri = file.toURI().toString();
+  // tableDescriptor.analyzerDefinition = new AnalyzerDefinition();
+  // server.createTable(tableDescriptor);
+  // }
+  //
+  // @AfterClass
+  // public static void zkServerShutdown() {
+  // daemonService.interrupt();
+  // server.close();
+  // }
+  //
+  // private static void rm(File file) {
+  // if (file.isDirectory()) {
+  // for (File f : file.listFiles()) {
+  // rm(f);
+  // }
+  // }
+  // file.delete();
+  // }
+  //
+  // @Test
+  // public void testQuery() throws BlurException, TException {
+  // BlurQuery blurQuery = new BlurQuery();
+  // blurQuery.maxQueryTime = TimeUnit.SECONDS.toMillis(5);
+  // blurQuery.minimumNumberOfResults = Long.MAX_VALUE;
+  // BlurResults results = server.query(TABLE, blurQuery);
+  // assertNotNull(results);
+  // }
+  //
+  // @Test
+  // public void testQueryWithFacets() throws BlurException, TException {
+  // BlurQuery blurQuery = new BlurQuery();
+  // blurQuery.maxQueryTime = TimeUnit.SECONDS.toMillis(5);
+  // blurQuery.minimumNumberOfResults = Long.MAX_VALUE;
+  // blurQuery.facets = new ArrayList<Facet>();
+  // blurQuery.facets.add(new Facet());
+  // blurQuery.facets.add(new Facet());
+  // BlurResults results = server.query(TABLE, blurQuery);
+  // assertNotNull(results);
+  // assertNotNull(results.facetCounts);
+  // for (int i = 0; i < results.facetCounts.size(); i++) {
+  // long count = results.facetCounts.get(i);
+  // assertEquals(shardServers.size() * (i + 1), count);
+  // }
+  // }
+  //
+  // @Test
+  // public void testRecordFrequency() throws BlurException, TException {
+  // long recordFrequency = server.recordFrequency(TABLE, "cf", "cn", "value");
+  // assertEquals(shardServers.size(), recordFrequency);
+  // }
+  //
+  // @Test
+  // public void testMutate() throws BlurException, TException {
+  // RowMutation mutation = new RowMutation();
+  // mutation.setRowId("1234");
+  // RecordMutation recMut = new RecordMutation();
+  // Record record = new Record();
+  // record.setFamily("test");
+  // record.setRecordId("5678");
+  // record.addToColumns(new Column("name", "value"));
+  // mutation.addToRecordMutations(recMut);
+  // mutation.table = TABLE;
+  // server.mutate(mutation);
+  //
+  // Selector selector = new Selector();
+  // selector.rowId = "1234";
+  //
+  // FetchResult fetchRow = server.fetchRow(TABLE, selector);
+  // assertNotNull(fetchRow.rowResult);
+  // }
+  //
+  // private static BlurClient getClient() {
+  // BlurClientEmbedded blurClientEmbedded = new BlurClientEmbedded();
+  // for (String node : shardServers.keySet()) {
+  // blurClientEmbedded.putNode(node, shardServers.get(node));
+  // }
+  // return blurClientEmbedded;
+  // }
+  //
+  // private static Iface getShardServer(final String node) {
+  // return new Iface() {
+  //
+  // private Map<String, Map<String, Row>> rows = new HashMap<String,
+  // Map<String, Row>>();
+  //
+  // @Override
+  // public List<String> terms(String arg0, String arg1, String arg2, String
+  // arg3, short arg4) throws BlurException, TException {
+  // throw new RuntimeException("no impl");
+  // }
+  //
+  // @Override
+  // public List<String> tableList() throws BlurException, TException {
+  // List<String> table = new ArrayList<String>();
+  // table.add(TABLE);
+  // return table;
+  // }
+  //
+  // @Override
+  // public List<String> shardServerList(String cluster) throws BlurException,
+  // TException {
+  // throw new RuntimeException("no impl");
+  // }
+  //
+  // @Override
+  // public Map<String, String> shardServerLayout(String table) throws
+  // BlurException, TException {
+  // Map<String, String> layout = new HashMap<String, String>();
+  // layout.put(node, node);
+  // return layout;
+  // }
+  //
+  // @Override
+  // public BlurResults query(String table, BlurQuery query) throws
+  // BlurException, TException {
+  // BlurResults results = new BlurResults();
+  // results.putToShardInfo(node, 0);
+  // results.setFacetCounts(getFacetCounts(query));
+  // return results;
+  // }
+  //
+  // private List<Long> getFacetCounts(BlurQuery query) {
+  // if (query.facets != null) {
+  // int size = query.facets.size();
+  // List<Long> results = new ArrayList<Long>();
+  // for (int i = 0; i < size; i++) {
+  // results.add(i + 1L);
+  // }
+  // return results;
+  // }
+  // return null;
+  // }
+  //
+  // @Override
+  // public Schema schema(String arg0) throws BlurException, TException {
+  // throw new RuntimeException("no impl");
+  // }
+  //
+  // @Override
+  // public long recordFrequency(String arg0, String arg1, String arg2, String
+  // arg3) throws BlurException, TException {
+  // return 1l;
+  // }
+  //
+  // @Override
+  // public FetchResult fetchRow(String table, Selector selector) throws
+  // BlurException, TException {
+  // Map<String, Row> map = rows.get(table);
+  // Row row = map.get(selector.rowId);
+  // FetchResult fetchResult = new FetchResult();
+  // fetchResult.setRowResult(new FetchRowResult(row));
+  // return fetchResult;
+  // }
+  //
+  // @Override
+  // public TableDescriptor describe(String arg0) throws BlurException,
+  // TException {
+  // TableDescriptor descriptor = new TableDescriptor();
+  // descriptor.isEnabled = true;
+  // descriptor.shardCount = 3;
+  // return descriptor;
+  // }
+  //
+  // @Override
+  // public List<BlurQueryStatus> currentQueries(String arg0) throws
+  // BlurException, TException {
+  // throw new RuntimeException("no impl");
+  // }
+  //
+  // @Override
+  // public List<String> controllerServerList() throws BlurException, TException
+  // {
+  // throw new RuntimeException("no impl");
+  // }
+  //
+  // @Override
+  // public void cancelQuery(String table, long arg0) throws BlurException,
+  // TException {
+  // throw new RuntimeException("no impl");
+  // }
+  //
+  // private Row toRow(RowMutation mutation) {
+  // Row row = new Row();
+  // row.id = mutation.rowId;
+  // row.records = toRecords(mutation.recordMutations);
+  // return row;
+  // }
+  //
+  // private List<Record> toRecords(List<RecordMutation> recordMutations) {
+  // List<Record> records = new ArrayList<Record>();
+  // for (RecordMutation mutation : recordMutations) {
+  // records.add(mutation.record);
+  // }
+  // return records;
+  // }
+  //
+  // @Override
+  // public void createTable(TableDescriptor tableDescriptor) throws
+  // BlurException, TException {
+  // throw new RuntimeException("not impl");
+  // }
+  //
+  // @Override
+  // public void disableTable(String table) throws BlurException, TException {
+  // throw new RuntimeException("not impl");
+  // }
+  //
+  // @Override
+  // public void enableTable(String table) throws BlurException, TException {
+  // throw new RuntimeException("not impl");
+  // }
+  //
+  // @Override
+  // public void removeTable(String table, boolean deleteIndexFiles) throws
+  // BlurException, TException {
+  // throw new RuntimeException("not impl");
+  // }
+  //
+  // @Override
+  // public TableStats getTableStats(String table) throws BlurException,
+  // TException {
+  // return new TableStats();
+  // }
+  //
+  // @Override
+  // public void mutate(RowMutation mutation) throws BlurException, TException {
+  // String table = mutation.table;
+  // Map<String, Row> map = rows.get(table);
+  // if (map == null) {
+  // map = new HashMap<String, Row>();
+  // rows.put(table, map);
+  // }
+  // Row row = toRow(mutation);
+  // map.put(row.id, row);
+  // }
+  //
+  // @Override
+  // public void mutateBatch(List<RowMutation> mutations) throws BlurException,
+  // TException {
+  // for (RowMutation mutation : mutations) {
+  // MutationHelper.validateMutation(mutation);
+  // }
+  // for (RowMutation mutation : mutations) {
+  // mutate(mutation);
+  // }
+  // }
+  //
+  // @Override
+  // public List<String> shardClusterList() throws BlurException, TException {
+  // throw new RuntimeException("no impl");
+  // }
+  // };
+  // }
+  //
+  // private static void addShardServer(String node) {
+  // shardServers.put(node, getShardServer(node));
+  // }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/thrift/BlurShardServerTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/thrift/BlurShardServerTest.java b/src/blur-core/src/test/java/org/apache/blur/thrift/BlurShardServerTest.java
new file mode 100644
index 0000000..d688d19
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/thrift/BlurShardServerTest.java
@@ -0,0 +1,148 @@
+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 java.util.Map;
+import java.util.SortedSet;
+
+import org.apache.blur.analysis.BlurAnalyzer;
+import org.apache.blur.manager.IndexManager;
+import org.apache.blur.manager.IndexServer;
+import org.apache.blur.manager.writer.BlurIndex;
+import org.apache.hadoop.io.compress.CompressionCodec;
+import org.apache.lucene.search.Similarity;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BlurShardServerTest {
+
+  private BlurShardServer blurShardServer;
+
+  @Before
+  public void setUp() {
+    IndexServer indexServer = getIndexServer();
+    IndexManager indexManager = getIndexManager();
+    indexManager.setIndexServer(indexServer);
+    indexManager.setThreadCount(1);
+    indexManager.init();
+    blurShardServer = new BlurShardServer();
+    blurShardServer.setIndexManager(indexManager);
+    blurShardServer.setIndexServer(indexServer);
+    blurShardServer.init();
+  }
+
+  @After
+  public void tearDown() throws InterruptedException {
+    blurShardServer.close();
+  }
+
+  @Test
+  public void testNothingYet() {
+
+  }
+
+  private IndexServer getIndexServer() {
+    return new IndexServer() {
+
+      @Override
+      public void close() {
+
+      }
+
+      @Override
+      public BlurAnalyzer getAnalyzer(String table) {
+        throw new RuntimeException("not impl");
+      }
+
+      @Override
+      public Map<String, BlurIndex> getIndexes(String table) throws IOException {
+        throw new RuntimeException("not impl");
+      }
+
+      @Override
+      public List<String> getShardList(String table) {
+        throw new RuntimeException("not impl");
+      }
+
+      @Override
+      public Similarity getSimilarity(String table) {
+        throw new RuntimeException("not impl");
+      }
+
+      @Override
+      public TABLE_STATUS getTableStatus(String table) {
+        throw new RuntimeException("not impl");
+      }
+
+      @Override
+      public String getNodeName() {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public String getTableUri(String table) {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public int getShardCount(String table) {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public int getCompressionBlockSize(String table) {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public CompressionCodec getCompressionCodec(String table) {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public long getRecordCount(String table) throws IOException {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public long getRowCount(String table) throws IOException {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public long getTableSize(String table) throws IOException {
+        throw new RuntimeException("no impl");
+      }
+
+      @Override
+      public SortedSet<String> getShardListCurrentServerOnly(String table) throws IOException {
+        throw new RuntimeException("no impl");
+      }
+    };
+  }
+
+  private IndexManager getIndexManager() {
+    return new IndexManager() {
+
+    };
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/thrift/DoNothingServer.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/thrift/DoNothingServer.java b/src/blur-core/src/test/java/org/apache/blur/thrift/DoNothingServer.java
new file mode 100644
index 0000000..56e3156
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/thrift/DoNothingServer.java
@@ -0,0 +1,174 @@
+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.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.BlurQuery;
+import org.apache.blur.thrift.generated.BlurQueryStatus;
+import org.apache.blur.thrift.generated.BlurResults;
+import org.apache.blur.thrift.generated.FetchResult;
+import org.apache.blur.thrift.generated.RowMutation;
+import org.apache.blur.thrift.generated.Schema;
+import org.apache.blur.thrift.generated.Selector;
+import org.apache.blur.thrift.generated.TableDescriptor;
+import org.apache.blur.thrift.generated.TableStats;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.thrift.TException;
+
+
+public class DoNothingServer implements Iface {
+
+  @Override
+  public TableDescriptor describe(String table) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public List<String> tableList() throws BlurException, TException {
+    return Arrays.asList("donothing");
+  }
+
+  @Override
+  public List<String> controllerServerList() throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public List<String> shardServerList(String cluster) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public Map<String, String> shardServerLayout(String table) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public BlurResults query(String table, BlurQuery blurQuery) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public void cancelQuery(String table, long providedUuid) throws BlurException, TException {
+
+  }
+
+  @Override
+  public FetchResult fetchRow(String table, Selector selector) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public List<BlurQueryStatus> currentQueries(String arg0) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public long recordFrequency(String arg0, String arg1, String arg2, String arg3) throws BlurException, TException {
+    return 0;
+  }
+
+  @Override
+  public Schema schema(String arg0) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public List<String> terms(String arg0, String arg1, String arg2, String arg3, short arg4) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public void createTable(TableDescriptor tableDescriptor) throws BlurException, TException {
+
+  }
+
+  @Override
+  public void disableTable(String table) throws BlurException, TException {
+
+  }
+
+  @Override
+  public void enableTable(String table) throws BlurException, TException {
+
+  }
+
+  @Override
+  public void removeTable(String table, boolean deleteIndexFiles) throws BlurException, TException {
+
+  }
+
+  @Override
+  public TableStats getTableStats(String table) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public void mutate(RowMutation mutation) throws BlurException, TException {
+
+  }
+
+  @Override
+  public void mutateBatch(List<RowMutation> mutations) throws BlurException, TException {
+
+  }
+
+  @Override
+  public List<String> shardClusterList() throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public List<String> tableListByCluster(String cluster) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public BlurQueryStatus queryStatusById(String table, long uuid) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public List<Long> queryStatusIdList(String table) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public void optimize(String table, int numberOfSegmentsPerShard) throws BlurException, TException {
+
+  }
+
+  @Override
+  public boolean isInSafeMode(String cluster) throws BlurException, TException {
+    return false;
+  }
+
+  @Override
+  public TableStats tableStats(String table) throws BlurException, TException {
+    return null;
+  }
+
+  @Override
+  public Map<String, String> configuration() throws BlurException, TException {
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java b/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
new file mode 100644
index 0000000..36a8dde
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
@@ -0,0 +1,146 @@
+package org.apache.blur.utils;
+
+/**
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.blur.lucene.LuceneConstant;
+import org.apache.blur.thrift.generated.Record;
+import org.apache.blur.thrift.generated.RecordMutation;
+import org.apache.blur.thrift.generated.RowMutation;
+import org.apache.blur.utils.BlurUtil;
+import org.apache.lucene.analysis.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+
+public class BlurUtilsTest {
+
+  @Test
+  public void testHumanizeTime1() {
+    long time = TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(42) + TimeUnit.SECONDS.toMillis(37) + TimeUnit.MILLISECONDS.toMillis(124);
+    String humanizeTime = BlurUtil.humanizeTime(time, TimeUnit.MILLISECONDS);
+    assertEquals("2 hours 42 minutes 37 seconds", humanizeTime);
+  }
+
+  @Test
+  public void testHumanizeTime2() {
+    long time = TimeUnit.HOURS.toMillis(0) + TimeUnit.MINUTES.toMillis(42) + TimeUnit.SECONDS.toMillis(37) + TimeUnit.MILLISECONDS.toMillis(124);
+    String humanizeTime = BlurUtil.humanizeTime(time, TimeUnit.MILLISECONDS);
+    assertEquals("42 minutes 37 seconds", humanizeTime);
+  }
+
+  @Test
+  public void testHumanizeTime3() {
+    long time = TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(0) + TimeUnit.SECONDS.toMillis(37) + TimeUnit.MILLISECONDS.toMillis(124);
+    String humanizeTime = BlurUtil.humanizeTime(time, TimeUnit.MILLISECONDS);
+    assertEquals("2 hours 0 minutes 37 seconds", humanizeTime);
+  }
+
+  @Test
+  public void testHumanizeTime4() {
+    long time = TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(0) + TimeUnit.SECONDS.toMillis(0) + TimeUnit.MILLISECONDS.toMillis(124);
+    String humanizeTime = BlurUtil.humanizeTime(time, TimeUnit.MILLISECONDS);
+    assertEquals("2 hours 0 minutes 0 seconds", humanizeTime);
+  }
+
+  @Test
+  public void testHumanizeTime5() {
+    long time = TimeUnit.HOURS.toMillis(0) + TimeUnit.MINUTES.toMillis(0) + TimeUnit.SECONDS.toMillis(37) + TimeUnit.MILLISECONDS.toMillis(124);
+    String humanizeTime = BlurUtil.humanizeTime(time, TimeUnit.MILLISECONDS);
+    assertEquals("37 seconds", humanizeTime);
+  }
+
+  @Test
+  public void testHumanizeTime6() {
+    long time = TimeUnit.HOURS.toMillis(0) + TimeUnit.MINUTES.toMillis(0) + TimeUnit.SECONDS.toMillis(0) + TimeUnit.MILLISECONDS.toMillis(124);
+    String humanizeTime = BlurUtil.humanizeTime(time, TimeUnit.MILLISECONDS);
+    assertEquals("0 seconds", humanizeTime);
+  }
+
+  @Test
+  public void testMemoryUsage() throws CorruptIndexException, LockObtainFailedException, IOException {
+    IndexReader reader = getReader();
+    long memoryUsage = BlurUtil.getMemoryUsage(reader);
+    assertTrue(memoryUsage > 0);
+  }
+
+  @Test
+  public void testRecordMatch() {
+    Record r1 = BlurUtil.newRecord("test-family", "record-1", BlurUtil.newColumn("a", "b"));
+    Record r2 = BlurUtil.newRecord("test-family", "record-1", BlurUtil.newColumn("c", "d"));
+    Record r3 = BlurUtil.newRecord("test-family", "record-2", BlurUtil.newColumn("e", "f"));
+    Record r4 = BlurUtil.newRecord("test-family-2", "record-1", BlurUtil.newColumn("g", "h"));
+
+    assertTrue("should match with same family and record-id", BlurUtil.match(r1, r2));
+    assertFalse("should not match with different record-id", BlurUtil.match(r1, r3));
+    assertFalse("should not match with different family", BlurUtil.match(r1, r4));
+  }
+
+  @Test
+  public void testRecordMutationMatch() {
+    RecordMutation rm1 = BlurUtil.newRecordMutation("test-family", "record-1", BlurUtil.newColumn("a", "b"));
+    RecordMutation rm2 = BlurUtil.newRecordMutation("test-family", "record-2", BlurUtil.newColumn("c", "d"));
+    RecordMutation rm3 = BlurUtil.newRecordMutation("test-family-2", "record-1", BlurUtil.newColumn("e", "f"));
+    Record r = BlurUtil.newRecord("test-family", "record-1", BlurUtil.newColumn("g", "h"));
+
+    assertTrue("should match with same family and record-id", BlurUtil.match(rm1, r));
+    assertFalse("should not match with different record-id", BlurUtil.match(rm2, r));
+    assertFalse("should not match with different family", BlurUtil.match(rm3, r));
+  }
+
+  @Test
+  public void testFindRecordMutation() {
+    RecordMutation rm1 = BlurUtil.newRecordMutation("test-family", "record-1", BlurUtil.newColumn("a", "b"));
+    RecordMutation rm2 = BlurUtil.newRecordMutation("test-family", "record-2", BlurUtil.newColumn("c", "d"));
+    RecordMutation rm3 = BlurUtil.newRecordMutation("test-family-2", "record-1", BlurUtil.newColumn("e", "f"));
+    RowMutation row = BlurUtil.newRowMutation("test-table", "row-123", rm1, rm2, rm3);
+    Record r = BlurUtil.newRecord("test-family", "record-2", BlurUtil.newColumn("g", "h"));
+    Record r2 = BlurUtil.newRecord("test-family", "record-99", BlurUtil.newColumn("g", "h"));
+
+    assertEquals("should find record-2", rm2, BlurUtil.findRecordMutation(row, r));
+    assertNull("should not find record-99", BlurUtil.findRecordMutation(row, r2));
+  }
+
+  private IndexReader getReader() throws CorruptIndexException, LockObtainFailedException, IOException {
+    RAMDirectory directory = new RAMDirectory();
+    IndexWriterConfig conf = new IndexWriterConfig(LuceneConstant.LUCENE_VERSION, new KeywordAnalyzer());
+    IndexWriter writer = new IndexWriter(directory, conf);
+    Document doc = new Document();
+    doc.add(new Field("a", "b", Store.YES, Index.NOT_ANALYZED_NO_NORMS));
+    writer.addDocument(doc);
+    writer.close();
+    return IndexReader.open(directory);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java b/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
new file mode 100644
index 0000000..610fccc
--- /dev/null
+++ b/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
@@ -0,0 +1,117 @@
+package org.apache.blur.utils;
+
+/**
+ * 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.apache.blur.lucene.LuceneConstant.LUCENE_VERSION;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.blur.utils.TermDocIterable;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldSelector;
+import org.apache.lucene.document.FieldSelectorResult;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
+import org.apache.lucene.store.FSDirectory;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TermDocIterableTest {
+
+  private static final int BLOCKS = 10;
+  private static final int COUNT_PER_BLOCK = 100;
+  private IndexReader reader;
+
+  @Before
+  public void setup() throws IOException {
+    reader = createIndexReader();
+  }
+
+  @SuppressWarnings("serial")
+  @Test
+  public void testTermDocIterable() throws IOException {
+    for (int pass = 0; pass < 1; pass++) {
+      for (int id = 0; id < BLOCKS; id++) {
+        TermDocs termDocs = reader.termDocs(new Term("id", Integer.toString(id)));
+        TermDocIterable iterable = new TermDocIterable(termDocs, reader, new FieldSelector() {
+          @Override
+          public FieldSelectorResult accept(String fieldName) {
+            return FieldSelectorResult.LOAD;
+          }
+        });
+        int count = 0;
+        int i = 0;
+        long s = System.nanoTime();
+        for (Document document : iterable) {
+          count++;
+          assertEquals(i, Integer.parseInt(document.get("field")));
+          i++;
+        }
+        long time = System.nanoTime() - s;
+        System.out.println(time / 1000000.0 + " " + id + " " + pass);
+        assertEquals(COUNT_PER_BLOCK, count);
+      }
+    }
+  }
+
+  private IndexReader createIndexReader() throws IOException {
+    FSDirectory directory = FSDirectory.open(new File("./tmp/termdociterable"));
+    if (!IndexReader.indexExists(directory)) {
+      rm(new File("./tmp/termdociterable"));
+      IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
+      for (int i = 0; i < BLOCKS; i++) {
+        addDocumentBlock(i, COUNT_PER_BLOCK, writer);
+      }
+      writer.close();
+    }
+    return IndexReader.open(directory);
+  }
+
+  private File rm(File file) {
+    if (file.isDirectory()) {
+      for (File f : file.listFiles()) {
+        rm(f);
+      }
+    }
+    file.delete();
+    return file;
+  }
+
+  private void addDocumentBlock(int id, int count, IndexWriter writer) throws IOException {
+    for (int i = 0; i < count; i++) {
+      Document document = new Document();
+      document.add(new Field("id", Integer.toString(id), Store.YES, Index.NOT_ANALYZED_NO_NORMS));
+      document.add(new Field("field", Integer.toString(i), Store.YES, Index.NOT_ANALYZED_NO_NORMS));
+      for (int j = 0; j < 100; j++) {
+        document.add(new Field("field" + j, "testing here testing here testing here testing here testing here testing here testing here", Store.YES, Index.NO));
+      }
+      writer.addDocument(document);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-demo/pom.xml
----------------------------------------------------------------------
diff --git a/src/blur-demo/pom.xml b/src/blur-demo/pom.xml
index 5edb28f..6cb2a40 100644
--- a/src/blur-demo/pom.xml
+++ b/src/blur-demo/pom.xml
@@ -20,19 +20,19 @@ 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/xsd/maven-4.0.0.xsd">
 	<parent>
-		<groupId>com.nearinfinity.blur</groupId>
+		<groupId>org.apache.blur</groupId>
 		<artifactId>blur</artifactId>
 		<version>0.1.3</version>
 	</parent>
 	<modelVersion>4.0.0</modelVersion>
-	<groupId>com.nearinfinity.blur</groupId>
+	<groupId>org.apache.blur</groupId>
 	<artifactId>blur-demo</artifactId>
 	<packaging>jar</packaging>
 	<name>Blur Demo</name>
 
 	<dependencies>
 		<dependency>
-			<groupId>com.nearinfinity.blur</groupId>
+			<groupId>org.apache.blur</groupId>
 			<artifactId>blur-core</artifactId>
 			<version>0.1.3</version>
 		</dependency>
@@ -102,19 +102,6 @@ under the License.
 					</execution>
 				</executions>
 			</plugin>
-		        <plugin>
-		            <artifactId>maven-assembly-plugin</artifactId>
-		            <configuration>
-		                <archive>
-		                    <manifest>
-		                        <mainClass>com.nearinfinity.blur.demo.DemoServer</mainClass>
-		                    </manifest>
-		                </archive>
-		                <descriptorRefs>
-		                    <descriptorRef>jar-with-dependencies</descriptorRef>
-		                </descriptorRefs>
-		            </configuration>
-		        </plugin>
 		    </plugins>
 	
 		

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
----------------------------------------------------------------------
diff --git a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java b/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
deleted file mode 100644
index 2af4c1d..0000000
--- a/src/blur-demo/src/main/java/com/nearinfinity/blur/demo/SampleProgram.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.nearinfinity.blur.demo;
-
-/**
- * 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 com.nearinfinity.blur.utils.BlurUtil.newColumn;
-import static com.nearinfinity.blur.utils.BlurUtil.newRecordMutation;
-import static com.nearinfinity.blur.utils.BlurUtil.newRowMutation;
-
-import java.util.List;
-import java.util.Random;
-
-import org.apache.thrift.TException;
-
-import com.nearinfinity.blur.thrift.BlurClient;
-import com.nearinfinity.blur.thrift.generated.AnalyzerDefinition;
-import com.nearinfinity.blur.thrift.generated.Blur;
-import com.nearinfinity.blur.thrift.generated.Blur.Iface;
-import com.nearinfinity.blur.thrift.generated.BlurException;
-import com.nearinfinity.blur.thrift.generated.FetchResult;
-import com.nearinfinity.blur.thrift.generated.FetchRowResult;
-import com.nearinfinity.blur.thrift.generated.Row;
-import com.nearinfinity.blur.thrift.generated.RowMutation;
-import com.nearinfinity.blur.thrift.generated.Selector;
-import com.nearinfinity.blur.thrift.generated.TableDescriptor;
-
-public class SampleProgram {
-
-  private static final String BLUR_CLUSTER_NAME = "default";
-  public static final String BLUR_CONTROLLER_HOSTNAME = "localhost";
-  public static final String BLUR_CONTROLLER_PORT = "40010";
-
-  public static final String HDFS_NAMENODE_HOSTNAME = "localhost";
-  public static final String HDFS_NAMENODE_PORT = "9000";
-
-  // Path must include trailing slash character
-  public static final String BLUR_TABLES_LOCATION = "/blur/tables/";
-  private static final int MAX_SAMPLE_ROWS = 1000;
-  private static final int MAX_SEARCHES = 500;
-
-  public static void main(String[] args) {
-    try {
-      // Connect
-      Blur.Iface client = connect();
-
-      // Delete all tables
-      deleteAllTables(client);
-
-      // Create a table
-      String tableName = "SAMPLE_TABLE_" + System.currentTimeMillis();
-      createTable(client, tableName);
-
-      // List all the tables
-      listTables(client);
-
-      // Populate the table with data
-      populateTable(client, tableName);
-
-      // Run searches
-      searchTable(client, tableName);
-
-      // Delete the table
-      deleteTable(client, tableName);
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-
-  }
-
-  private static void deleteAllTables(Iface client) throws BlurException, TException {
-    List<String> tableList = listTables(client);
-    for (String tableName : tableList) {
-      deleteTable(client, tableName);
-    }
-  }
-
-  private static Blur.Iface connect() {
-    String blurConnectionString = BLUR_CONTROLLER_HOSTNAME + ":" + BLUR_CONTROLLER_PORT;
-    System.out.println("Connecting to " + blurConnectionString);
-    Blur.Iface client = BlurClient.getClient(blurConnectionString);
-    System.out.println("Successfully connected to " + blurConnectionString);
-    return client;
-  }
-
-  private static void createTable(Iface client, String tableName) {
-    try {
-      AnalyzerDefinition ad = new AnalyzerDefinition();
-
-      TableDescriptor tableDescriptor = new TableDescriptor();
-      tableDescriptor.setTableUri("hdfs://" + HDFS_NAMENODE_HOSTNAME + ":" + HDFS_NAMENODE_PORT + BLUR_TABLES_LOCATION + tableName);
-      tableDescriptor.setAnalyzerDefinition(ad);
-      tableDescriptor.setName(tableName);
-      tableDescriptor.setCluster(BLUR_CLUSTER_NAME);
-
-      System.out.println("About to create table " + tableName);
-      client.createTable(tableDescriptor);
-      System.out.println("Created table " + tableName);
-    } catch (BlurException e) {
-      e.printStackTrace();
-    } catch (TException e) {
-      e.printStackTrace();
-    }
-  }
-
-  private static List<String> listTables(Blur.Iface client) {
-    try {
-      System.out.println("Listing all tables");
-      List<String> tableNames = client.tableList();
-      for (String tableName : tableNames) {
-        System.out.println("tableName=" + tableName);
-      }
-      return tableNames;
-    } catch (BlurException e) {
-      e.printStackTrace();
-    } catch (TException e) {
-      e.printStackTrace();
-    }
-    return null;
-  }
-
-  private static void populateTable(Iface client, String tableName) throws BlurException, TException {
-    Random random = new Random();
-    for (int count = 1; count <= MAX_SAMPLE_ROWS; count++) {
-      RowMutation mutation = newRowMutation(tableName, "rowid_" + count, newRecordMutation("sample", "recordid_1", newColumn("sampleData", "data_" + random.nextInt(50000))));
-      System.out.println("About to add rowid_" + count);
-      client.mutate(mutation);
-      System.out.println("Added rowid_" + count);
-    }
-
-  }
-
-  private static void searchTable(Iface client, String tableName) throws BlurException, TException {
-    Random random = new Random();
-    for (int count = 1; count <= MAX_SEARCHES; count++) {
-      String rowid = "rowid_" + random.nextInt(MAX_SAMPLE_ROWS);
-      Selector selector = new Selector();
-      selector.setRowId(rowid);
-      FetchResult fetchRow = client.fetchRow(tableName, selector);
-      if (fetchRow != null) {
-        FetchRowResult rowResult = fetchRow.getRowResult();
-        if (rowResult != null) {
-          Row row = rowResult.getRow();
-          if (row != null) {
-            System.out.println("Found " + rowid);
-          }
-
-        }
-      } else {
-        System.out.println("Could not find " + rowid);
-      }
-    }
-
-  }
-
-  private static void deleteTable(Iface client, String tableName) throws BlurException, TException {
-    client.disableTable(tableName);
-    client.removeTable(tableName, true);
-    System.out.println("Deleted table " + tableName);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-demo/src/main/java/org/apache/blur/demo/SampleProgram.java
----------------------------------------------------------------------
diff --git a/src/blur-demo/src/main/java/org/apache/blur/demo/SampleProgram.java b/src/blur-demo/src/main/java/org/apache/blur/demo/SampleProgram.java
new file mode 100644
index 0000000..b8c7a8f
--- /dev/null
+++ b/src/blur-demo/src/main/java/org/apache/blur/demo/SampleProgram.java
@@ -0,0 +1,174 @@
+package org.apache.blur.demo;
+
+/**
+ * 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.apache.blur.utils.BlurUtil.newColumn;
+import static org.apache.blur.utils.BlurUtil.newRecordMutation;
+import static org.apache.blur.utils.BlurUtil.newRowMutation;
+
+import java.util.List;
+import java.util.Random;
+
+import org.apache.blur.thrift.BlurClient;
+import org.apache.blur.thrift.generated.AnalyzerDefinition;
+import org.apache.blur.thrift.generated.Blur;
+import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.FetchResult;
+import org.apache.blur.thrift.generated.FetchRowResult;
+import org.apache.blur.thrift.generated.Row;
+import org.apache.blur.thrift.generated.RowMutation;
+import org.apache.blur.thrift.generated.Selector;
+import org.apache.blur.thrift.generated.TableDescriptor;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.thrift.TException;
+
+
+public class SampleProgram {
+
+  private static final String BLUR_CLUSTER_NAME = "default";
+  public static final String BLUR_CONTROLLER_HOSTNAME = "localhost";
+  public static final String BLUR_CONTROLLER_PORT = "40010";
+
+  public static final String HDFS_NAMENODE_HOSTNAME = "localhost";
+  public static final String HDFS_NAMENODE_PORT = "9000";
+
+  // Path must include trailing slash character
+  public static final String BLUR_TABLES_LOCATION = "/blur/tables/";
+  private static final int MAX_SAMPLE_ROWS = 1000;
+  private static final int MAX_SEARCHES = 500;
+
+  public static void main(String[] args) {
+    try {
+      // Connect
+      Blur.Iface client = connect();
+
+      // Delete all tables
+      deleteAllTables(client);
+
+      // Create a table
+      String tableName = "SAMPLE_TABLE_" + System.currentTimeMillis();
+      createTable(client, tableName);
+
+      // List all the tables
+      listTables(client);
+
+      // Populate the table with data
+      populateTable(client, tableName);
+
+      // Run searches
+      searchTable(client, tableName);
+
+      // Delete the table
+      deleteTable(client, tableName);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+  }
+
+  private static void deleteAllTables(Iface client) throws BlurException, TException {
+    List<String> tableList = listTables(client);
+    for (String tableName : tableList) {
+      deleteTable(client, tableName);
+    }
+  }
+
+  private static Blur.Iface connect() {
+    String blurConnectionString = BLUR_CONTROLLER_HOSTNAME + ":" + BLUR_CONTROLLER_PORT;
+    System.out.println("Connecting to " + blurConnectionString);
+    Blur.Iface client = BlurClient.getClient(blurConnectionString);
+    System.out.println("Successfully connected to " + blurConnectionString);
+    return client;
+  }
+
+  private static void createTable(Iface client, String tableName) {
+    try {
+      AnalyzerDefinition ad = new AnalyzerDefinition();
+
+      TableDescriptor tableDescriptor = new TableDescriptor();
+      tableDescriptor.setTableUri("hdfs://" + HDFS_NAMENODE_HOSTNAME + ":" + HDFS_NAMENODE_PORT + BLUR_TABLES_LOCATION + tableName);
+      tableDescriptor.setAnalyzerDefinition(ad);
+      tableDescriptor.setName(tableName);
+      tableDescriptor.setCluster(BLUR_CLUSTER_NAME);
+
+      System.out.println("About to create table " + tableName);
+      client.createTable(tableDescriptor);
+      System.out.println("Created table " + tableName);
+    } catch (BlurException e) {
+      e.printStackTrace();
+    } catch (TException e) {
+      e.printStackTrace();
+    }
+  }
+
+  private static List<String> listTables(Blur.Iface client) {
+    try {
+      System.out.println("Listing all tables");
+      List<String> tableNames = client.tableList();
+      for (String tableName : tableNames) {
+        System.out.println("tableName=" + tableName);
+      }
+      return tableNames;
+    } catch (BlurException e) {
+      e.printStackTrace();
+    } catch (TException e) {
+      e.printStackTrace();
+    }
+    return null;
+  }
+
+  private static void populateTable(Iface client, String tableName) throws BlurException, TException {
+    Random random = new Random();
+    for (int count = 1; count <= MAX_SAMPLE_ROWS; count++) {
+      RowMutation mutation = newRowMutation(tableName, "rowid_" + count, newRecordMutation("sample", "recordid_1", newColumn("sampleData", "data_" + random.nextInt(50000))));
+      System.out.println("About to add rowid_" + count);
+      client.mutate(mutation);
+      System.out.println("Added rowid_" + count);
+    }
+
+  }
+
+  private static void searchTable(Iface client, String tableName) throws BlurException, TException {
+    Random random = new Random();
+    for (int count = 1; count <= MAX_SEARCHES; count++) {
+      String rowid = "rowid_" + random.nextInt(MAX_SAMPLE_ROWS);
+      Selector selector = new Selector();
+      selector.setRowId(rowid);
+      FetchResult fetchRow = client.fetchRow(tableName, selector);
+      if (fetchRow != null) {
+        FetchRowResult rowResult = fetchRow.getRowResult();
+        if (rowResult != null) {
+          Row row = rowResult.getRow();
+          if (row != null) {
+            System.out.println("Found " + rowid);
+          }
+
+        }
+      } else {
+        System.out.println("Could not find " + rowid);
+      }
+    }
+
+  }
+
+  private static void deleteTable(Iface client, String tableName) throws BlurException, TException {
+    client.disableTable(tableName);
+    client.removeTable(tableName, true);
+    System.out.println("Deleted table " + tableName);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-gui/pom.xml
----------------------------------------------------------------------
diff --git a/src/blur-gui/pom.xml b/src/blur-gui/pom.xml
index 1b514ce..9529928 100644
--- a/src/blur-gui/pom.xml
+++ b/src/blur-gui/pom.xml
@@ -20,12 +20,12 @@ 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/xsd/maven-4.0.0.xsd">
 	<parent>
-		<groupId>com.nearinfinity.blur</groupId>
+		<groupId>org.apache.blur</groupId>
 		<artifactId>blur</artifactId>
 		<version>0.1.3</version>
 	</parent>
 	<modelVersion>4.0.0</modelVersion>
-	<groupId>com.nearinfinity.blur</groupId>
+	<groupId>org.apache.blur</groupId>
 	<artifactId>blur-gui</artifactId>
 	<packaging>war</packaging>
 	<name>Blur GUI</name>
@@ -36,17 +36,17 @@ under the License.
 
 	<dependencies>
 		<dependency>
-			<groupId>com.nearinfinity.blur</groupId>
+			<groupId>org.apache.blur</groupId>
 			<artifactId>blur-thrift</artifactId>
 			<version>0.1.3</version>
 		</dependency>
 		<dependency>
-			<groupId>com.nearinfinity.blur</groupId>
+			<groupId>org.apache.blur</groupId>
 			<artifactId>blur-store</artifactId>
 			<version>0.1.3</version>
 		</dependency>
 		<dependency>
-			<groupId>com.nearinfinity.blur</groupId>
+			<groupId>org.apache.blur</groupId>
 			<artifactId>blur-util</artifactId>
 			<version>0.1.3</version>
 		</dependency>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
deleted file mode 100644
index da71982..0000000
--- a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package com.nearinfinity.blur.gui;
-
-/**
- * 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 java.util.Properties;
-
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.mortbay.jetty.webapp.WebAppContext;
-
-import com.nearinfinity.blur.log.Log;
-import com.nearinfinity.blur.log.LogFactory;
-import com.nearinfinity.blur.metrics.BlurMetrics;
-
-/**
- * Starts up a Jetty server to run the utility gui.
- * 
- */
-public class HttpJettyServer {
-
-  private static final Log LOG = LogFactory.getLog(HttpJettyServer.class);
-
-  private Server server = null;
-
-  /**
-   * @param bindPort
-   *          port of the process that the gui is wrapping
-   * @param port
-   *          port to run gui on
-   * @param baseControllerPort
-   *          ports that service runs on
-   * @param baseShardPort
-   * @param baseGuiShardPort
-   *          port to run gui on
-   * @param baseGuiControllerPort
-   *          port to run gui on
-   * @param base
-   *          location of webapp to serve
-   * @param bm
-   *          metrics object for using.
-   * @throws IOException
-   */
-  public HttpJettyServer(int bindPort, int port, int baseControllerPort, int baseShardPort, int baseGuiControllerPort, int baseGuiShardPort, String base, BlurMetrics bm)
-      throws IOException {
-    server = new Server(port);
-
-    String logDir = System.getProperty("blur.logs.dir");
-    String logFile = System.getProperty("blur.log.file");
-    String blurLogFile = logDir + "/" + logFile;
-    System.setProperty("blur.gui.servicing.port", bindPort + "");
-    System.setProperty("blur.base.shard.port", baseShardPort + "");
-    System.setProperty("blur.base.controller.port", baseControllerPort + "");
-    System.setProperty("baseGuiShardPort", baseGuiShardPort + "");
-    System.setProperty("baseGuiControllerPort", baseGuiControllerPort + "");
-    System.setProperty("blur.gui.mode", base);
-    LOG.info("System props:" + System.getProperties().toString());
-
-    WebAppContext context = new WebAppContext();
-    String warPath = getWarFolder();
-    context.setWar(warPath);
-    context.setContextPath("/");
-    context.setParentLoaderPriority(true);
-    context.addServlet(new ServletHolder(new MetricsServlet(bm)), "/metrics");
-    context.addServlet(new ServletHolder(new LogServlet(blurLogFile)), "/logs");
-
-    LOG.info("WEB GUI coming up for resource: " + base);
-    LOG.info("WEB GUI thinks its at: " + warPath);
-    LOG.info("WEB GUI log file being exposed: " + logDir == null ? "STDOUT" : blurLogFile);
-
-    server.setHandler(context);
-
-    try {
-      server.start();
-    } catch (Exception e) {
-      throw new IOException("cannot start Http server for " + base, e);
-    }
-    LOG.info("WEB GUI up on port: " + port);
-  }
-
-  private static String findBlurGuiInClassPath() {
-    Properties properties = System.getProperties();
-    String cp = (String) properties.get("java.class.path");
-    String[] split = cp.split(":");
-    for (String s : split) {
-      if (s.endsWith(".war")) {
-        return s;
-      }
-    }
-    return null;
-  }
-
-  private String getWarFolder() {
-    String findBlurGuiInClassPath = findBlurGuiInClassPath();
-    if (findBlurGuiInClassPath != null) {
-      return findBlurGuiInClassPath;
-    }
-    String name = getClass().getName().replace('.', '/');
-    String classResource = "/" + name + ".class";
-    String pathToClassResource = getClass().getResource(classResource).toString();
-    pathToClassResource = pathToClassResource.replace('/', File.separatorChar);
-    int indexOfJar = pathToClassResource.indexOf(".jar");
-    if (indexOfJar < 0) {
-      int index = pathToClassResource.indexOf(name);
-      String pathToClasses = pathToClassResource.substring(0, index);
-      int indexOfProjectName = pathToClasses.indexOf("/blur-gui/");
-      return pathToClasses.substring(0, indexOfProjectName) + "/blur-gui/src/main/webapp";
-    }
-    return null;
-  }
-
-  public void close() {
-    if (server != null) {
-      try {
-        LOG.info("stopping web server");
-        server.stop();
-        LOG.info("stopped web server");
-      } catch (Exception e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java
deleted file mode 100644
index 83f0084..0000000
--- a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package com.nearinfinity.blur.gui;
-
-/**
- * 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 java.io.PrintWriter;
-import java.io.RandomAccessFile;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-public class LogServlet extends HttpServlet {
-
-  private static final long serialVersionUID = 1L;
-  private String filePath = null;
-  private int buffLen = 8192;
-
-  public LogServlet(String filePath) {
-    this.filePath = filePath;
-  }
-
-  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
-    response.setContentType("text/html");
-    PrintWriter out = response.getWriter();
-
-    File f = new File(filePath);
-    RandomAccessFile ram = new RandomAccessFile(f, "r");
-
-    String offsetStr = request.getParameter("offset");
-    long offset = -1;
-    if (offsetStr != null)
-      offset = Long.parseLong(offsetStr);
-
-    long start = 0;
-    long length = ram.length();
-    // figure out buffer
-    if (length < buffLen)
-      buffLen = new Long(length).intValue();
-
-    // use offset if passed in
-    if (offset >= 0)
-      start = offset;
-    else
-      start = length - buffLen;
-
-    // calc new offset
-    offset = start - buffLen;
-    if (offset < 0)
-      offset = 0;
-
-    // buffer
-    byte[] buff = new byte[buffLen];
-
-    ram.seek(start);
-    ram.read(buff);
-
-    String returnStr = new String(buff, "UTF-8").replaceAll("\n", "\n<br>");
-
-    out.write("<html><link href='style.css' rel='stylesheet' type='text/css' /><body>");
-    out.write("<a href='index.html'>home</a><br/>");
-    out.write("<p>File:<b> " + f.toString() + "</b> (" + start + "/" + length + ")</p>");
-    if (start != 0) {
-      out.write("<a href='logs?offset=" + 0 + "'>start</a>");
-      out.write(" <a href='logs?offset=" + offset + "'>prev</a>");
-    }
-    if (start + buffLen < length) {
-      out.write(" <a href='logs?offset=" + (start + buffLen) + "'>next</a>");
-      out.write(" <a href='logs?offset=" + ((length - buffLen > 0) ? (length - buffLen) : 0) + "'>end</a>");
-    }
-    out.write("<br/>");
-    out.write(returnStr);
-    out.write("</body></html>");
-
-    ram.close();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/33df9310/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java
deleted file mode 100644
index 7940aa3..0000000
--- a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.nearinfinity.blur.gui;
-
-/**
- * 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.io.PrintWriter;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.codehaus.jackson.map.ObjectMapper;
-
-import com.nearinfinity.blur.metrics.BlurMetrics;
-
-public class MetricsServlet extends HttpServlet {
-
-  private static final long serialVersionUID = 1L;
-
-  private BlurMetrics bm = null;
-
-  public MetricsServlet() {
-  }
-
-  public MetricsServlet(BlurMetrics bm) {
-    this.bm = bm;
-  }
-
-  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-    response.setContentType("application/json");
-    PrintWriter out = response.getWriter();
-    ObjectMapper mapper = new ObjectMapper();
-    mapper.writeValue(out, bm);
-  }
-
-}


Mime
View raw message