public void AddDenyTest3()
        {
            var cache = new FastConcurrentLruCache <string, BadTestClass>(
                TestCacheCapacity,
                value => value.Identifier);

            _ = Assert.Throws <ArgumentNullException>(() => cache.Add(new BadTestClass()));
        }
        // Constructors

        internal Domain(DomainConfiguration configuration, object upgradeContextCookie, SqlConnection singleConnection)
        {
            Configuration                = configuration;
            Handlers                     = new HandlerAccessor(this);
            GenericKeyFactories          = new ConcurrentDictionary <TypeInfo, GenericKeyFactory>();
            EntityDataReader             = new EntityDataReader(this);
            KeyGenerators                = new KeyGeneratorRegistry();
            PrefetchFieldDescriptorCache = new ConcurrentDictionary <TypeInfo, ReadOnlyList <PrefetchFieldDescriptor> >();
            KeyCache                     = new LruCache <Key, Key>(Configuration.KeyCacheSize, k => k);
            QueryCache                   = new FastConcurrentLruCache <object, Pair <object, ParameterizedQuery> >(Configuration.QueryCacheSize, k => k.First);
            PrefetchActionMap            = new Dictionary <TypeInfo, Action <SessionHandler, IEnumerable <Key> > >();
            Extensions                   = new ExtensionCollection();
            UpgradeContextCookie         = upgradeContextCookie;
            SingleConnection             = singleConnection;
            StorageNodeManager           = new StorageNodeManager(Handlers);
            isDebugEventLoggingEnabled   = OrmLog.IsLogged(LogLevel.Debug); // Just to cache this value
        }
        public void SynchronizationTest()
        {
            globalCache =
                new FastConcurrentLruCache <string, TestClass>(
                    1000,
                    value => value.Text);

            using (new ThreadPoolThreadsIncreaser(20, 20)) {
                var addThreads              = new Task[10];
                var removeThreads           = new Task[10];
                var cancellationTokenSource = new CancellationTokenSource();

                for (var i = 0; i < 10; i++)
                {
                    addThreads[i]    = new Task(() => AddItem(cancellationTokenSource.Token), cancellationTokenSource.Token);
                    removeThreads[i] = new Task(() => RemoveItem(cancellationTokenSource.Token), cancellationTokenSource.Token);
                }

                try {
                    for (var i = 0; i < 10; i++)
                    {
                        addThreads[i].Start();
                    }
                    Thread.Sleep(10);

                    for (var i = 0; i < 10; i++)
                    {
                        removeThreads[i].Start();
                    }
                    Thread.Sleep(200);
                }
                finally {
                    cancellationTokenSource.Cancel();
                    Thread.Sleep(20);
                }
            }

            Assert.IsTrue(globalCache.Count >= 0);
            globalCache = null;
        }