incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject [2/4] git commit: Allow args to vary per test
Date Tue, 23 Sep 2014 02:56:11 GMT
Allow args to vary per test


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

Branch: refs/heads/master
Commit: 4ddfab11bc90351370259e1ff8a8e1e39e560c6b
Parents: 76e79b5
Author: twilliams <twilliams@apache.org>
Authored: Mon Sep 22 22:15:10 2014 -0400
Committer: twilliams <twilliams@apache.org>
Committed: Mon Sep 22 22:15:10 2014 -0400

----------------------------------------------------------------------
 .../apache/blur/command/CoreTestContext.java    | 117 +++++++++++++++++++
 .../blur/command/DocumentCountCombinerTest.java |   2 +-
 .../apache/blur/command/DocumentCountTest.java  |   2 +-
 .../org/apache/blur/command/TestContext.java    | 113 ------------------
 .../blur/command/TestContextArgDecorator.java   |  64 ++++++++++
 5 files changed, 183 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ddfab11/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java b/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java
new file mode 100644
index 0000000..b564ebd
--- /dev/null
+++ b/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java
@@ -0,0 +1,117 @@
+package org.apache.blur.command;
+
+/**
+ * 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 org.apache.blur.BlurConfiguration;
+import org.apache.blur.server.TableContext;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.Version;
+
+public class CoreTestContext extends IndexContext {
+  private RAMDirectory directory = new RAMDirectory();
+  private Args args = null;
+
+  private CoreTestContext() {
+  }
+
+  /**
+   * Index will contain 26 documents with the following column/values: 
+   * alpha = double-letter a-z (lowercase characters); 
+   * num = 0-25 val = val (constant across all docs)
+   * 
+   * New columns may be added so don't rely on the column count in tests.
+   * 
+   * @return
+   */
+  public static IndexContext newSimpleAlpaNumContext() {
+    CoreTestContext ctx = new CoreTestContext();
+
+    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new StandardAnalyzer(Version.LUCENE_43));
+    try {
+      IndexWriter writer = new IndexWriter(ctx.directory, conf);
+
+      for (int i = 0; i < 26; i++) {
+        String alpha = new Character((char) (97 + i)).toString();
+        Document doc = new Document();
+
+        doc.add(new Field("id", Integer.toString(i), TextField.TYPE_STORED));
+        doc.add(new Field("alpha", alpha + alpha, TextField.TYPE_STORED));
+        doc.add(new Field("num", Integer.toString(i), TextField.TYPE_STORED));
+        doc.add(new Field("val", "val", TextField.TYPE_STORED));
+        
+        writer.addDocument(doc);
+        
+        writer.commit();
+      }
+      writer.commit();
+      writer.close();
+    } catch (IOException e) {
+      throw new RuntimeException("Unable to create test context.", e);
+    }
+
+    return ctx;
+  }
+
+  @Override
+  public TableContext getTableContext() {
+    return null;
+  }
+
+  @Override
+  public Shard getShard() {
+    return null;
+  }
+
+  @Override
+  public IndexSearcher getIndexSearcher() {
+    return new IndexSearcher(getIndexReader());
+  }
+
+  @Override
+  public IndexReader getIndexReader() {
+    try {
+      return DirectoryReader.open(directory);
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+
+    return null;
+  }
+
+  @Override
+  public BlurConfiguration getBlurConfiguration() {
+    return null;
+  }
+
+  @Override
+  public Args getArgs() {
+    return args;
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ddfab11/blur-command/src/test/java/org/apache/blur/command/DocumentCountCombinerTest.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/DocumentCountCombinerTest.java
b/blur-command/src/test/java/org/apache/blur/command/DocumentCountCombinerTest.java
index d169e49..36b7083 100644
--- a/blur-command/src/test/java/org/apache/blur/command/DocumentCountCombinerTest.java
+++ b/blur-command/src/test/java/org/apache/blur/command/DocumentCountCombinerTest.java
@@ -33,7 +33,7 @@ public class DocumentCountCombinerTest  {
   
   @BeforeClass
   public static void init() {
-    ctx = TestContext.newSimpleAlpaNumContext();
+    ctx = CoreTestContext.newSimpleAlpaNumContext();
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ddfab11/blur-command/src/test/java/org/apache/blur/command/DocumentCountTest.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/DocumentCountTest.java b/blur-command/src/test/java/org/apache/blur/command/DocumentCountTest.java
index 258b517..79506fe 100644
--- a/blur-command/src/test/java/org/apache/blur/command/DocumentCountTest.java
+++ b/blur-command/src/test/java/org/apache/blur/command/DocumentCountTest.java
@@ -29,7 +29,7 @@ public class DocumentCountTest  {
   
   @BeforeClass
   public static void init() {
-    ctx = TestContext.newSimpleAlpaNumContext();
+    ctx = CoreTestContext.newSimpleAlpaNumContext();
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ddfab11/blur-command/src/test/java/org/apache/blur/command/TestContext.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/TestContext.java b/blur-command/src/test/java/org/apache/blur/command/TestContext.java
deleted file mode 100644
index fca7953..0000000
--- a/blur-command/src/test/java/org/apache/blur/command/TestContext.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.apache.blur.command;
-
-/**
- * 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 org.apache.blur.BlurConfiguration;
-import org.apache.blur.server.TableContext;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.TextField;
-import org.apache.lucene.index.DirectoryReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.util.Version;
-
-public class TestContext extends IndexContext {
-  private RAMDirectory directory = new RAMDirectory();
-
-  private TestContext() {
-  }
-  
-  /**
-   * Index will contain 26 documents with the following column/values:
-   * alpha = a-z (lowercase characters);
-   * num   = 0-25 
-   * val   = val (constant across all docs)
-   * 
-   * New columns may be added so don't rely on the column count in tests.
-   * @return
-   */
-  public static IndexContext newSimpleAlpaNumContext() {
-    TestContext ctx = new TestContext();
-    
-    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new StandardAnalyzer(Version.LUCENE_43));
-    try {
-      IndexWriter writer = new IndexWriter(ctx.directory, conf);
-      
-      for (int i = 0; i < 26; i++) {
-        String alpha = new Character((char) (97+i)).toString();
-        Document doc = new Document();
-        
-        doc.add(new Field("alpha", alpha,TextField.TYPE_STORED));
-        doc.add(new Field("num", Integer.toString(i), TextField.TYPE_STORED));
-        doc.add(new Field("val", "val", TextField.TYPE_STORED));
-        
-        writer.addDocument(doc);
-      }
-      writer.commit();
-      writer.close();
-    } catch (IOException e) {
-      throw new RuntimeException("Unable to create test context.", e);
-    }
-    
-    return ctx;
-  }
-
-  @Override
-  public TableContext getTableContext() {
-    return null;
-  }
-
-  @Override
-  public Shard getShard() {
-    return null;
-  }
-
-  @Override
-  public IndexSearcher getIndexSearcher() {
-    return null;
-  }
-
-  @Override
-  public IndexReader getIndexReader() {
-    try {
-      return DirectoryReader.open(directory);
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-
-    return null;
-  }
-
-  @Override
-  public BlurConfiguration getBlurConfiguration() {
-    return null;
-  }
-
-  @Override
-  public Args getArgs() {
-    return null;
-  }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ddfab11/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java
b/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java
new file mode 100644
index 0000000..efa8da8
--- /dev/null
+++ b/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java
@@ -0,0 +1,64 @@
+package org.apache.blur.command;
+
+import org.apache.blur.BlurConfiguration;
+import org.apache.blur.server.TableContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.IndexSearcher;
+
+/**
+ * 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.
+ */
+public class TestContextArgDecorator extends IndexContext {
+  private IndexContext heavyContext;
+  private Args args;
+
+  public TestContextArgDecorator(IndexContext heavyContext, Args args) {
+    super();
+    this.heavyContext = heavyContext;
+    this.args = args;
+  }
+
+  public TableContext getTableContext() {
+    return heavyContext.getTableContext();
+  }
+
+  public Shard getShard() {
+    return heavyContext.getShard();
+  }
+
+  public IndexReader getIndexReader() {
+    return heavyContext.getIndexReader();
+  }
+
+  public IndexSearcher getIndexSearcher() {
+    return heavyContext.getIndexSearcher();
+  }
+
+  public BlurConfiguration getBlurConfiguration() {
+    return heavyContext.getBlurConfiguration();
+  }
+
+  @Override
+  public Args getArgs() {
+    return this.args;
+  }
+  
+  
+  
+  
+  
+
+}


Mime
View raw message