Exemple #1
0
        public static async Task PersistentPartitionOverflow()
        {
            var options = new PersistentChannelOptions
            {
                SingleReader      = true,
                SingleWriter      = true,
                PartitionCapacity = 3
            };
            Guid g1 = Guid.NewGuid(), g2 = Guid.NewGuid(), g3 = Guid.NewGuid(), g4 = Guid.NewGuid();

            using (var channel = new SerializationChannel <Guid>(options))
            {
                await channel.Writer.WriteAsync(g1);

                await channel.Writer.WriteAsync(g2);

                await channel.Writer.WriteAsync(g3);

                await channel.Writer.WriteAsync(g4);

                Equal(0D, channel.Throughput);
                Equal(g1, await channel.Reader.ReadAsync());
                Equal(0.25D, channel.Throughput);
            }
            using (var channel = new SerializationChannel <Guid>(options))
            {
                Equal(0.25D, channel.Throughput);
                Equal(g2, await channel.Reader.ReadAsync());
                Equal(0.5D, channel.Throughput);
                Equal(g3, await channel.Reader.ReadAsync());
                Equal(0.75D, channel.Throughput);
                Equal(g4, await channel.Reader.ReadAsync());
                Equal(1D, channel.Throughput);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new persistent channel with the specified options.
        /// </summary>
        /// <param name="options">The options of the channel.</param>
        protected PersistentChannel(PersistentChannelOptions options)
        {
            maxCount   = options.PartitionCapacity;
            bufferSize = options.BufferSize;
            location   = new DirectoryInfo(options.Location);
            if (!location.Exists)
            {
                location.Create();
            }
            var writer = new PersistentChannelWriter <TInput>(this, options.SingleWriter, options.InitialPartitionSize);
            var reader = new PersistentChannelReader <TOutput>(this, options.SingleReader);

            Reader      = reader;
            Writer      = writer;
            readTrigger = new AsyncCounter(writer.Position - reader.Position);
        }
        public static async Task Persistence()
        {
            Guid g1 = Guid.NewGuid(), g2 = Guid.NewGuid(), g3 = Guid.NewGuid();
            var  options = new PersistentChannelOptions {
                BufferSize = 1024
            };

            using (var channel = new SerializationChannel <Guid>(options))
            {
                await channel.Writer.WriteAsync(g1);

                await channel.Writer.WriteAsync(g2);

                await channel.Writer.WriteAsync(g3);

                Equal(g1, await channel.Reader.ReadAsync());
            }
            using (var channel = new SerializationChannel <Guid>(options))
            {
                Equal(g2, await channel.Reader.ReadAsync());
                Equal(g3, await channel.Reader.ReadAsync());
            }
        }
Exemple #4
0
 internal SerializationChannel(PersistentChannelOptions options)
     : base(options)
 {
 }
 internal SerializationChannel(PersistentChannelOptions options)
     : base(options)
 {
     formatter = new BinaryFormatter();
 }