You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/07/11 07:42:37 UTC
[12/22] lucenenet git commit: lucene-cli: added integration tests for
the IndexUpgradeCommand
lucene-cli: added integration tests for the IndexUpgradeCommand
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/92db055e
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/92db055e
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/92db055e
Branch: refs/heads/master
Commit: 92db055eae0fa42ebbea1f00a46d3cefb3e7980d
Parents: faa85eb
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Jul 10 18:05:57 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Jul 10 18:05:57 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Index/IndexUpgrader.cs | 6 +-
src/Lucene.Net/Properties/AssemblyInfo.cs | 1 +
.../Commands/CommandTestCase.cs | 27 ++++---
.../Commands/Index/IndexUpgradeCommandTest.cs | 77 ++++++++++++++++++++
.../index/index-upgrade/IndexUpgradeCommand.cs | 3 +-
5 files changed, 97 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92db055e/src/Lucene.Net/Index/IndexUpgrader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Index/IndexUpgrader.cs b/src/Lucene.Net/Index/IndexUpgrader.cs
index 9898fea..8cae11f 100644
--- a/src/Lucene.Net/Index/IndexUpgrader.cs
+++ b/src/Lucene.Net/Index/IndexUpgrader.cs
@@ -136,9 +136,9 @@ namespace Lucene.Net.Index
#pragma warning restore 612, 618
}
- private readonly Directory dir;
- private readonly IndexWriterConfig iwc;
- private readonly bool deletePriorCommits;
+ internal readonly Directory dir; // LUCENENET specific - made internal for testing CLI arguments
+ internal readonly IndexWriterConfig iwc; // LUCENENET specific - made internal for testing CLI arguments
+ internal readonly bool deletePriorCommits; // LUCENENET specific - made internal for testing CLI arguments
/// <summary>
/// Creates index upgrader on the given directory, using an <see cref="IndexWriter"/> using the given
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92db055e/src/Lucene.Net/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Properties/AssemblyInfo.cs b/src/Lucene.Net/Properties/AssemblyInfo.cs
index 68b5b85..948bc8f 100644
--- a/src/Lucene.Net/Properties/AssemblyInfo.cs
+++ b/src/Lucene.Net/Properties/AssemblyInfo.cs
@@ -63,6 +63,7 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Lucene.Net.Tests.ICU")] // For Analysis.Util.TestSegmentingTokenizerBase
[assembly: InternalsVisibleTo("Lucene.Net.Tests.Misc")]
[assembly: InternalsVisibleTo("Lucene.Net.Tests.QueryParser")]
+[assembly: InternalsVisibleTo("Lucene.Net.Tests.Cli")] // For lucene-cli
// NOTE: Version information is in CommonAssemblyInfo.cs
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92db055e/src/tools/Lucene.Net.Tests.Cli/Commands/CommandTestCase.cs
----------------------------------------------------------------------
diff --git a/src/tools/Lucene.Net.Tests.Cli/Commands/CommandTestCase.cs b/src/tools/Lucene.Net.Tests.Cli/Commands/CommandTestCase.cs
index 7d933d7..9174667 100644
--- a/src/tools/Lucene.Net.Tests.Cli/Commands/CommandTestCase.cs
+++ b/src/tools/Lucene.Net.Tests.Cli/Commands/CommandTestCase.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using Lucene.Net.Util;
+using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -23,18 +24,8 @@ namespace Lucene.Net.Cli.Commands
*/
// LUCENENET TODO: Move to TestFramework ?
- public abstract class CommandTestCase
+ public abstract class CommandTestCase : LuceneTestCase
{
- [SetUp]
- protected virtual void SetUp()
- {
- }
-
- [TearDown]
- protected virtual void TearDown()
- {
- }
-
protected abstract ConfigurationBase CreateConfiguration(MockConsoleApp app);
protected abstract IList<Arg[]> GetRequiredArgs();
@@ -142,6 +133,18 @@ namespace Lucene.Net.Cli.Commands
}
}
+ /// <summary>
+ /// Runs a command against the current command configuration
+ /// </summary>
+ /// <param name="command">A command as a string that will be parsed.</param>
+ /// <returns>A MockConsoleApp that can be used to inspect the number of calls and arguments that will be passed to the Lucene CLI tool.</returns>
+ public virtual MockConsoleApp RunCommand(string command)
+ {
+ var output = new MockConsoleApp();
+ var cmd = CreateConfiguration(output).Execute(command.ToArgs());
+ return output;
+ }
+
public class MockConsoleApp
{
public void Main(string[] args)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92db055e/src/tools/Lucene.Net.Tests.Cli/Commands/Index/IndexUpgradeCommandTest.cs
----------------------------------------------------------------------
diff --git a/src/tools/Lucene.Net.Tests.Cli/Commands/Index/IndexUpgradeCommandTest.cs b/src/tools/Lucene.Net.Tests.Cli/Commands/Index/IndexUpgradeCommandTest.cs
index 776c3d4..547fbab 100644
--- a/src/tools/Lucene.Net.Tests.Cli/Commands/Index/IndexUpgradeCommandTest.cs
+++ b/src/tools/Lucene.Net.Tests.Cli/Commands/Index/IndexUpgradeCommandTest.cs
@@ -1,4 +1,6 @@
using Lucene.Net.Cli.CommandLine;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
using NUnit.Framework;
using System.Collections.Generic;
@@ -63,5 +65,80 @@ namespace Lucene.Net.Cli.Commands
{
Assert.Throws<CommandParsingException>(() => AssertConsoleOutput("one two", ""));
}
+
+ /// <summary>
+ /// Integration test to ensure --verbose argument is passed through and parsed correctly by IndexUpgrader
+ /// </summary>
+ [Test]
+ public virtual void TestPassingVerboseArgument()
+ {
+ MockConsoleApp output;
+ IndexUpgrader upgrader;
+
+ output = RunCommand(@"C:\test-index");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreSame(Util.InfoStream.Default, upgrader.iwc.InfoStream);
+
+ output = RunCommand(@"C:\test-index -v");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreNotSame(Util.InfoStream.Default, upgrader.iwc.InfoStream);
+
+ output = RunCommand(@"C:\test-index --verbose");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreNotSame(Util.InfoStream.Default, upgrader.iwc.InfoStream);
+ }
+
+ /// <summary>
+ /// Integration test to ensure --delete-prior-commits argument is passed through and parsed correctly by IndexUpgrader
+ /// </summary>
+ [Test]
+ public virtual void TestPassingDeletePriorCommitsArgument()
+ {
+ MockConsoleApp output;
+ IndexUpgrader upgrader;
+
+ output = RunCommand(@"C:\test-index");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.IsFalse(upgrader.deletePriorCommits);
+
+ output = RunCommand(@"C:\test-index -d");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.IsTrue(upgrader.deletePriorCommits);
+
+ output = RunCommand(@"C:\test-index --delete-prior-commits");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.IsTrue(upgrader.deletePriorCommits);
+ }
+
+ /// <summary>
+ /// Integration test to ensure --directory-type argument is passed through and parsed correctly by IndexUpgrader
+ /// </summary>
+ [Test]
+ public virtual void TestPassingDirectoryTypeArgument()
+ {
+ MockConsoleApp output;
+ IndexUpgrader upgrader;
+ var tempDir = CreateTempDir("index-upgrader");
+
+ output = RunCommand(@"C:\test-index");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreEqual(FSDirectory.Open(tempDir).GetType(), upgrader.dir.GetType());
+
+ output = RunCommand(@"C:\test-index -dir SimpleFSDirectory");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreEqual(typeof(SimpleFSDirectory), upgrader.dir.GetType());
+
+ output = RunCommand(@"C:\test-index --directory-type SimpleFSDirectory");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreEqual(typeof(SimpleFSDirectory), upgrader.dir.GetType());
+
+ output = RunCommand(@"C:\test-index -dir MMapDirectory");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreEqual(typeof(MMapDirectory), upgrader.dir.GetType());
+
+ output = RunCommand(@"C:\test-index --directory-type MMapDirectory");
+ upgrader = IndexUpgrader.ParseArgs(output.Args);
+ Assert.AreEqual(typeof(MMapDirectory), upgrader.dir.GetType());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92db055e/src/tools/lucene-cli/commands/index/index-upgrade/IndexUpgradeCommand.cs
----------------------------------------------------------------------
diff --git a/src/tools/lucene-cli/commands/index/index-upgrade/IndexUpgradeCommand.cs b/src/tools/lucene-cli/commands/index/index-upgrade/IndexUpgradeCommand.cs
index f849bb5..eadcc72 100644
--- a/src/tools/lucene-cli/commands/index/index-upgrade/IndexUpgradeCommand.cs
+++ b/src/tools/lucene-cli/commands/index/index-upgrade/IndexUpgradeCommand.cs
@@ -31,6 +31,7 @@ namespace Lucene.Net.Cli
this.Name = "upgrade";
this.Description = FromResource("Description");
+ this.ExtendedHelpText = FromResource("ExtendedHelpText");
this.Arguments.Add(new IndexDirectoryArgument());
this.DeletePriorCommitsOption = this.Option("-d|--delete-prior-commits",
@@ -39,8 +40,6 @@ namespace Lucene.Net.Cli
this.Options.Add(new VerboseOption());
this.Options.Add(new DirectoryTypeOption());
- this.ExtendedHelpText = FromResource("ExtendedHelpText");
-
this.OnExecute(() => new IndexUpgradeCommand().Run(this));
}