BUG: Lucene.Net.Store.LockVerifyServer: Read/write 1 byte instead of 1 int (4 bytes). Also, we don't need 2 streams in .NET for input/output (solution provided by Vincent Van Den Berghe).
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/425d5e71 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/425d5e71 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/425d5e71 Branch: refs/heads/master Commit: 425d5e7152aa1f501b7a849333e6554c59073526 Parents: 95a7505 Author: Shad Storhaug <[email protected]> Authored: Thu Jul 20 16:48:43 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Jul 20 17:40:25 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net/Store/LockStressTest.cs | 10 +++++----- src/Lucene.Net/Store/LockVerifyServer.cs | 15 +++++++-------- src/Lucene.Net/Store/VerifyingLockFactory.cs | 17 +++++++---------- 3 files changed, 19 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/425d5e71/src/Lucene.Net/Store/LockStressTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/LockStressTest.cs b/src/Lucene.Net/Store/LockStressTest.cs index 341bb69..ebd3de9 100644 --- a/src/Lucene.Net/Store/LockStressTest.cs +++ b/src/Lucene.Net/Store/LockStressTest.cs @@ -124,16 +124,16 @@ namespace Lucene.Net.Store socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); socket.Connect(verifierHost, verifierPort); - using (Stream @out = new NetworkStream(socket), @in = new NetworkStream(socket)) + using (Stream stream = new NetworkStream(socket)) { - BinaryReader intReader = new BinaryReader(@in); - BinaryWriter intWriter = new BinaryWriter(@out); + BinaryReader intReader = new BinaryReader(stream); + BinaryWriter intWriter = new BinaryWriter(stream); intWriter.Write(myID); - @out.Flush(); + stream.Flush(); lockFactory.LockPrefix = "test"; - LockFactory verifyLF = new VerifyingLockFactory(lockFactory, @in, @out); + LockFactory verifyLF = new VerifyingLockFactory(lockFactory, stream); Lock l = verifyLF.MakeLock("test.lock"); Random rnd = new Random(); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/425d5e71/src/Lucene.Net/Store/LockVerifyServer.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/LockVerifyServer.cs b/src/Lucene.Net/Store/LockVerifyServer.cs index 93a1a52..0060606 100644 --- a/src/Lucene.Net/Store/LockVerifyServer.cs +++ b/src/Lucene.Net/Store/LockVerifyServer.cs @@ -113,10 +113,10 @@ namespace Lucene.Net.Store public override void Run() { - using (Stream @in = new NetworkStream(cs), os = new NetworkStream(cs)) + using (Stream stream = new NetworkStream(cs)) { - BinaryReader intReader = new BinaryReader(@in); - BinaryWriter intWriter = new BinaryWriter(os); + BinaryReader intReader = new BinaryReader(stream); + BinaryWriter intWriter = new BinaryWriter(stream); try { int id = intReader.ReadInt32(); @@ -125,14 +125,13 @@ namespace Lucene.Net.Store throw new IOException("Client closed connection before communication started."); } - //LUCENE TO-DO NOt sure about this startingGun.Wait(); intWriter.Write(43); - os.Flush(); + stream.Flush(); while (true) { - int command = intReader.Read(); + int command = stream.ReadByte(); if (command < 0) { return; // closed @@ -170,8 +169,8 @@ namespace Lucene.Net.Store default: throw new Exception("Unrecognized command: " + command); } - intWriter.Write(command); - os.Flush(); + intWriter.Write((byte)command); + stream.Flush(); } } } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/425d5e71/src/Lucene.Net/Store/VerifyingLockFactory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/VerifyingLockFactory.cs b/src/Lucene.Net/Store/VerifyingLockFactory.cs index 731283f..188352b 100644 --- a/src/Lucene.Net/Store/VerifyingLockFactory.cs +++ b/src/Lucene.Net/Store/VerifyingLockFactory.cs @@ -35,8 +35,7 @@ namespace Lucene.Net.Store public class VerifyingLockFactory : LockFactory { internal readonly LockFactory lf; - internal readonly Stream @in; - internal readonly Stream @out; + internal readonly Stream stream; private class CheckedLock : Lock { @@ -52,9 +51,9 @@ namespace Lucene.Net.Store private void Verify(byte message) { - [email protected](message); - [email protected](); - int ret = [email protected](); + outerInstance.stream.WriteByte(message); + outerInstance.stream.Flush(); + int ret = outerInstance.stream.ReadByte(); if (ret < 0) { throw new InvalidOperationException("Lock server died because of locking error."); @@ -106,13 +105,11 @@ namespace Lucene.Net.Store /// Creates a new <see cref="VerifyingLockFactory"/> instance. /// </summary> /// <param name="lf"> the <see cref="LockFactory"/> that we are testing </param> - /// <param name="in"> the socket's input to <see cref="LockVerifyServer"/> </param> - /// <param name="out"> the socket's output to <see cref="LockVerifyServer"/> </param> - public VerifyingLockFactory(LockFactory lf, Stream @in, Stream @out) + /// <param name="stream"> the socket's stream input/output to <see cref="LockVerifyServer"/> </param> + public VerifyingLockFactory(LockFactory lf, Stream stream) { this.lf = lf; - this.@in = @in; - this.@out = @out; + this.stream = stream; } public override Lock MakeLock(string lockName)
