Repository: incubator-blur Updated Branches: refs/heads/master 21ff08341 -> d683f1aae
add some simple test coverage to get a feel for the command stuffs Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/d683f1aa Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/d683f1aa Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/d683f1aa Branch: refs/heads/master Commit: d683f1aae710480e44f7ac4e382d7996383aec0b Parents: 21ff083 Author: twilliams <[email protected]> Authored: Mon Sep 22 19:49:42 2014 -0400 Committer: twilliams <[email protected]> Committed: Mon Sep 22 19:49:42 2014 -0400 ---------------------------------------------------------------------- .../blur/command/DocumentCountCombinerTest.java | 44 +++++++++ .../apache/blur/command/DocumentCountTest.java | 29 ++++++ .../org/apache/blur/command/TestContext.java | 96 ++++++++++++++++++++ .../apache/blur/command/BaseCommandManager.java | 2 +- .../org/apache/blur/command/IndexContext.java | 2 - .../blur/command/ShardCommandManager.java | 5 - 6 files changed, 170 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d683f1aa/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 new file mode 100644 index 0000000..18dc750 --- /dev/null +++ b/blur-command/src/test/java/org/apache/blur/command/DocumentCountCombinerTest.java @@ -0,0 +1,44 @@ +package org.apache.blur.command; + + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +public class DocumentCountCombinerTest { + private static IndexContext ctx; + + @BeforeClass + public static void init() { + ctx = TestContext.newSimpleAlpaNumContext(); + } + + @Test + public void documentCountShouldBeAccurate() throws IOException { + DocumentCountCombiner dc = new DocumentCountCombiner(); + + int docCount = dc.execute(ctx); + + assertEquals(26, docCount); + } + + @Test + public void combineShouldProperlySum() throws IOException { + DocumentCountCombiner dc = new DocumentCountCombiner(); + Map<Shard, Integer> shardTotals = Maps + .newHashMap(ImmutableMap + .of(new Shard("t1","s1"), 10, new Shard("t1","s2"), 20, new Shard("t1","s3"), 30)); + long total = dc.combine(shardTotals); + + assertEquals(60l, total); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d683f1aa/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 new file mode 100644 index 0000000..8552486 --- /dev/null +++ b/blur-command/src/test/java/org/apache/blur/command/DocumentCountTest.java @@ -0,0 +1,29 @@ +package org.apache.blur.command; + + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class DocumentCountTest { + private static IndexContext ctx; + + @BeforeClass + public static void init() { + ctx = TestContext.newSimpleAlpaNumContext(); + } + + @Test + public void documentCountShouldBeAccurate() throws IOException { + DocumentCount dc = new DocumentCount(); + + int docCount = dc.execute(ctx); + + assertEquals(26, docCount); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d683f1aa/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 new file mode 100644 index 0000000..3bacb12 --- /dev/null +++ b/blur-command/src/test/java/org/apache/blur/command/TestContext.java @@ -0,0 +1,96 @@ +package org.apache.blur.command; + +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/d683f1aa/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java b/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java index b36c63a..480af71 100644 --- a/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java +++ b/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java @@ -181,7 +181,7 @@ public class BaseCommandManager implements Closeable { } protected BigInteger checkContents(FileStatus fileStatus, FileSystem fileSystem) throws IOException { - if (fileStatus.isDirectory()) { + if (fileStatus.isDir()) { BigInteger count = BigInteger.ZERO; Path path = fileStatus.getPath(); FileStatus[] listStatus = fileSystem.listStatus(path); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d683f1aa/blur-core/src/main/java/org/apache/blur/command/IndexContext.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/IndexContext.java b/blur-core/src/main/java/org/apache/blur/command/IndexContext.java index 64f7643..02f260f 100644 --- a/blur-core/src/main/java/org/apache/blur/command/IndexContext.java +++ b/blur-core/src/main/java/org/apache/blur/command/IndexContext.java @@ -37,6 +37,4 @@ public abstract class IndexContext { public abstract BlurConfiguration getBlurConfiguration(); - public abstract Configuration getConfiguration(); - } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/d683f1aa/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java b/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java index 4298cdf..ddad04d 100644 --- a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java +++ b/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java @@ -218,11 +218,6 @@ public class ShardCommandManager extends BaseCommandManager { return _tableContext.getBlurConfiguration(); } - @Override - public Configuration getConfiguration() { - return _tableContext.getConfiguration(); - } - } public void cancel(ExecutionId executionId) {
