lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [24/47] lucenenet git commit: Added Codecs.IntBlock tests + mocks to the project
Date Tue, 11 Oct 2016 18:35:09 GMT
Added Codecs.IntBlock tests + mocks to the project


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8e1656b9
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8e1656b9
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8e1656b9

Branch: refs/heads/master
Commit: 8e1656b953a0b0d21e5771e7efa34af21adb3214
Parents: 4137444
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Oct 11 00:08:12 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Oct 11 00:26:23 2016 +0700

----------------------------------------------------------------------
 .../MockFixedIntBlockPostingsFormat.cs          | 251 +++++++++++++++++
 .../MockVariableIntBlockPostingsFormat.cs       | 279 +++++++++++++++++++
 .../Lucene.Net.TestFramework.csproj             |   2 +
 .../IntBlock/TestFixedIntBlockPostingsFormat.cs |  44 ++-
 .../IntBlock/TestIntBlockCodec.cs               |  92 +++---
 .../TestVariableIntBlockPostingsFormat.cs       |  48 ++--
 .../Lucene.Net.Tests.Codecs.csproj              |   3 +
 7 files changed, 625 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockFixedIntBlockPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockFixedIntBlockPostingsFormat.cs
b/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockFixedIntBlockPostingsFormat.cs
new file mode 100644
index 0000000..fc15dd0
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockFixedIntBlockPostingsFormat.cs
@@ -0,0 +1,251 @@
+using Lucene.Net.Codecs.BlockTerms;
+using Lucene.Net.Codecs.Sep;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Codecs.IntBlock
+{
+    /*
+     * 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.
+     */
+
+    /// <summary>
+    /// A silly test codec to verify core support for fixed
+    /// sized int block encoders is working.The int encoder
+    /// used here just writes each block as a series of vInt.
+    /// </summary>
+    public sealed class MockFixedIntBlockPostingsFormat : PostingsFormat
+    {
+        private readonly int blockSize;
+
+        public MockFixedIntBlockPostingsFormat()
+            : this(1)
+        {
+        }
+
+        public MockFixedIntBlockPostingsFormat(int blockSize)
+            : base("MockFixedIntBlock")
+        {
+            this.blockSize = blockSize;
+        }
+
+        public override string ToString()
+        {
+            return Name + "(blockSize=" + blockSize + ")";
+        }
+
+        // only for testing
+        public IntStreamFactory getIntFactory()
+        {
+            return new MockIntFactory(blockSize);
+        }
+
+        /**
+         * Encodes blocks as vInts of a fixed block size.
+         */
+        public class MockIntFactory : IntStreamFactory
+        {
+            private readonly int blockSize;
+
+            public MockIntFactory(int blockSize)
+            {
+                this.blockSize = blockSize;
+            }
+
+            public override IntIndexInput OpenInput(Directory dir, string fileName, IOContext
context)
+            {
+                return new FixedIntBlockIndexInputAnonymousHelper(this, dir.OpenInput(fileName,
context));
+            }
+
+            private class FixedIntBlockIndexInputAnonymousHelper : FixedIntBlockIndexInput
+            {
+                private readonly MockIntFactory outerInstance;
+
+                public FixedIntBlockIndexInputAnonymousHelper(MockIntFactory outerInstance,
IndexInput input)
+                    : base(input)
+                {
+                    this.outerInstance = outerInstance;
+                }
+
+                protected override IBlockReader GetBlockReader(IndexInput @in, int[] buffer)
+                {
+                    return new BlockReaderAnonymousHelper(outerInstance, @in, buffer);
+                }
+
+                private class BlockReaderAnonymousHelper : FixedIntBlockIndexInput.IBlockReader
+                {
+                    private readonly MockIntFactory outerInstance;
+                    private readonly IndexInput @in;
+                    private readonly int[] buffer;
+
+                    public BlockReaderAnonymousHelper(MockIntFactory outerInstance, IndexInput
@in, int[] buffer)
+                    {
+                        this.outerInstance = outerInstance;
+                        this.@in = @in;
+                        this.buffer = buffer;
+                    }
+                    public void Seek(long pos)
+                    {
+                    }
+
+                    public void ReadBlock()
+                    {
+                        for (int i = 0; i < buffer.Length; i++)
+                        {
+                            buffer[i] = @in.ReadVInt();
+                        }
+                    }
+                }
+            }
+
+
+            public override IntIndexOutput CreateOutput(Directory dir, string fileName, IOContext
context)
+            {
+                IndexOutput output = dir.CreateOutput(fileName, context);
+                bool success = false;
+                try
+                {
+                    FixedIntBlockIndexOutputAnonymousHelper ret = new FixedIntBlockIndexOutputAnonymousHelper(output,
blockSize);
+
+                    success = true;
+                    return ret;
+                }
+                finally
+                {
+                    if (!success)
+                    {
+                        IOUtils.CloseWhileHandlingException(output);
+                    }
+                }
+            }
+        }
+
+        private class FixedIntBlockIndexOutputAnonymousHelper : FixedIntBlockIndexOutput
+        {
+            public FixedIntBlockIndexOutputAnonymousHelper(IndexOutput output, int blockSize)
+                : base(output, blockSize)
+            {
+            }
+            protected override void FlushBlock()
+            {
+                for (int i = 0; i < buffer.Length; i++)
+                {
+                    output.WriteVInt(buffer[i]);
+                }
+            }
+        }
+
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            PostingsWriterBase postingsWriter = new SepPostingsWriter(state, new MockIntFactory(blockSize));
+
+            bool success = false;
+            TermsIndexWriterBase indexWriter;
+            try
+            {
+                indexWriter = new FixedGapTermsIndexWriter(state);
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    postingsWriter.Dispose();
+                }
+            }
+
+            success = false;
+            try
+            {
+                FieldsConsumer ret = new BlockTermsWriter(indexWriter, state, postingsWriter);
+                success = true;
+                return ret;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    try
+                    {
+                        postingsWriter.Dispose();
+                    }
+                    finally
+                    {
+                        indexWriter.Dispose();
+                    }
+                }
+            }
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            PostingsReaderBase postingsReader = new SepPostingsReader(state.Directory,
+                                                                      state.FieldInfos,
+                                                                      state.SegmentInfo,
+                                                                      state.Context,
+                                                                      new MockIntFactory(blockSize),
state.SegmentSuffix);
+
+            TermsIndexReaderBase indexReader;
+            bool success = false;
+            try
+            {
+                indexReader = new FixedGapTermsIndexReader(state.Directory,
+                                                                 state.FieldInfos,
+                                                                 state.SegmentInfo.Name,
+                                                                 state.TermsIndexDivisor,
+                                                                 BytesRef.UTF8SortedAsUnicodeComparer,
state.SegmentSuffix,
+                                                                 IOContext.DEFAULT);
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    postingsReader.Dispose();
+                }
+            }
+
+            success = false;
+            try
+            {
+                FieldsProducer ret = new BlockTermsReader(indexReader,
+                                                          state.Directory,
+                                                          state.FieldInfos,
+                                                          state.SegmentInfo,
+                                                          postingsReader,
+                                                          state.Context,
+                                                          state.SegmentSuffix);
+                success = true;
+                return ret;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    try
+                    {
+                        postingsReader.Dispose();
+                    }
+                    finally
+                    {
+                        indexReader.Dispose();
+                    }
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockVariableIntBlockPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockVariableIntBlockPostingsFormat.cs
b/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockVariableIntBlockPostingsFormat.cs
new file mode 100644
index 0000000..eeba725
--- /dev/null
+++ b/src/Lucene.Net.TestFramework/Codecs/MockIntBlock/MockVariableIntBlockPostingsFormat.cs
@@ -0,0 +1,279 @@
+using Lucene.Net.Codecs.BlockTerms;
+using Lucene.Net.Codecs.Sep;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using System.Diagnostics;
+
+namespace Lucene.Net.Codecs.IntBlock
+{
+    /*
+     * 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.
+     */
+
+    /// <summary>
+    /// A silly test codec to verify core support for variable
+    /// sized int block encoders is working.The int encoder
+    /// used here writes baseBlockSize ints at once, if the first
+    /// int is &lt;= 3, else 2* baseBlockSize.
+    /// </summary>
+    public class MockVariableIntBlockPostingsFormat : PostingsFormat
+    {
+        private readonly int baseBlockSize;
+
+        public MockVariableIntBlockPostingsFormat()
+            : this(1)
+        {
+
+        }
+
+        public MockVariableIntBlockPostingsFormat(int baseBlockSize)
+            : base("MockVariableIntBlock")
+        {
+            this.baseBlockSize = baseBlockSize;
+        }
+
+        public override string ToString()
+        {
+            return Name + "(baseBlockSize=" + baseBlockSize + ")";
+        }
+
+        /**
+         * If the first value is &lt;= 3, writes baseBlockSize vInts at once,
+         * otherwise writes 2*baseBlockSize vInts.
+         */
+        public class MockIntFactory : IntStreamFactory
+        {
+
+            private readonly int baseBlockSize;
+
+            public MockIntFactory(int baseBlockSize)
+            {
+                this.baseBlockSize = baseBlockSize;
+            }
+
+            public override IntIndexInput OpenInput(Directory dir, string fileName, IOContext
context)
+            {
+                IndexInput input = dir.OpenInput(fileName, context);
+                int baseBlockSize = input.ReadInt();
+                return new VariableIntBlockIndexInputAnonymousHelper(input, baseBlockSize);
+            }
+
+            private class VariableIntBlockIndexInputAnonymousHelper : VariableIntBlockIndexInput
+            {
+                private readonly int baseBlockSize;
+
+                public VariableIntBlockIndexInputAnonymousHelper(IndexInput input, int baseBlockSize)
+                    : base(input)
+                {
+                    this.baseBlockSize = baseBlockSize;
+                }
+                protected override IBlockReader GetBlockReader(IndexInput @in, int[] buffer)
+                {
+                    return new BlockReaderAnonymousHelper(@in, buffer, baseBlockSize);
+                }
+
+                private class BlockReaderAnonymousHelper : IBlockReader
+                {
+                    private readonly IndexInput input;
+                    private readonly int[] buffer;
+                    private readonly int baseBlockSize;
+
+                    public BlockReaderAnonymousHelper(IndexInput input, int[] buffer, int
baseBlockSize)
+                    {
+                        this.input = input;
+                        this.buffer = buffer;
+                        this.baseBlockSize = baseBlockSize;
+                    }
+
+                    public void Seek(long pos)
+                    {
+                    }
+
+                    public int ReadBlock()
+                    {
+                        buffer[0] = input.ReadVInt();
+                        int count = buffer[0] <= 3 ? baseBlockSize - 1 : 2 * baseBlockSize
- 1;
+                        Debug.Assert(buffer.Length >= count, "buffer.length=" + buffer.Length
+ " count=" + count);
+                        for (int i = 0; i < count; i++)
+                        {
+                            buffer[i + 1] = input.ReadVInt();
+                        }
+                        return 1 + count;
+                    }
+                }
+            }
+
+            public override IntIndexOutput CreateOutput(Directory dir, string fileName, IOContext
context)
+            {
+                IndexOutput output = dir.CreateOutput(fileName, context);
+                bool success = false;
+                try
+                {
+                    output.WriteInt(baseBlockSize);
+                    VariableIntBlockIndexOutput ret = new VariableIntBlockIndexOutputAnonymousHelper(output,
2 * baseBlockSize);
+                    success = true;
+                    return ret;
+                }
+                finally
+                {
+                    if (!success)
+                    {
+                        IOUtils.CloseWhileHandlingException(output);
+                    }
+                }
+            }
+        }
+
+        private class VariableIntBlockIndexOutputAnonymousHelper : VariableIntBlockIndexOutput
+        {
+            private readonly int baseBlockSize;
+            public VariableIntBlockIndexOutputAnonymousHelper(IndexOutput output, int baseBlockSize)
+                : base(output, baseBlockSize)
+            {
+                this.baseBlockSize = baseBlockSize;
+                this.buffer = new int[2 + 2 * baseBlockSize];
+            }
+
+            private int pendingCount;
+            private readonly int[] buffer;
+
+            protected override int Add(int value)
+            {
+                buffer[pendingCount++] = value;
+                // silly variable block length int encoder: if
+                // first value <= 3, we write N vints at once;
+                // else, 2*N
+                int flushAt = buffer[0] <= 3 ? baseBlockSize : 2 * baseBlockSize;
+
+                // intentionally be non-causal here:
+                if (pendingCount == flushAt + 1)
+                {
+                    for (int i = 0; i < flushAt; i++)
+                    {
+                        output.WriteVInt(buffer[i]);
+                    }
+                    buffer[0] = buffer[flushAt];
+                    pendingCount = 1;
+                    return flushAt;
+                }
+                else
+                {
+                    return 0;
+                }
+            }
+        }
+
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            PostingsWriterBase postingsWriter = new SepPostingsWriter(state, new MockIntFactory(baseBlockSize));
+
+            bool success = false;
+            TermsIndexWriterBase indexWriter;
+            try
+            {
+                indexWriter = new FixedGapTermsIndexWriter(state);
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    postingsWriter.Dispose();
+                }
+            }
+
+            success = false;
+            try
+            {
+                FieldsConsumer ret = new BlockTermsWriter(indexWriter, state, postingsWriter);
+                success = true;
+                return ret;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    try
+                    {
+                        postingsWriter.Dispose();
+                    }
+                    finally
+                    {
+                        indexWriter.Dispose();
+                    }
+                }
+            }
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            PostingsReaderBase postingsReader = new SepPostingsReader(state.Directory,
+                                                                      state.FieldInfos,
+                                                                      state.SegmentInfo,
+                                                                      state.Context,
+                                                                      new MockIntFactory(baseBlockSize),
state.SegmentSuffix);
+
+            TermsIndexReaderBase indexReader;
+            bool success = false;
+            try
+            {
+                indexReader = new FixedGapTermsIndexReader(state.Directory,
+                                                                 state.FieldInfos,
+                                                                 state.SegmentInfo.Name,
+                                                                 state.TermsIndexDivisor,
+                                                                 BytesRef.UTF8SortedAsUnicodeComparer,
+                                                                 state.SegmentSuffix, state.Context);
+                success = true;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    postingsReader.Dispose();
+                }
+            }
+
+            success = false;
+            try
+            {
+                FieldsProducer ret = new BlockTermsReader(indexReader,
+                                                          state.Directory,
+                                                          state.FieldInfos,
+                                                          state.SegmentInfo,
+                                                          postingsReader,
+                                                          state.Context,
+                                                          state.SegmentSuffix);
+                success = true;
+                return ret;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    try
+                    {
+                        postingsReader.Dispose();
+                    }
+                    finally
+                    {
+                        indexReader.Dispose();
+                    }
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
index 66be25c..bbee1e8 100644
--- a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
+++ b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj
@@ -251,6 +251,8 @@
     <Compile Include="Codecs\MissingOrdRemapper.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Codecs\MockIntBlock\MockFixedIntBlockPostingsFormat.cs" />
+    <Compile Include="Codecs\MockIntBlock\MockVariableIntBlockPostingsFormat.cs" />
     <Compile Include="Codecs\MockSep\MockSepPostingsFormat.cs" />
     <Compile Include="Codecs\MockSep\MockSingleIntFactory.cs" />
     <Compile Include="Codecs\MockSep\MockSingleIntIndexInput.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.Tests.Codecs/IntBlock/TestFixedIntBlockPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Codecs/IntBlock/TestFixedIntBlockPostingsFormat.cs b/src/Lucene.Net.Tests.Codecs/IntBlock/TestFixedIntBlockPostingsFormat.cs
index 1133c64..1cd9e4b 100644
--- a/src/Lucene.Net.Tests.Codecs/IntBlock/TestFixedIntBlockPostingsFormat.cs
+++ b/src/Lucene.Net.Tests.Codecs/IntBlock/TestFixedIntBlockPostingsFormat.cs
@@ -1,7 +1,10 @@
-namespace org.apache.lucene.codecs.intblock
-{
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+using NUnit.Framework;
 
-	/*
+namespace Lucene.Net.Codecs.IntBlock
+{
+    /*
 	 * 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.
@@ -18,25 +21,20 @@
 	 * limitations under the License.
 	 */
 
-	using MockFixedIntBlockPostingsFormat = org.apache.lucene.codecs.mockintblock.MockFixedIntBlockPostingsFormat;
-	using BasePostingsFormatTestCase = org.apache.lucene.index.BasePostingsFormatTestCase;
-	using TestUtil = org.apache.lucene.util.TestUtil;
-
-	/// <summary>
-	/// Basic tests for FixedIntBlock
-	/// </summary>
-	public class TestFixedIntBlockPostingsFormat : BasePostingsFormatTestCase
-	{
-	  // TODO: randomize blocksize
-	  private readonly Codec codec = TestUtil.alwaysPostingsFormat(new MockFixedIntBlockPostingsFormat());
-
-	  protected internal override Codec Codec
-	  {
-		  get
-		  {
-			return codec;
-		  }
-	  }
-	}
+    /// <summary>
+    /// Basic tests for FixedIntBlock
+    /// </summary>
+    public class TestFixedIntBlockPostingsFormat : BasePostingsFormatTestCase
+    {
+        // TODO: randomize blocksize
+        private readonly Codec codec = TestUtil.AlwaysPostingsFormat(new MockFixedIntBlockPostingsFormat());
 
+        protected override Codec Codec
+        {
+            get
+            {
+                return codec;
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.Tests.Codecs/IntBlock/TestIntBlockCodec.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Codecs/IntBlock/TestIntBlockCodec.cs b/src/Lucene.Net.Tests.Codecs/IntBlock/TestIntBlockCodec.cs
index 1e973dc..f84ac9a 100644
--- a/src/Lucene.Net.Tests.Codecs/IntBlock/TestIntBlockCodec.cs
+++ b/src/Lucene.Net.Tests.Codecs/IntBlock/TestIntBlockCodec.cs
@@ -1,7 +1,11 @@
-namespace org.apache.lucene.codecs.intblock
-{
+using Lucene.Net.Codecs.Sep;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using NUnit.Framework;
 
-	/*
+namespace Lucene.Net.Codecs.IntBlock
+{
+    /*
 	 * 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.
@@ -18,59 +22,51 @@
 	 * limitations under the License.
 	 */
 
-	using LuceneTestCase = org.apache.lucene.util.LuceneTestCase;
-	using org.apache.lucene.store;
-	using org.apache.lucene.codecs.mockintblock;
-	using org.apache.lucene.codecs.sep;
-
-	public class TestIntBlockCodec : LuceneTestCase
-	{
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public void testSimpleIntBlocks() throws Exception
-	  public virtual void testSimpleIntBlocks()
-	  {
-		Directory dir = newDirectory();
+    public class TestIntBlockCodec : LuceneTestCase
+    {
 
-		IntStreamFactory f = (new MockFixedIntBlockPostingsFormat(128)).IntFactory;
+        [Test]
+        public virtual void TestSimpleIntBlocks()
+        {
+            Directory dir = NewDirectory();
 
-		IntIndexOutput @out = f.createOutput(dir, "test", newIOContext(random()));
-		for (int i = 0;i < 11777;i++)
-		{
-		  @out.write(i);
-		}
-		@out.close();
+            IntStreamFactory f = (new MockFixedIntBlockPostingsFormat(128)).getIntFactory();
 
-		IntIndexInput @in = f.openInput(dir, "test", newIOContext(random()));
-		IntIndexInput.Reader r = @in.reader();
+            IntIndexOutput @out = f.CreateOutput(dir, "test", NewIOContext(Random()));
+            for (int i = 0; i < 11777; i++)
+            {
+                @out.Write(i);
+            }
+            @out.Dispose();
 
-		for (int i = 0;i < 11777;i++)
-		{
-		  assertEquals(i, r.next());
-		}
-		@in.close();
+            IntIndexInput @in = f.OpenInput(dir, "test", NewIOContext(Random()));
+            IntIndexInputReader r = @in.Reader();
 
-		dir.close();
-	  }
+            for (int i = 0; i < 11777; i++)
+            {
+                assertEquals(i, r.Next());
+            }
+            @in.Dispose();
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public void testEmptySimpleIntBlocks() throws Exception
-	  public virtual void testEmptySimpleIntBlocks()
-	  {
-		Directory dir = newDirectory();
+            dir.Dispose();
+        }
 
-		IntStreamFactory f = (new MockFixedIntBlockPostingsFormat(128)).IntFactory;
-		IntIndexOutput @out = f.createOutput(dir, "test", newIOContext(random()));
+        [Test]
+        public virtual void TestEmptySimpleIntBlocks()
+        {
+            Directory dir = NewDirectory();
 
-		// write no ints
-		@out.close();
+            IntStreamFactory f = (new MockFixedIntBlockPostingsFormat(128)).getIntFactory();
+            IntIndexOutput @out = f.CreateOutput(dir, "test", NewIOContext(Random()));
 
-		IntIndexInput @in = f.openInput(dir, "test", newIOContext(random()));
-		@in.reader();
-		// read no ints
-		@in.close();
-		dir.close();
-	  }
-	}
+            // write no ints
+            @out.Dispose();
 
+            IntIndexInput @in = f.OpenInput(dir, "test", NewIOContext(Random()));
+            @in.Reader();
+            // read no ints
+            @in.Dispose();
+            dir.Dispose();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.Tests.Codecs/IntBlock/TestVariableIntBlockPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Codecs/IntBlock/TestVariableIntBlockPostingsFormat.cs b/src/Lucene.Net.Tests.Codecs/IntBlock/TestVariableIntBlockPostingsFormat.cs
index 0a8a644..0b74a74 100644
--- a/src/Lucene.Net.Tests.Codecs/IntBlock/TestVariableIntBlockPostingsFormat.cs
+++ b/src/Lucene.Net.Tests.Codecs/IntBlock/TestVariableIntBlockPostingsFormat.cs
@@ -1,7 +1,10 @@
-namespace org.apache.lucene.codecs.intblock
-{
+using Lucene.Net.Index;
+using Lucene.Net.Util;
+using NUnit.Framework;
 
-	/*
+namespace Lucene.Net.Codecs.IntBlock
+{
+    /*
 	 * 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.
@@ -18,26 +21,25 @@
 	 * limitations under the License.
 	 */
 
-	using MockVariableIntBlockPostingsFormat = org.apache.lucene.codecs.mockintblock.MockVariableIntBlockPostingsFormat;
-	using BasePostingsFormatTestCase = org.apache.lucene.index.BasePostingsFormatTestCase;
-	using TestUtil = org.apache.lucene.util.TestUtil;
-	using TestUtil = org.apache.lucene.util.TestUtil;
-
-	/// <summary>
-	/// Basic tests for VariableIntBlock
-	/// </summary>
-	public class TestVariableIntBlockPostingsFormat : BasePostingsFormatTestCase
-	{
-	  // TODO: randomize blocksize
-	  private readonly Codec codec = TestUtil.alwaysPostingsFormat(new MockVariableIntBlockPostingsFormat());
+    //using MockVariableIntBlockPostingsFormat = org.apache.lucene.codecs.mockintblock.MockVariableIntBlockPostingsFormat;
+    //using BasePostingsFormatTestCase = org.apache.lucene.index.BasePostingsFormatTestCase;
+    //using TestUtil = org.apache.lucene.util.TestUtil;
+    //using TestUtil = org.apache.lucene.util.TestUtil;
 
-	  protected internal override Codec Codec
-	  {
-		  get
-		  {
-			return codec;
-		  }
-	  }
-	}
+    /// <summary>
+    /// Basic tests for VariableIntBlock
+    /// </summary>
+    public class TestVariableIntBlockPostingsFormat : BasePostingsFormatTestCase
+    {
+        // TODO: randomize blocksize
+        private readonly Codec codec = TestUtil.AlwaysPostingsFormat(new MockVariableIntBlockPostingsFormat());
 
+        protected override Codec Codec
+        {
+            get
+            {
+                return codec;
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8e1656b9/src/Lucene.Net.Tests.Codecs/Lucene.Net.Tests.Codecs.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Codecs/Lucene.Net.Tests.Codecs.csproj b/src/Lucene.Net.Tests.Codecs/Lucene.Net.Tests.Codecs.csproj
index 7002ab5..db67f15 100644
--- a/src/Lucene.Net.Tests.Codecs/Lucene.Net.Tests.Codecs.csproj
+++ b/src/Lucene.Net.Tests.Codecs/Lucene.Net.Tests.Codecs.csproj
@@ -45,6 +45,9 @@
     <Compile Include="BlockTerms\TestFixedGapPostingsFormat.cs" />
     <Compile Include="Bloom\TestBloomPostingsFormat.cs" />
     <Compile Include="DiskDv\TestDiskDocValuesFormat.cs" />
+    <Compile Include="IntBlock\TestFixedIntBlockPostingsFormat.cs" />
+    <Compile Include="IntBlock\TestIntBlockCodec.cs" />
+    <Compile Include="IntBlock\TestVariableIntBlockPostingsFormat.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Sep\TestSepPostingsFormat.cs" />
     <Compile Include="SimpleText\TestSimpleTextDocValuesFormat.cs" />


Mime
View raw message