incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [14/47] git commit: Adding more tests.
Date Mon, 03 Sep 2012 00:32:19 GMT
Adding more tests.


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

Branch: refs/heads/master
Commit: eeb05f395df6f2de421497d918fc942f18dfed10
Parents: 4fd3327
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Aug 28 20:42:27 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Aug 28 20:42:27 2012 -0400

----------------------------------------------------------------------
 .../java/com/nearinfinity/blur/MiniCluster.java    |    1 -
 .../blur/analysis/LongAnalyzerTest.java            |   56 +++++++++++
 .../blur/manager/IndexManagerTest.java             |   78 ++++++++++++---
 3 files changed, 122 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eeb05f39/src/blur-core/src/test/java/com/nearinfinity/blur/MiniCluster.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/com/nearinfinity/blur/MiniCluster.java b/src/blur-core/src/test/java/com/nearinfinity/blur/MiniCluster.java
index de1a9c7..a15c6b1 100644
--- a/src/blur-core/src/test/java/com/nearinfinity/blur/MiniCluster.java
+++ b/src/blur-core/src/test/java/com/nearinfinity/blur/MiniCluster.java
@@ -418,7 +418,6 @@ public abstract class MiniCluster {
           }
         }
       }
-
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eeb05f39/src/blur-core/src/test/java/com/nearinfinity/blur/analysis/LongAnalyzerTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/com/nearinfinity/blur/analysis/LongAnalyzerTest.java
b/src/blur-core/src/test/java/com/nearinfinity/blur/analysis/LongAnalyzerTest.java
new file mode 100644
index 0000000..c4af678
--- /dev/null
+++ b/src/blur-core/src/test/java/com/nearinfinity/blur/analysis/LongAnalyzerTest.java
@@ -0,0 +1,56 @@
+package com.nearinfinity.blur.analysis;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Random;
+
+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.IndexWriterConfig;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.NumericRangeQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.Version;
+import org.junit.Test;
+
+import com.nearinfinity.blur.index.IndexWriter;
+
+public class LongAnalyzerTest {
+
+  @Test
+  public void testLongAnalyzer() throws IOException {
+    LongAnalyzer analyzer = new LongAnalyzer("long");
+    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_36, analyzer);
+    Directory dir = new RAMDirectory();
+    IndexWriter indexWriter = new IndexWriter(dir, conf);
+    Random random = new Random();
+    int max = 17;
+    for (int i = 0; i < 100; i++) {
+      int v = random.nextInt(max);
+      Document document = new Document();
+      document.add(new Field("f1", Long.toString(v), Store.YES, Index.ANALYZED_NO_NORMS));
+      FieldConverterUtil.convert(document, analyzer);
+      indexWriter.addDocument(document);
+    }
+    indexWriter.close();
+
+    IndexSearcher searcher = new IndexSearcher(IndexReader.open(dir));
+    NumericRangeQuery<Long> query = NumericRangeQuery.newLongRange("f1", 0L, 2L, true,
true);
+    Query rewrite = searcher.rewrite(query);
+    TopDocs docs = searcher.search(rewrite, 100);
+    ScoreDoc[] scoreDocs = docs.scoreDocs;
+    for (int i = 0; i < docs.totalHits; i++) {
+      Document document = searcher.doc(scoreDocs[i].doc);
+      assertTrue(Integer.parseInt(document.get("f1")) < 3);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eeb05f39/src/blur-core/src/test/java/com/nearinfinity/blur/manager/IndexManagerTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/com/nearinfinity/blur/manager/IndexManagerTest.java
b/src/blur-core/src/test/java/com/nearinfinity/blur/manager/IndexManagerTest.java
index e344ce8..d58495d 100644
--- a/src/blur-core/src/test/java/com/nearinfinity/blur/manager/IndexManagerTest.java
+++ b/src/blur-core/src/test/java/com/nearinfinity/blur/manager/IndexManagerTest.java
@@ -76,6 +76,7 @@ public class IndexManagerTest {
   private static final String SHARD_NAME = BlurUtil.getShardName(BlurConstants.SHARD_PREFIX,
0);
   private static final String TABLE = "table";
   private static final String FAMILY = "test-family";
+  private static final String FAMILY2 = "test-family2";
   private LocalIndexServer server;
   private IndexManager indexManager;
 
@@ -122,24 +123,76 @@ public class IndexManagerTest {
     RowMutation mutation4 = newRowMutation(TABLE, "row-4",
         newRecordMutation(FAMILY, "record-4", newColumn("testcol1", "value1"), newColumn("testcol2",
"value5"), newColumn("testcol3", "value9")),
         newRecordMutation(FAMILY, "record-4B", newColumn("testcol2", "value234123"), newColumn("testcol3",
"value234123")));
-    RowMutation mutation5 = newRowMutation(
-        TABLE,
-        "row-5",
+    RowMutation mutation5 = newRowMutation(TABLE,"row-5",
         newRecordMutation(FAMILY, "record-5A", newColumn("testcol1", "value13"), newColumn("testcol2",
"value14"), newColumn("testcol3", "value15")),
-        newRecordMutation(FAMILY, "record-5B", newColumn("testcol1", "value16"), newColumn("testcol2",
"value17"), newColumn("testcol3", "value18"),
-            newColumn("testcol3", "value19")));
-    mutation5.waitToBeVisible = true;
+        newRecordMutation(FAMILY, "record-5B", newColumn("testcol1", "value16"), newColumn("testcol2",
"value17"), newColumn("testcol3", "value18"), newColumn("testcol3", "value19")));
+    RowMutation mutation6 = newRowMutation(TABLE, "row-6", 
+        newRecordMutation(FAMILY, "record-6A", newColumn("testcol12", "value110"), newColumn("testcol13",
"value102")),
+        newRecordMutation(FAMILY, "record-6B", newColumn("testcol12", "value101"), newColumn("testcol13",
"value104")),
+        newRecordMutation(FAMILY2, "record-6C", newColumn("testcol18", "value501")));
+    RowMutation mutation7 = newRowMutation(TABLE, "row-7", 
+        newRecordMutation(FAMILY, "record-7A", newColumn("testcol12", "value101"), newColumn("testcol13",
"value102")),
+        newRecordMutation(FAMILY2, "record-7B", newColumn("testcol18", "value501")));
+    mutation7.waitToBeVisible = true;
     indexManager.mutate(mutation1);
     indexManager.mutate(mutation2);
     indexManager.mutate(mutation3);
     indexManager.mutate(mutation4);
     indexManager.mutate(mutation5);
+    indexManager.mutate(mutation6);
+    indexManager.mutate(mutation7);
   }
 
   @Test
+  public void testQueryWithJoinAll() throws Exception {
+    BlurQuery blurQuery = new BlurQuery();
+    blurQuery.simpleQuery = new SimpleQuery();
+    blurQuery.simpleQuery.queryStr = "+test-family.testcol12:value101 +test-family.testcol13:value102
+test-family2.testcol18:value501";
+    blurQuery.simpleQuery.superQueryOn = true;
+    blurQuery.simpleQuery.type = ScoreType.SUPER;
+    blurQuery.fetch = 10;
+    blurQuery.minimumNumberOfResults = Long.MAX_VALUE;
+    blurQuery.maxQueryTime = Long.MAX_VALUE;
+    blurQuery.uuid = 1;
+
+    BlurResultIterable iterable = indexManager.query(TABLE, blurQuery, null);
+    assertEquals(iterable.getTotalResults(), 2);
+    for (BlurResult result : iterable) {
+      Selector selector = new Selector().setLocationId(result.getLocationId());
+      FetchResult fetchResult = new FetchResult();
+      indexManager.fetchRow(TABLE, selector, fetchResult);
+      assertNotNull(fetchResult.rowResult);
+      assertNull(fetchResult.recordResult);
+    }
+  }
+  
+  @Test
   public void testQueryWithJoin() throws Exception {
     BlurQuery blurQuery = new BlurQuery();
     blurQuery.simpleQuery = new SimpleQuery();
+    blurQuery.simpleQuery.queryStr = "+(+test-family.testcol12:value101 +test-family.testcol13:value102)
+test-family2.testcol18:value501";
+    blurQuery.simpleQuery.superQueryOn = true;
+    blurQuery.simpleQuery.type = ScoreType.SUPER;
+    blurQuery.fetch = 10;
+    blurQuery.minimumNumberOfResults = Long.MAX_VALUE;
+    blurQuery.maxQueryTime = Long.MAX_VALUE;
+    blurQuery.uuid = 1;
+
+    BlurResultIterable iterable = indexManager.query(TABLE, blurQuery, null);
+    assertEquals(iterable.getTotalResults(), 1);
+    for (BlurResult result : iterable) {
+      Selector selector = new Selector().setLocationId(result.getLocationId());
+      FetchResult fetchResult = new FetchResult();
+      indexManager.fetchRow(TABLE, selector, fetchResult);
+      assertNotNull(fetchResult.rowResult);
+      assertNull(fetchResult.recordResult);
+    }
+  }
+
+  @Test
+  public void testQueryWithJoinForcingSuperQuery() throws Exception {
+    BlurQuery blurQuery = new BlurQuery();
+    blurQuery.simpleQuery = new SimpleQuery();
     blurQuery.simpleQuery.queryStr = "+(+test-family.testcol1:value1 nojoin) +(+test-family.testcol3:value234123)";
     blurQuery.simpleQuery.superQueryOn = true;
     blurQuery.simpleQuery.type = ScoreType.SUPER;
@@ -301,8 +354,9 @@ public class IndexManagerTest {
     Schema schema = indexManager.schema(TABLE);
     assertEquals(TABLE, schema.table);
     Map<String, Set<String>> columnFamilies = schema.columnFamilies;
-    assertEquals(new TreeSet<String>(Arrays.asList(FAMILY)), new TreeSet<String>(columnFamilies.keySet()));
-    assertEquals(new TreeSet<String>(Arrays.asList("testcol1", "testcol2", "testcol3")),
new TreeSet<String>(columnFamilies.get(FAMILY)));
+    assertEquals(new TreeSet<String>(Arrays.asList(FAMILY, FAMILY2)), new TreeSet<String>(columnFamilies.keySet()));
+    assertEquals(new TreeSet<String>(Arrays.asList("testcol1", "testcol2", "testcol3",
"testcol12", "testcol13")), new TreeSet<String>(columnFamilies.get(FAMILY)));
+    assertEquals(new TreeSet<String>(Arrays.asList("testcol18")), new TreeSet<String>(columnFamilies.get(FAMILY2)));
   }
 
   @Test
@@ -573,9 +627,9 @@ public class IndexManagerTest {
 
   @Test(expected = BlurException.class)
   public void testMutationUpdateMissingRowDeleteRecord() throws Exception {
-    RecordMutation rm = newRecordMutation(DELETE_ENTIRE_RECORD, FAMILY, "record-6");
+    RecordMutation rm = newRecordMutation(DELETE_ENTIRE_RECORD, FAMILY, "record-101");
 
-    RowMutation rowMutation = newRowMutation(UPDATE_ROW, TABLE, "row-6", rm);
+    RowMutation rowMutation = newRowMutation(UPDATE_ROW, TABLE, "row-101", rm);
     rowMutation.waitToBeVisible = true;
     indexManager.mutate(rowMutation);
   }
@@ -657,10 +711,10 @@ public class IndexManagerTest {
     Column c1 = newColumn("testcol1", "value104");
     Column c2 = newColumn("testcol2", "value105");
     Column c3 = newColumn("testcol3", "value105");
-    String rec = "record-6";
+    String rec = "record-100";
     RecordMutation rm = newRecordMutation(REPLACE_ENTIRE_RECORD, FAMILY, rec, c1, c2, c3);
 
-    updateAndFetchRecord("row-6", rec, rm);
+    updateAndFetchRecord("row-100", rec, rm);
   }
 
   @Test


Mime
View raw message