public ServiceDbConfigManagerTests()
        {
            _signatureGenerator = Substitute.For <IServiceConfigSignatureGenerator>();
            _documentClient     = Substitute.For <IDocumentClient>();

            _configSourceA = CreateConfigSource("StoreA");
        }
示例#2
0
        /// <inheritdoc />
        public void RegisterStoreConfigSource(IDocumentStoreConfigSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            RegisterSource(source);
        }
示例#3
0
        /// <inheritdoc />
        public bool IsStoreConfigRegistered(IDocumentStoreConfigSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            lock (_sync)
            {
                return(_configSources.ContainsValue(source));
            }
        }
        private void RegisterSource(IDocumentStoreConfigSource source)
        {
            // Multiple threads may attempt to register config sources. Access to the config sources is
            // synchronised to ensure thread safety.

            var storeName = source.GetConfig().StoreName;

            lock (_sync)
            {
                if (!_configSources.ContainsKey(storeName))
                {
                    // There is no store registered with the given name. Add the new source and mark a service update as
                    // being required on the next service config check.
                    _configSources.Add(storeName, source);
                    _serviceUpdateRequired = true;
                }
            }
        }
示例#5
0
        protected VersionedDocumentStore(IDocumentDbAccess dbAccess, IDocumentStoreConfigSource existingSource)
        {
            if (dbAccess == null)
            {
                throw new ArgumentNullException(nameof(dbAccess));
            }
            if (existingSource == null)
            {
                throw new ArgumentNullException(nameof(existingSource));
            }

            DbAccess = dbAccess;

            if (!dbAccess.ConfigRegistry.IsStoreConfigRegistered(existingSource))
            {
                throw new ArgumentException("Store config has not been registed");
            }
        }
示例#6
0
        private void RegisterSource(IDocumentStoreConfigSource source)
        {
            // This processing must be synchronised to ensure that service updates are kept consistent with the
            // registration of new sources. The locking flow is simplified by ensuring that a service update
            // cannot happen at the same time as a source being registered. That has a trade off of efficiency
            // because callers may be blocked at registration while waiting for a service update on another thread.

            var storeName = source.GetConfig().StoreName;

            lock (_sync)
            {
                if (!_configSources.ContainsKey(storeName))
                {
                    // There is no store registered with the given name. Add the new source and mark a service update as
                    // being required on the next service config check.
                    _configSources.Add(storeName, source);
                    _serviceUpdateRequired = true;
                }
            }
        }