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 2020/08/26 12:06:13 UTC

[lucenenet] branch master updated (5e4d299 -> 2a006dc)

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git.


    from 5e4d299  PERFORMANCE: Lucene.Net.Diagnostics: Added Asssert overload for passing a string for cases where no concatenation is used.
     new 5ea888b  Lucene.Net.Replicator: Fixed an issue in IndexInputStream that meant the read method could return a number larger than what was passed in for read count or what the buffer could hold, it should instead return the total number of bytes that was read into the buffer, which logically can't be bigger than the buffer it self.
     new 9f09f3b  Lucene.Net.Replicator: Review fixes
     new 2a006dc  Lucene.Net.Replicator: Review fixes

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/Lucene.Net.Replicator/IndexInputInputStream.cs |  7 +-
 .../IndexInputStreamTest.cs                        | 74 ++++++++++++++++++++++
 2 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs


[lucenenet] 02/03: Lucene.Net.Replicator: Review fixes

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 9f09f3b770daf55883d0d293fa111c05d6bfe497
Author: Jens Melgaard <ad...@it-links.dk>
AuthorDate: Wed Aug 26 13:54:29 2020 +0200

    Lucene.Net.Replicator: Review fixes
---
 src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs b/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
index b16de7d..0007d85 100644
--- a/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
+++ b/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
@@ -2,10 +2,12 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using Lucene.Net.Attributes;
 using Lucene.Net.Index;
 using Lucene.Net.Replicator;
 using Lucene.Net.Store;
 using NUnit.Framework;
+using Assert = Lucene.Net.TestFramework.Assert;
 
 namespace Lucene.Net.Tests.Replicator
 {
@@ -31,6 +33,7 @@ namespace Lucene.Net.Tests.Replicator
     {
         
         [Test]
+        [LuceneNetSpecific]
         public void Read_RemainingIndexInputLargerThanReadCount_ReturnsReadCount()
         {
             byte[] buffer = new byte[8.KiloBytes()];
@@ -39,10 +42,11 @@ namespace Lucene.Net.Tests.Replicator
 
             int readBytes = 2.KiloBytes();
             byte[] readBuffer = new byte[readBytes];
-            Assert.That(stream.Read(readBuffer, 0, readBytes), Is.EqualTo(readBytes));
+            Assert.AreEqual(stream.Read(readBuffer, 0, readBytes), readBytes);
         }
 
         [Test]
+        [LuceneNetSpecific]
         public void Read_RemainingIndexInputLargerThanReadCount_ReturnsExpectedSection([Range(1,8)]int section)
         {
             byte[] buffer = new byte[8.KiloBytes()];
@@ -53,8 +57,7 @@ namespace Lucene.Net.Tests.Replicator
             byte[] readBuffer = new byte[readBytes];
             for (int i = section; i > 0; i--)
                 stream.Read(readBuffer, 0, readBytes);
-
-            Assert.That(readBuffer, Is.EqualTo(buffer.Skip((section-1) * readBytes).Take(readBytes).ToArray()));
+            Assert.AreEqual(readBuffer, buffer.Skip((section - 1) * readBytes).Take(readBytes).ToArray());
         }
 
     }


[lucenenet] 01/03: Lucene.Net.Replicator: Fixed an issue in IndexInputStream that meant the read method could return a number larger than what was passed in for read count or what the buffer could hold, it should instead return the total number of bytes that was read into the buffer, which logically can't be bigger than the buffer it self.

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 5ea888bcad7fbb07b17fb250a91264322670d8a1
Author: Jens Melgaard <ad...@it-links.dk>
AuthorDate: Wed Aug 26 12:56:27 2020 +0200

    Lucene.Net.Replicator: Fixed an issue in IndexInputStream that meant the read method could return a number larger than what was passed in for read count or what the buffer could hold, it should instead return the total number of bytes that was read into the buffer, which logically can't be bigger than the buffer it self.
---
 src/Lucene.Net.Replicator/IndexInputInputStream.cs |  7 +--
 .../IndexInputStreamTest.cs                        | 70 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/src/Lucene.Net.Replicator/IndexInputInputStream.cs b/src/Lucene.Net.Replicator/IndexInputInputStream.cs
index 3c8d54d..6a4a944 100644
--- a/src/Lucene.Net.Replicator/IndexInputInputStream.cs
+++ b/src/Lucene.Net.Replicator/IndexInputInputStream.cs
@@ -30,12 +30,10 @@ namespace Lucene.Net.Replicator
     public class IndexInputStream : Stream
     {
         private readonly IndexInput input;
-        private long remaining;
 
         public IndexInputStream(IndexInput input)
         {
             this.input = input;
-            remaining = input.Length;
         }
 
         public override void Flush()
@@ -68,8 +66,9 @@ namespace Lucene.Net.Replicator
         public override int Read(byte[] buffer, int offset, int count)
         {
             int remaining = (int) (input.Length - input.GetFilePointer());
-            input.ReadBytes(buffer, offset, Math.Min(remaining, count));
-            return remaining;
+            int readCount = Math.Min(remaining, count);
+            input.ReadBytes(buffer, offset, readCount);
+            return readCount;
         }
 
         public override void Write(byte[] buffer, int offset, int count)
diff --git a/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs b/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
new file mode 100644
index 0000000..b16de7d
--- /dev/null
+++ b/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Lucene.Net.Index;
+using Lucene.Net.Replicator;
+using Lucene.Net.Store;
+using NUnit.Framework;
+
+namespace Lucene.Net.Tests.Replicator
+{
+    /*
+     * 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.
+     */
+
+    //Note: LUCENENET specific
+    public class IndexInputStreamTest
+    {
+        
+        [Test]
+        public void Read_RemainingIndexInputLargerThanReadCount_ReturnsReadCount()
+        {
+            byte[] buffer = new byte[8.KiloBytes()];
+            new Random().NextBytes(buffer);
+            IndexInputStream stream = new IndexInputStream(new MockIndexInput(buffer));
+
+            int readBytes = 2.KiloBytes();
+            byte[] readBuffer = new byte[readBytes];
+            Assert.That(stream.Read(readBuffer, 0, readBytes), Is.EqualTo(readBytes));
+        }
+
+        [Test]
+        public void Read_RemainingIndexInputLargerThanReadCount_ReturnsExpectedSection([Range(1,8)]int section)
+        {
+            byte[] buffer = new byte[8.KiloBytes()];
+            new Random().NextBytes(buffer);
+            IndexInputStream stream = new IndexInputStream(new MockIndexInput(buffer));
+
+            int readBytes = 1.KiloBytes();
+            byte[] readBuffer = new byte[readBytes];
+            for (int i = section; i > 0; i--)
+                stream.Read(readBuffer, 0, readBytes);
+
+            Assert.That(readBuffer, Is.EqualTo(buffer.Skip((section-1) * readBytes).Take(readBytes).ToArray()));
+        }
+
+    }
+
+    //Note: LUCENENET specific
+    internal static class ByteHelperExtensions
+    {
+        public static int KiloBytes(this int value)
+        {
+            return value * 1024;
+        }
+    }
+}


[lucenenet] 03/03: Lucene.Net.Replicator: Review fixes

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 2a006dcfa276256084233323b6e0f347ee3f5914
Author: Jens Melgaard <ad...@it-links.dk>
AuthorDate: Wed Aug 26 13:58:57 2020 +0200

    Lucene.Net.Replicator: Review fixes
---
 src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs b/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
index 0007d85..a38c06c 100644
--- a/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
+++ b/src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs
@@ -29,6 +29,7 @@ namespace Lucene.Net.Tests.Replicator
      */
 
     //Note: LUCENENET specific
+    [LuceneNetSpecific]
     public class IndexInputStreamTest
     {