Exemple #1
0
        public void TestThatExactStoresCreated()
        {
            var readers = 10;
            var writers = 7;
            var times   = readers + writers;

            var results = new MessageCountingResults(times);

            // must be exact
            var store = (PartitioningStateStore)PartitioningStateStore.Using(_world.Stage, typeof(MessageCountingStateStoreActor), readers, writers, results);

            for (var i = 0; i < store.ReadersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Reader);
            }
            for (var i = 0; i < store.WritersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Writer);
            }

            Assert.NotNull(store);
            Assert.Equal(times, results.GetCtor());
            Assert.Equal(readers, results.GetReaderCtor());
            Assert.Equal(writers, results.GetWriterCtor());
        }
Exemple #2
0
        public void TestThatMaximumStoresCreated()
        {
            var readers = int.MaxValue / 2;
            var writers = int.MaxValue / 10;
            var times   = PartitioningStateStore.MaximumReaders + PartitioningStateStore.MaximumWriters;

            var results = new MessageCountingResults(times);

            // 3, 2 must be minimum 5, 3 and must default to that below minimum given
            var store = (PartitioningStateStore)PartitioningStateStore.Using(_world.Stage, typeof(MessageCountingStateStoreActor), readers, writers, results);

            for (var i = 0; i < store.ReadersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Reader);
            }
            for (var i = 0; i < store.WritersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Writer);
            }
            Assert.NotNull(store);
            Assert.Equal(times, results.GetCtor());
            Assert.NotEqual(readers, results.GetReaderCtor());
            Assert.Equal(PartitioningStateStore.MaximumReaders, results.GetReaderCtor());
            Assert.NotEqual(writers, results.GetWriterCtor());
            Assert.Equal(PartitioningStateStore.MaximumWriters, results.GetWriterCtor());
        }
        public MessageCountingResults(int times)
        {
            _access = AccessSafely.AfterCompleting(times);

            _access.WritingWith("ctor", (InstantiationType type) =>
            {
                _ctor.IncrementAndGet();
                if (type == InstantiationType.Reader)
                {
                    _readerCtor.IncrementAndGet();
                }
                else if (type == InstantiationType.Writer)
                {
                    _writerCtor.IncrementAndGet();
                }
            });
            _access.ReadingWith("ctor", () => _ctor.Get());
            _access.ReadingWith("readerCtor", () => _readerCtor.Get());
            _access.ReadingWith("writerCtor", () => _writerCtor.Get());

            _access.WritingWith("read", (string id, int totalPartitions) =>
            {
                _read.IncrementAndGet();
                var partition = PartitioningStateStore.PartitionOf(id, totalPartitions);
                _readPartitions.TryGetValue(partition, out var count);
                _readPartitions.AddOrUpdate(partition, i => 1, (x, y) => count + 1);
            });
            _access.ReadingWith("read", () => _read.Get());

            _access.WritingWith <int>("readAll", one => _readAll.IncrementAndGet());
            _access.ReadingWith("readAll", () => _readAll.Get());

            _access.WritingWith <int>("streamAllOf", one => _streamAllOf.IncrementAndGet());
            _access.ReadingWith("streamAllOf", () => _streamAllOf.Get());

            _access.WritingWith <int>("streamSomeUsing", one => _streamSomeUsing.IncrementAndGet());
            _access.ReadingWith("streamSomeUsing", () => _streamSomeUsing.Get());

            _access.WritingWith("write", (string id, int totalPartitions) =>
            {
                _write.IncrementAndGet();
                var partition = PartitioningStateStore.PartitionOf(id, totalPartitions);
                _writePartitions.TryGetValue(partition, out var count);
                _writePartitions.AddOrUpdate(partition, i => 1, (x, y) => count + 1);
            });
            _access.ReadingWith("write", () => _write.Get());

            _access.WritingWith <int>("entryReader", one => _entryReader.IncrementAndGet());
            _access.ReadingWith("entryReader", () => _entryReader.Get());
        }
Exemple #4
0
        public void TestThatReadersReceive()
        {
            var ctors          = PartitioningStateStore.MinimumReaders + PartitioningStateStore.MinimumWriters;
            var interations    = 5;
            var partitionReads = 2;
            var reads          = interations * partitionReads;
            var readAlls       = 1;

            var times = ctors + reads + readAlls;

            var results = new MessageCountingResults(times);

            var store = (PartitioningStateStore)PartitioningStateStore.Using(_world.Stage, typeof(MessageCountingStateStoreActor), 0, 0, results);

            for (var i = 0; i < store.ReadersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Reader);
            }
            for (var i = 0; i < store.WritersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Writer);
            }

            Assert.NotNull(store);

            for (var read = 0; read < interations; ++read)
            {
                store.Read <TextEntry>(IdFor(read, PartitioningStateStore.MinimumReaders), null !, null);
                store.Read <TextEntry>(IdFor(read, PartitioningStateStore.MinimumReaders), null !, null);
            }

            store.ReadAll <TextEntry>(new [] { new TypedStateBundle("3", typeof(TextEntry)), new TypedStateBundle("4", typeof(TextEntry)) }, null !, null);

            Assert.Equal(ctors, results.GetCtor());
            Assert.Equal(PartitioningStateStore.MinimumReaders, results.GetReaderCtor());
            Assert.Equal(PartitioningStateStore.MinimumWriters, results.GetWriterCtor());

            Assert.Equal(reads, results.GetRead());
            Assert.Equal(readAlls, results.GetReadAll());

            Assert.Equal(partitionReads, results.GetReadPartitionCount(0));
            Assert.Equal(partitionReads, results.GetReadPartitionCount(1));
            Assert.Equal(partitionReads, results.GetReadPartitionCount(2));
            Assert.Equal(partitionReads, results.GetReadPartitionCount(3));
            Assert.Equal(partitionReads, results.GetReadPartitionCount(4));
        }
Exemple #5
0
        public void TestThatWritersReceive()
        {
            var iterations = 3;

            var ctors  = PartitioningStateStore.MinimumReaders + PartitioningStateStore.MinimumWriters;
            var writes = 3;

            var times = ctors + writes * iterations;

            var results = new MessageCountingResults(times);

            var store = (PartitioningStateStore)PartitioningStateStore.Using(_world.Stage, typeof(MessageCountingStateStoreActor), 0, 0, results);

            for (var i = 0; i < store.ReadersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Reader);
            }
            for (var i = 0; i < store.WritersCount; i++)
            {
                results.IncrementCtor(InstantiationType.Writer);
            }

            Assert.NotNull(store);

            for (var outer = 0; outer < iterations; ++outer)
            {
                for (var inner = 0; inner < writes; ++inner)
                {
                    store.Write(IdFor(inner, PartitioningStateStore.MinimumWriters), this, 1, null !);
                }
            }

            Assert.Equal(ctors, results.GetCtor());
            Assert.Equal(PartitioningStateStore.MinimumReaders, results.GetReaderCtor());
            Assert.Equal(PartitioningStateStore.MinimumWriters, results.GetWriterCtor());

            Assert.Equal(iterations * writes, results.GetWrite());

            Assert.Equal(writes, results.GetWritePartitionCount(0));
            Assert.Equal(writes, results.GetWritePartitionCount(1));
            Assert.Equal(writes, results.GetWritePartitionCount(2));
        }