示例#1
0
        public void MemoryManagerReusesFreeSpaceOnExactMatch()
        {
            var name = GetUniqueName();

            OutboundChannel outboundChannel = null;

            InboundChannel inboundChannel = null;

            try
            {
                var outboundChannelResult = Channel.CreateOutboundLocal(name);

                outboundChannel = outboundChannelResult.Data;

                InconclusiveWhenNotCompleted(outboundChannelResult);

                var data = new byte[5];

                // Write two nodes

                var writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(outboundChannelResult);

                writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(writingResult);

                var previousAllocatedSpace = writingResult.Data.AllocatedSpace;

                var inboundChannelResult = Channel.OpenInboundLocalNoncontainerized(name);

                inboundChannel = inboundChannelResult.Data;

                InconclusiveWhenNotCompleted(inboundChannelResult);

                // Remove node #1

                var readingResult = inboundChannel.Read((stream) => { });

                InconclusiveWhenNotCompleted(readingResult);

                // Write node #3 in place of #1

                writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(writingResult);

                var allocatedSpace = writingResult.Data.AllocatedSpace;

                Assert.AreEqual(previousAllocatedSpace, allocatedSpace);
            }
            finally
            {
                inboundChannel?.Dispose();

                outboundChannel?.Dispose();
            }
        }
示例#2
0
        public void OutboundChannelCanWriteSynchronously()
        {
            OutboundChannel channel = null;

            try
            {
                var channelResult = Channel.CreateOutboundLocal(GetUniqueName());

                channel = channelResult.Data;

                InconclusiveWhenNotCompleted(channelResult);

                var data = new byte[11];

                var writingResult = channel.Write((stream) =>
                {
                    stream.Write(data, 0, data.Length);

                    return(OperationStatus.Completed);
                },
                                                  data.Length);

                Assert.AreEqual(OperationStatus.Completed, writingResult.Status);

                Assert.AreEqual(1, writingResult.Data.MessagesCount, "Message counter should increase after writing");
            }
            finally
            {
                channel?.Dispose();
            }
        }
示例#3
0
        public async Task InboundChannelCanReadAsynchronously()
        {
            var name = GetUniqueName();

            OutboundChannel outboundChannel = null;

            InboundChannel inboundChannel = null;

            try
            {
                var outboundChannelResult = Channel.CreateOutboundLocal(name);

                outboundChannel = outboundChannelResult.Data;

                InconclusiveWhenNotCompleted(outboundChannelResult);

                var data = new byte[5] {
                    1, 2, 3, 4, 5
                };

                var writingResult = outboundChannel.Write((stream) =>
                {
                    stream.Write(data, 0, data.Length);

                    return(OperationStatus.Completed);
                },
                                                          data.Length);

                InconclusiveWhenNotCompleted(writingResult);

                var inboundChannelResult = Channel.OpenInboundLocalNoncontainerized(name);

                inboundChannel = inboundChannelResult.Data;

                InconclusiveWhenNotCompleted(inboundChannelResult);

                var buffer = new byte[data.Length];

                var readingResult = await inboundChannel.ReadAsync(async (stream) =>
                {
                    await stream.ReadAsync(buffer, 0, data.Length);

                    return(OperationStatus.Completed);
                });

                CollectionAssert.AreEqual(data, buffer);

                Assert.AreEqual(0, readingResult.Data.MessagesCount, "Message counter should decrease after reading");
            }
            finally
            {
                inboundChannel?.Dispose();

                outboundChannel?.Dispose();
            }
        }
示例#4
0
        public void MemoryManagerReusesFreeSpaceWhenAllocationRequired()
        {
            var name = GetUniqueName();

            OutboundChannel outboundChannel = null;

            InboundChannel inboundChannel = null;

            const int messageSize = 5;

            try
            {
                var outboundChannelResult = Channel.CreateOutboundLocal(name);

                outboundChannel = outboundChannelResult.Data;

                InconclusiveWhenNotCompleted(outboundChannelResult);

                var data = new byte[messageSize];

                // Write two nodes

                var writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(outboundChannelResult);

                writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(writingResult);

                var inboundChannelResult = Channel.OpenInboundLocalNoncontainerized(name);

                inboundChannel = inboundChannelResult.Data;

                InconclusiveWhenNotCompleted(inboundChannelResult);

                // Remove one node ...

                var readingResult = inboundChannel.Read((stream) => { });

                InconclusiveWhenNotCompleted(readingResult);

                // ... to write node #3 in place of first node

                writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(writingResult);

                // Remove node #2

                readingResult = inboundChannel.Read((stream) => { });

                InconclusiveWhenNotCompleted(readingResult);

                // To force MM write next large node #4 in place of #2

                var previousAllocatedSpace = readingResult.Data.AllocatedSpace;

                var largeData = new byte[messageSize + 1];

                writingResult = outboundChannel.Write((stream) => { stream.Write(largeData, 0, largeData.Length); }, largeData.Length);

                InconclusiveWhenNotCompleted(writingResult);

                var allocatedSpace = writingResult.Data.AllocatedSpace;

                // It is one byte larger than #2, so MM should allocate one additional byte after free node

                Assert.AreEqual(previousAllocatedSpace + 1, allocatedSpace);
            }
            finally
            {
                inboundChannel?.Dispose();

                outboundChannel?.Dispose();
            }
        }
示例#5
0
        public void MemoryManagerReusesFreeSpaceWhenItCanSplitFreeNode()
        {
            var name = GetUniqueName();

            OutboundChannel outboundChannel = null;

            InboundChannel inboundChannel = null;

            var sizeOfNode = Marshal.SizeOf <Node>();

            try
            {
                var outboundChannelResult = Channel.CreateOutboundLocal(name);

                outboundChannel = outboundChannelResult.Data;

                InconclusiveWhenNotCompleted(outboundChannelResult);

                var data = new byte[sizeOfNode];

                // Write two nodes having data with length >= size of node's header

                var writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                InconclusiveWhenNotCompleted(outboundChannelResult);

                writingResult = outboundChannel.Write((stream) => { stream.Write(data, 0, data.Length); }, data.Length);

                var previousAllocatedSpace = writingResult.Data.AllocatedSpace;

                InconclusiveWhenNotCompleted(writingResult);

                var inboundChannelResult = Channel.OpenInboundLocalNoncontainerized(name);

                inboundChannel = inboundChannelResult.Data;

                InconclusiveWhenNotCompleted(inboundChannelResult);

                // Remove one

                var readingResult = inboundChannel.Read((stream) => { });

                InconclusiveWhenNotCompleted(readingResult);

                // Write third empty node

                writingResult = outboundChannel.Write((stream) => { stream.Write(new byte[0], 0, 0); }, data.Length);

                InconclusiveWhenNotCompleted(writingResult);

                // MM should split free node into active node and new free list node

                var allocatedSpace = writingResult.Data.AllocatedSpace;

                Assert.AreEqual(previousAllocatedSpace, allocatedSpace);
            }
            finally
            {
                inboundChannel?.Dispose();

                outboundChannel?.Dispose();
            }
        }