Example #1
0
        public void SetUp()
        {
            _cachedItem = new TDataMock();
            _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<TDataMock, int>("", _lookupKey);

            _cacheTimeout = RMM.GenerateStrictMock<ICacheTimeout>();

            _contextCacheMock = RMM.GenerateStrictMock<IContextCache>();
            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();

            _configurationMock = RMM.GenerateStub<IBlendedCacheConfiguration>();
            RME.Stub(_configurationMock, x => x.GetCacheTimeoutForTypeOrDefault(_cachedItem.GetType())).Return(_cacheTimeout);

            _setterMock = RMM.GenerateStrictMock<ICacheSetter>();
            RME.Stub(_setterMock, x => x.Set<TDataMock>(null, null, null, SetCacheLocation.NotSet, null, null, null)).IgnoreArguments()
                .Do(new Action<string, TDataMock, ICacheTimeout, SetCacheLocation, IContextCache, IVolatileCache, ILongTermCache>(
                    (passedCacheKey, passedCachedItem, passedTimeout, passedLocation, passedContext, passedVolatile, passedLongTerm) =>
                    {
                        _passedCacheKey = passedCacheKey;
                        _passedCachedItem = passedCachedItem;
                        _passedCacheTimeout = passedTimeout;
                        _passedCacheLocation = passedLocation;
                        _passedContextCache = passedContext;
                        _passedVolatileCache = passedVolatile;
                        _passedLongTermCache = passedLongTerm;
                    }));
        }
        public void SetUp()
        {
            _response = null;
            _lookupKey = "my lookupKey";
            _fixedUpCacheKey = "cache key for: " + _lookupKey;
            _flushMode = null;

            _cacheTimeout = RMM.GenerateMock<ICacheTimeout>();
            _configurationMock = RMM.GenerateMock<IBlendedCacheConfiguration>();
            RME.Stub(_configurationMock, x => x.GetCacheTimeoutForTypeOrDefault(typeof(TDataMock))).Return(_cacheTimeout);

            _cacheItemMetrics = new CachedItemMetrics(_lookupKey, _fixedUpCacheKey);

            _cacheKeyConverterMock = RMM.GenerateStrictMock<ICacheKeyConverter>();
            RME.Stub(_cacheKeyConverterMock, x => x.ConvertCacheKey<TDataMock, string>(null, _lookupKey)).Do(new Func<string, string, string>((a, b) => _fixedUpCacheKey));

            _contextCachedObject = null;
            _contextCacheLookupMock = RMM.GenerateStrictMock<IContextCacheLookup>();
            RME.Stub(_contextCacheLookupMock, x => x.GetDataFromContextCache<TDataMock>(_fixedUpCacheKey)).Do(new Func<string, TDataMock>((a) => _contextCachedObject));

            _volatileCachedObject = null;
            _volatileCacheLookupMock = RMM.GenerateStrictMock<IVolatileCacheLookup>();
            RME.Stub(_volatileCacheLookupMock, x=>x.GetDataFromVolatileCache<TDataMock>(_fixedUpCacheKey, _cacheItemMetrics)).Do(new Func<string, CachedItemMetrics, TDataMock>((a, b) => _volatileCachedObject));

            _longTermCachedObject = null;
            _longTermCacheLookupMock = RMM.GenerateStrictMock<ILongTermCacheLookup>();
            RME.Stub(_longTermCacheLookupMock, x => x.GetDataFromLongTermCache<TDataMock>(_fixedUpCacheKey, _cacheItemMetrics)).Do(new Func<string, CachedItemMetrics, TDataMock>((a, b) => _longTermCachedObject));

            _cacheSetterMock = RMM.GenerateMock<ICacheSetter>();

            _contextCacheMock = RMM.GenerateMock<IContextCache>();
            _volatileCacheMock = RMM.GenerateMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateMock<ILongTermCache>();
        }
Example #3
0
        public void SetUp()
        {
            _passedVolatileCacheEntry = null;
            _passedVolatileCacheEntry = null;
            _passedLongTermCacheEntry = null;
            _passedLongTermCacheEntry = null;
            _location = SetCacheLocation.NotSet;
            _cacheKey = "my cacheKey";
            _cachedItem = new TDataMock();
            _cacheTimeout = new DefaultCacheTimeout();

            _contextCacheMock = RMM.GenerateStrictMock<IContextCache>();
            RME.Stub(_contextCacheMock, x => x.Set<TDataMock>(_cacheKey, _cachedItem));

            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            RME.Stub(_volatileCacheMock, x => x.Set<TDataMock>(_cacheKey, null)).IgnoreArguments().Do(new Action<string, IVolatileCacheEntry<TDataMock>>((cacheKey, cacheEntry) =>
                {
                    _passedVolatileCacheEntry = cacheEntry;
                    _passedVolatileCacheKey = cacheKey;
                }));

            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();
            RME.Stub(_longTermCacheMock, x => x.Set<TDataMock>(_cacheKey, null)).IgnoreArguments().Do(new Action<string, ILongTermCacheEntry<TDataMock>>((cacheKey, cacheEntry) =>
            {
                _passedLongTermCacheEntry = cacheEntry;
                _passedLongTermCacheKey = cacheKey;
            }));
        }
Example #4
0
 ListCursor(IContextCache contextCache, IReadOnlyList <T> elements, int index, T entity)
     : base(contextCache)
 {
     _elements  = elements;
     _index     = index;
     Current    = entity;
     HasCurrent = true;
 }
 public void SetUp()
 {
     _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<CachedData, string>("", _lookupKey);
     _contextCache = null;
     _response = null;
     _cachedItem = new CachedData();
     _previousMetrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics();
 }
            public static IContextCache GetPatternEntityNodes(IContextCache cache)
            {
                IEnumerable <ContextNode> result = from n in cache
                                                   where n.PatternEntity != null
                                                   select n;

                return(new CacheBase(result.ToList()));
            }
Example #7
0
 EntityResultCursor(IContextCache contextCache, EntityResult <TSchema> entityResult, int index, TSchema entity)
     : base(contextCache)
 {
     _entityResult = entityResult;
     _index        = index;
     Current       = entity;
     HasCurrent    = true;
 }
            public static IContextCache GetHandledContextNodes(IContextCache cache, bool handled)
            {
                IEnumerable <ContextNode> result =
                    from n in cache
                    where n.Handled == handled
                    select n;

                return(new CacheBase(result.ToList()));
            }
Example #9
0
        public EntityTranslateContext(IContextCache contextCache, EntityResult <TSchema> source, TInput input, bool hasInput, int?index = default(int?))
            : base(contextCache)
        {
            Source = source;

            HasInput = hasInput;
            Input    = input;
            Index    = index;
        }
Example #10
0
        private void InitializeCommand()
        {
            var rootRebuilder         = _provider.GetRequiredService <IAggregateRootRebuilder>();
            var loggerFactory         = _provider.GetRequiredService <ILoggerFactory>();
            var commandHandlerFactory = _provider.GetRequiredService <ICommandHandlerFactory>();
            var eventStore            = _provider.GetRequiredService <IEventStore>();
            var eventBus        = _provider.GetRequiredService <IEventBus>();
            var commandRegister = _provider.GetRequiredService <ICommandRegister>();

            IContextCache contextCache = _provider.GetRequiredService <IContextCache>();

            var size         = _options.CommandQueueSize;
            var waitStrategy = new SpinWaitWaitStrategy();

            var queue = RingBuffer <WrapMessage <CommandMessage> > .CreateMultiProducer(() => new WrapMessage <CommandMessage>(), size, waitStrategy);

            var barrier = queue.NewBarrier();

            var commandMappingProvider = _provider.GetService <ICommandMappingProvider>();

            if (commandMappingProvider != null)
            {
                var cacheHandler = new RingCommandCacheHandler(
                    commandMappingProvider
                    , rootRebuilder
                    , contextCache
                    , loggerFactory
                    , _options.CommandMaxHandleCount);


                var cacheConsumer = BatchEventProcessorFactory.Create <WrapMessage <CommandMessage> >(queue, barrier, cacheHandler);

                barrier = queue.NewBarrier(cacheConsumer.Sequence);
                consumers.Add(cacheConsumer);
            }


            var executorHandler = new RingCommandBusinessHandler(
                contextCache
                , commandHandlerFactory
                , eventStore
                , eventBus
                , commandRegister
                , rootRebuilder
                , loggerFactory
                , _options.CommandMaxHandleCount
                );

            var executorConsumer = BatchEventProcessorFactory.Create <WrapMessage <CommandMessage> >(queue, barrier, executorHandler);

            consumers.Add(executorConsumer);

            queue.AddGatingSequences(executorConsumer.Sequence);

            _commandQueue = queue;
        }
            public static IContextCache GetContextNodes(IContextCache cache,
                                                        ContextType contextType, InputType inputType)
            {
                IEnumerable <ContextNode> result =
                    from n in cache
                    where n.Key.ContextType == contextType && n.Key.InputType == inputType
                    select n;

                return(new CacheBase(result.ToList()));
            }
 public RingCommandCacheHandler(
     ICommandMappingProvider commandMappingProvider
     , IAggregateRootRebuilder aggregateRootRebuilder
     , IContextCache contextCache
     , ILoggerFactory loggerFactory
     , int maxHandleCount)
     : base(maxHandleCount)
 {
     this._aggregateRootRebuilder = aggregateRootRebuilder;
     this._contextCache           = contextCache;
     this._logger = loggerFactory.CreateLogger <RingCommandCacheHandler>();
     this._commandMappingProvider = commandMappingProvider;
 }
        public void SetUp()
        {
            _cachedItem = new CachedData();
            var existingCachedItem = new CachedData();

            _cacheKeyProvider = new DefaultCacheKeyConverter();
            _cacheKey = _cacheKeyProvider.ConvertCacheKey<CachedData, string>("", _lookupKey);
            _contextCache = new DictionaryContextCache(_cacheKey, existingCachedItem);
            _volatileCache = new DictionaryVolatileCache(_cacheKey, existingCachedItem);
            _longTermCache = new DictionaryLongTermCache(_cacheKey, existingCachedItem);

            _configuration = new BlendedCacheConfiguration();
        }
            public static IContextCache GetRecognitionPatternNodes(IContextCache cache, InputType inputType = InputType.Undefined)
            {
                IEnumerable <ContextNode> result =
                    from n in cache
                    where (n.TemplateType != Galatea.AI.Abstract.TemplateType.Null || n.NamedEntity != null || n.NamedTemplate != null)
                    select n;

                if (inputType != InputType.Undefined)
                {
                    result = from n in result
                             where n.Key.InputType == inputType
                             select n;
                }

                return(new CacheBase(result.ToList()));
            }
        public void SetUp()
        {
            _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<CachedData, string>("", _lookupKey);
            _response = null;
            _contextCachedItem = new CachedData();
            _volatileCachedItem = new CachedData();
            _longTermCachedItem = new CachedData();

            _contextCache_Empty = new DictionaryContextCache();
            _contextCache_Full = new DictionaryContextCache(_cacheKey, _contextCachedItem);

            _volatileCache_Empty = new DictionaryVolatileCache();
            _volatileCache_Full = new DictionaryVolatileCache(_cacheKey, _volatileCachedItem);

            _longTermCache_Empty = new DictionaryLongTermCache();
            _longTermCache_Full = new DictionaryLongTermCache(_cacheKey, _longTermCachedItem);
        }
Example #16
0
        /// <summary>
        /// Will get a blended cache under the default conditions.
        /// </summary>
        /// <returns></returns>
        public static BlendedCache GetCache(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null, IBlendedCacheConfiguration configuration = null, bool initialFlushMode = false)
        {
            if(contextCache == null)
                contextCache = new DictionaryContextCache();
            if(volatileCache == null)
                volatileCache = new DictionaryVolatileCache();
            if(longTermCache == null)
                longTermCache = new DictionaryLongTermCache();
            if(configuration == null)
                configuration = new BlendedCacheConfiguration();

            var cache = new BlendedCache(contextCache, volatileCache, longTermCache, configuration);

            if (initialFlushMode)
                cache.GetType().GetField("_flushMode", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(cache, true);

            return cache;
        }
 public RingCommandBusinessHandler(
     IContextCache contextCache
     , ICommandHandlerFactory commandHandlerFactory
     , IEventStore eventStore
     , IEventBus eventBus
     , ICommandRegister commandRegister
     , IAggregateRootRebuilder aggregateRootRebuilder
     , ILoggerFactory loggerFactory
     , int maxHandleCount)
     : base(maxHandleCount)
 {
     this.context                 = new RingCommandContext(contextCache, aggregateRootRebuilder);
     this._contextCache           = contextCache;
     this._commandHandlerFactory  = commandHandlerFactory;
     this._eventStore             = eventStore;
     this._eventBus               = eventBus;
     this._commandRegister        = commandRegister;
     this._aggregateRootRebuilder = aggregateRootRebuilder;
     this._logger                 = loggerFactory.CreateLogger <RingCommandBusinessHandler>();
 }
        private void Execute(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null)
        {
            var cache = TestHelpers.GetCache(contextCache, volatileCache, longTermCache, initialFlushMode: false);

            _response = cache.Get<CachedData>(_lookupKey);
        }
        private void Execute()
        {
            var volatileCache = new DictionaryVolatileCache(_cacheKey, _cachedItem);
            var cache = TestHelpers.GetCache(volatileCache: volatileCache);

            _contextCache = cache.GetContextCache();

            _response = cache.Get<CachedData>(_lookupKey);

            _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics();
        }
 public static ContextNode GetMostRecent(IContextCache cache)
 {
     return(cache.OrderBy(node => node.Key.Timestamp).FirstOrDefault());
 }
Example #21
0
 public BaseContext(IContextCache contextCache)
 {
     _contextCache = contextCache;
 }
Example #22
0
 public BaseContext(IReadOnlyContextCollection parent)
 {
     _contextCache = new ContextCache(parent);
 }
 public static ContextNode GetItem(IContextCache cache, ContextKey key)
 {
     return(cache.ToDictionary(node => node.Key)[key]);
 }
Example #24
0
 public BaseContext(IContext parent)
 {
     _contextCache = new ContextCache(parent.CurrentContext);
 }
Example #25
0
 public RingCommandContext(IContextCache contextCache, IAggregateRootRebuilder aggregateRootRebuilder)
 {
     this._contextCache           = contextCache;
     this._aggregateRootRebuilder = aggregateRootRebuilder;
 }
        private void Execute()
        {
            var longTermCache = new DictionaryLongTermCache(_cacheKey, _cachedItem);
            var cache = TestHelpers.GetCache(longTermCache: longTermCache);

            _contextCache = cache.GetContextCache();
            _volatileCache = cache.GetVolatileCache();

            _response = cache.Get<CachedData, Guid>(_lookupKey);

            _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, Guid>(_lookupKey) ?? new Metrics();
        }
Example #27
0
        public void when_CacheLocation_is_NotSet_should_not_call_anything()
        {
            _contextCacheMock = RMM.GenerateStrictMock<IContextCache>();
            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();

            _location = SetCacheLocation.NotSet;

            Execute();

            //the fact it doesn't thrown an exception means it wasn't called.
        }
        public void when_set_should_set_ContextCache()
        {
            _contextCache = new DictionaryContextCache(); // remove the item

            Execute();

            Assert.AreEqual(_cachedItem, _contextCache.Get<CachedData>(_cacheKey));
        }
        private void Execute(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null)
        {
            var cache = TestHelpers.GetCache(_contextCache_Full);

            _response = cache.Get<CachedData>(_lookupKey);
            _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics();
        }