예제 #1
0
        public async Task Smoke(MemstateSettings settings)
        {
            const int NumRecords = 100;

            settings.LoggerFactory.AddProvider(new TestOutputLoggingProvider(_log));
            settings.StreamName = _randomStreamName;

            var builder = new EngineBuilder(settings);
            var engine  = builder.Build <List <string> >();

            foreach (var number in Enumerable.Range(1, NumRecords))
            {
                var command = new AddStringCommand(number.ToString());
                var count   = await engine.ExecuteAsync(command).ConfigureAwait(false);

                Assert.Equal(number, count);
            }

            await engine.DisposeAsync().ConfigureAwait(false);

            engine = builder.Build <List <string> >();
            var strings = await engine.ExecuteAsync(new GetStringsQuery()).ConfigureAwait(false);

            Assert.Equal(NumRecords, strings.Count);
            await engine.DisposeAsync().ConfigureAwait(false);
        }
예제 #2
0
        public async Task Smoke(Config config)
        {
            const int NumRecords = 100;

            Config.Current = config;
            Console.WriteLine(config);

            var engine = await Engine.Start <List <string> >().ConfigureAwait(false);

            foreach (var number in Enumerable.Range(1, NumRecords))
            {
                var command = new AddStringCommand(number.ToString());
                var count   = await engine.Execute(command).ConfigureAwait(false);

                Assert.AreEqual(number, count);
            }

            await engine.DisposeAsync().ConfigureAwait(false);

            engine = await Engine.Start <List <string> >().ConfigureAwait(false);

            var strings = await engine.Execute(new GetStringsQuery()).ConfigureAwait(false);

            Assert.AreEqual(NumRecords, strings.Count);
            await engine.DisposeAsync().ConfigureAwait(false);
        }
예제 #3
0
        public async Task CanWriteManyAndReadFromMany(Config config)
        {
            const int records = 100;

            Config.Current = config;


            var readers = new Engine <List <string> > [3];

            readers[0] = await Engine.Start <List <string> >().ConfigureAwait(false);

            readers[1] = await Engine.Start <List <string> >().ConfigureAwait(false);

            readers[2] = await Engine.Start <List <string> >().ConfigureAwait(false);

            var writers = new Engine <List <string> > [3];

            writers[0] = await Engine.Start <List <string> >().ConfigureAwait(false);

            writers[1] = await Engine.Start <List <string> >().ConfigureAwait(false);

            writers[2] = await Engine.Start <List <string> >().ConfigureAwait(false);

            var totalCount = 0;

            foreach (var writer in writers)
            {
                foreach (var number in Enumerable.Range(1, records))
                {
                    var command = new AddStringCommand($"{number}");
                    var count   = await writer.Execute(command).ConfigureAwait(false);

                    Assert.AreEqual(++totalCount, count);
                }

                await writer.DisposeAsync().ConfigureAwait(false);
            }

            for (var i = 0; i < readers.Length; i++)
            {
                var reader = readers[i];
                Console.WriteLine("Reader index: " + i);

                //await reader.EnsureVersion(totalCount);
                var strings = await reader.Execute(new GetStringsQuery()).ConfigureAwait(false);

                Assert.AreEqual(totalCount, strings.Count);

                await reader.DisposeAsync().ConfigureAwait(false);
            }
        }
예제 #4
0
        public async Task CanWriteManyAndReadFromMany(MemstateSettings settings)
        {
            const int records = 100;

            Configure(settings);


            var readers = new Engine <List <string> > [3];

            readers[0] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            readers[1] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            readers[2] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            var writers = new Engine <List <string> > [3];

            writers[0] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            writers[1] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            writers[2] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            var totalCount = 0;

            foreach (var writer in writers)
            {
                foreach (var number in Enumerable.Range(1, records))
                {
                    var command = new AddStringCommand($"{number}");
                    var count   = await writer.ExecuteAsync(command).ConfigureAwait(false);

                    Assert.Equal(++totalCount, count);
                }

                await writer.DisposeAsync().ConfigureAwait(false);
            }

            foreach (var reader in readers)
            {
                var strings = await reader.ExecuteAsync(new GetStringsQuery()).ConfigureAwait(false);

                Assert.Equal(records * writers.Length, strings.Count);

                await reader.DisposeAsync().ConfigureAwait(false);
            }
        }
예제 #5
0
        public async Task CanWriteOneAndReadFromMany(MemstateSettings settings)
        {
            const int records = 100;

            Configure(settings);

            var writer = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            var readers = new Engine <List <string> > [3];

            readers[0] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            readers[1] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            readers[2] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            foreach (var number in Enumerable.Range(1, records))
            {
                var command = new AddStringCommand($"{number}");
                var count   = await writer.ExecuteAsync(command).ConfigureAwait(false);

                Assert.Equal(number, count);
            }

            await writer.DisposeAsync().ConfigureAwait(false);

            foreach (var reader in readers)
            {
                await reader.EnsureVersionAsync(writer.LastRecordNumber);

                var strings = await reader.ExecuteAsync(new GetStringsQuery()).ConfigureAwait(false);

                Assert.Equal(records, strings.Count);

                await reader.DisposeAsync().ConfigureAwait(false);
            }
        }
예제 #6
0
        public async Task CanWriteManyAndReadFromManyInParallel(MemstateSettings settings)
        {
            const int Records = 100;

            Configure(settings);

            _log.WriteLine("Creating readers");
            var readers = new Engine <List <string> > [3];

            readers[0] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            readers[1] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            readers[2] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            _log.WriteLine("Readers created");

            _log.WriteLine("Creating writers");
            var writers = new Engine <List <string> > [3];

            writers[0] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            writers[1] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            writers[2] = await Engine.StartAsync <List <string> >(settings).ConfigureAwait(false);

            _log.WriteLine("Writers created");

            _log.WriteLine("Creating write tasks");
            var tasks = writers.Select(
                (writer, index) => Task.Run(
                    async() =>
            {
                _log.WriteLine($"Writing commands on writer-{index + 1}");
                foreach (var number in Enumerable.Range(1, Records))
                {
                    var command = new AddStringCommand($"{index}.{number}");
                    await writer.ExecuteAsync(command).ConfigureAwait(false);
                }

                //await writer.DisposeAsync().ConfigureAwait(false);
                _log.WriteLine($"Done writing commands on writer-{index + 1}");
            })).ToArray();

            _log.WriteLine("Waiting on write tasks");
            await Task.WhenAll(tasks).ConfigureAwait(false);

            var recordsWritten = Records * writers.Length;

            _log.WriteLine("Done waiting on write tasks");

            _log.WriteLine("Reading from all engines");
            var engines = readers.Concat(writers);

            foreach (var engine in engines)
            {
                _log.WriteLine("Counting strings");
                await engine.EnsureAsync(recordsWritten - 1).ConfigureAwait(false);

                var strings = await engine.ExecuteAsync(new GetStringsQuery()).ConfigureAwait(false);

                _log.WriteLine($"Count: {strings.Count}");

                Assert.Equal(recordsWritten, strings.Count);

                _log.WriteLine("Disposing reader");
                await engine.DisposeAsync().ConfigureAwait(false);

                _log.WriteLine("Disposed reader");
            }
            _log.WriteLine("Done reading from all engines");
        }