コード例 #1
0
        public void Publicize_2SameKeys_RaiseBufferPublicationException()
        {
            // arrange
            IEntity entityMock = this.mocks.NewMock<IEntity>();
            EntityPropertyStorage storage = new EntityPropertyStorage( entityMock );
            string key = "testData";
            object data = new object();
            int times = 2;

            // act
            for ( int i = times; i > 0; i-- )
            {
                storage.Publicize( key, data );
            }

            // assert
        }
コード例 #2
0
        public void SwapAndFlush_100ThenFlushThen30PublicationsFromSingleThreads_100ValuesToMainDataThen30Updates()
        {
            // arrange
            IEntity entityMock = this.mocks.NewMock<IEntity>();
            EntityPropertyStorage storage = new EntityPropertyStorage( entityMock );
            int times = 100;
            IList<Thread> threads = new List<Thread>();
            for ( int i = times; i > 0; i-- )
            {
                string key = "test_" + i;
                Thread t = new Thread( x => { Thread.Sleep( i * 16 ); storage.Publicize( key, new object() ); } );
                threads.Add( t );
                t.Start();
            }
            foreach ( Thread t in threads )
            {
                t.Join();
            }
            threads.Clear();
            Assert.AreEqual( times, storage.UnstableBufferStorage.Count );

            // act
            storage.SwapAndFlush();

            Assert.AreEqual( 0, storage.UnstableBufferStorage.Count );
            Assert.AreEqual( times, storage.MainDataStorage.Count );

            times = 30;
            for ( int i = times; i > 0; i-- )
            {
                if ( i == 15 )
                {
                    Thread swapT = new Thread
                    (
                        (object x) =>
                        {
                            Thread.Sleep( (int)x );
                            storage.SwapAndFlush();
                        }
                    );
                    threads.Add( swapT );
                    swapT.Start(i);
                }
                string key = "test_" + i;
                Thread t = new Thread( x => { Thread.Sleep( i * 56 ); storage.Publicize( key, new object() ); } );
                threads.Add( t );
                t.Start();
            }
            foreach ( Thread t in threads )
            {
                t.Join();
            }
            threads.Clear();
            Assert.AreEqual( times, storage.UnstableBufferStorage.Count + storage.StableBufferStorage.Count );

            storage.SwapAndFlush();

            // assert
            Assert.AreEqual( 0, storage.UnstableBufferStorage.Count );
            Assert.AreEqual( 100, storage.MainDataStorage.Count );
        }
コード例 #3
0
        public void Publicize_1000ValidKeyValidData_1000Stored()
        {
            // arrange
            IEntity entityMock = this.mocks.NewMock<IEntity>();
            EntityPropertyStorage storage = new EntityPropertyStorage( entityMock );
            int times = 1000;

            // act
            for(int i = 0; i < times; i++)
            {
                storage.Publicize( "test_" + i, new object() );
            }

            // assert
            Assert.AreEqual( times, storage.UnstableBufferStorage.Count );
        }