public void TwoSimultaneiousWritesReadsInSameOrder()
        {
            var b1 = new RedisInlineCommandBuilder();
            var b2 = new RedisInlineCommandBuilder();
            b1.SetCommand(":1");
            b2.SetCommand(":2");

            var loopbackConnection = new LoopbackConnection();
            loopbackConnection.WriteResponce();
            var executor = new PipelinedCommandExecutor(loopbackConnection);

            int result = 0;

            var t1 = new Thread(() => result = BitConverter.ToInt32(executor.ExecuteCommand(b1).First(), 0));
            var t2 = new Thread(() => executor.ExecuteCommand(b2));

            t1.Start();
            t2.Start();

            t1.Join();
            t2.Join();

            executor.Dispose();

            Assert.That(result, Is.EqualTo(1));
        }
Ejemplo n.º 2
0
        public void IfResponseIsBlockedThenNextCommandWillWrite()
        {
            var b1 = new RedisInlineCommandBuilder();
            var b2 = new RedisInlineCommandBuilder();

            b1.SetCommand(":1");
            b2.SetCommand(":2");

            var loopbackConnection = new LoopbackConnection();
            var executor           = new PipelinedCommandExecutor(loopbackConnection);

            var t1 = new Thread(() => executor.ExecuteCommand(b1));
            var t2 = new Thread(() => executor.ExecuteCommand(b2));

            t1.Start();
            t2.Start();

            Thread.Sleep(100);
            var str = Encoding.ASCII.GetString(loopbackConnection.GetBuffer());

            loopbackConnection.WriteResponce();

            t1.Join();
            t2.Join();

            executor.Dispose();

            Assert.That(str, Is.EqualTo(":1\r\n:2\r\n"));
        }
        public void IfResponseIsBlockedThenNextCommandWillWrite()
        {
            var b1 = new RedisInlineCommandBuilder();
            var b2 = new RedisInlineCommandBuilder();
            b1.SetCommand(":1");
            b2.SetCommand(":2");

            var loopbackConnection = new LoopbackConnection();
            var executor = new PipelinedCommandExecutor(loopbackConnection);

            var t1 = new Thread(() => executor.ExecuteCommand(b1));
            var t2 = new Thread(() => executor.ExecuteCommand(b2));

            t1.Start();
            t2.Start();

            Thread.Sleep(100);
            var str = Encoding.ASCII.GetString(loopbackConnection.GetBuffer());
            loopbackConnection.WriteResponce();

            t1.Join();
            t2.Join();

            executor.Dispose();

            Assert.That(str, Is.EqualTo(":1\r\n:2\r\n"));
        }
Ejemplo n.º 4
0
        public void TwoSimultaneiousWritesReadsInSameOrder()
        {
            var b1 = new RedisInlineCommandBuilder();
            var b2 = new RedisInlineCommandBuilder();

            b1.SetCommand(":1");
            b2.SetCommand(":2");

            var loopbackConnection = new LoopbackConnection();

            loopbackConnection.WriteResponce();
            var executor = new PipelinedCommandExecutor(loopbackConnection);

            int result = 0;

            var t1 = new Thread(() => result = BitConverter.ToInt32(executor.ExecuteCommand(b1).First(), 0));
            var t2 = new Thread(() => executor.ExecuteCommand(b2));

            t1.Start();
            t2.Start();

            t1.Join();
            t2.Join();

            executor.Dispose();

            Assert.That(result, Is.EqualTo(1));
        }