You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2020/08/26 11:23:46 UTC

[GitHub] [lucenenet] NightOwl888 commented on a change in pull request #332: Lucene.Net.Replicator: Fixed an issue in IndexInputStream.Read(...)

NightOwl888 commented on a change in pull request #332:
URL: https://github.com/apache/lucenenet/pull/332#discussion_r477222864



##########
File path: 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]

Review comment:
       Please add `[LuceneNetSpecific]` attribute from `Lucene.Net.Attributes`.

##########
File path: 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]

Review comment:
       Please add `[LuceneNetSpecific]` attribute from `Lucene.Net.Attributes`.

##########
File path: 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));

Review comment:
       Please use `Lucene.Net.TestFramework.Assert.AreEqual()` to make comparisons. NUnit's asserts are extremely slow so we are avoiding them.

##########
File path: 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()));

Review comment:
       Please use `Lucene.Net.TestFramework.Assert.AreEqual()` to make comparisons. NUnit's asserts are extremely slow so we are avoiding them.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org