public void Parse_Values_GB_Valid_825(uint size) { // act var sut = CacheSize.Parse($"{size}GB", Sc825); // assert Assert.Equal(size, sut.Value.GB); }
public void Parse_Values_MB_Invalid_825(uint size) { // act var sut = CacheSize.Parse($"{size}mb", Sc825); // assert Assert.Equal(0, sut.Value.MB); // kind weird, but that's what it is }
public void Parse_Text(uint size) { // arrange var text = $"{size}"; // act var sut = CacheSize.Parse(text, Sc825); // assert Assert.Equal(text, sut.Text); }
public void TestFailData() { var data = new Map { { "data", "20MB" }, { "items", "10MB" }, // {"paths", "500KB"}, // no itempaths to make it fallback to default cache size 100KB { "itempaths", "1MB" }, { "standardValues", "50KB" }, { "prefetch", "1MB" } }; new SolutionUnitTestContext() .AddInstance(new SitecoreInstance { Configuration = new XmlDocument() .Create(CacheSizesXPath) .Add(CacheSizesXPath, "data", data["data"]) .Add(CacheSizesXPath, "items", data["items"]) //.Add(CacheSizesXPath, "paths", data["paths"]) .Add(CacheSizesXPath, "itempaths", data["itempaths"]) .Add(CacheSizesXPath, "standardValues", data["standardValues"]) .Add(WebDatabaseXPath, PrefetchXPath, data["prefetch"]), Version = Sc711 }) .Process(this) .MustReturn(new TestOutput(TestResultState.Warning, new ShortMessage(new Text($"One or several Sitecore caches are not tuned up and use default settings which may lead to performance degradation:")), data: GetMessage(new Map <Map <CacheSizeDetails> > { { "web", new Map <CacheSizeDetails> { { "data", new CacheSizeDetails { Value = CacheSize.Parse(data["data"], Sc711), Comment = "which is default" } }, { "items", new CacheSizeDetails { Value = CacheSize.Parse(data["items"], Sc711), Comment = "which is default" } }, } } }))) .MustReturn(new TestOutput(TestResultState.Error, new ShortMessage(new Text($"One or several Sitecore caches are use custom configuration which is below the minimum recommended values (set up by default) which may lead to performance degradation:")), data: GetMessage(new Map <Map <CacheSizeDetails> > { { "web", new Map <CacheSizeDetails> { { "paths", new CacheSizeDetails { Value = CacheSize.Parse("100KB", Sc711), Comment = "cache size is not specified, uses Caching.DefaultPathCacheSize setting value as fallback" } }, { "standardValues", new CacheSizeDetails { Value = CacheSize.Parse(data["standardValues"], Sc711), Comment = $"which is below than default: {Size.FromKB(500)}" } }, { "itempaths", new CacheSizeDetails { Value = CacheSize.Parse(data["itempaths"], Sc711), Comment = $"which is below than default: {Size.FromMB(10)}" } }, { "prefetch", new CacheSizeDetails { Value = CacheSize.Parse(data["prefetch"], Sc711), Comment = $"which is below than default: {Size.FromMB(10)}" } } } } }))) .Done(); }
private void Process(ISitecoreInformationContext info, ITestOutputContext output, LogicalDatabaseDefinition database, LogicalDatabaseDefinition defaultDatabase, Map<Map<CacheSizeDetails>> defaultCachesPerDatabase, Map<Map<CacheSizeDetails>> belowDefaultCachesPerDatabase) { var databaseCaches = new Map<CacheSizeDetails>(); var belowDefaultCaches = new Map<CacheSizeDetails>(); var databaseName = database.Name; foreach (var cache in database.Caches.Values) { var cacheSize = cache.Size; var defaultSize = defaultDatabase.Caches[cache.Name].Size; if (defaultSize == null) { // custom cache, or filesystem database continue; } if (cacheSize == null) { var fallbackSettingCacheSize = CacheSize.Parse(info.GetSetting(cache.FallbackSettingName), info.SitecoreVersion); if (fallbackSettingCacheSize.Value.Bytes < defaultSize.Value.Bytes) { var cacheSizeDetails = new CacheSizeDetails { Value = fallbackSettingCacheSize, Comment = $"cache size is not specified, uses {cache.FallbackSettingName} setting value as fallback" }; belowDefaultCaches.Add(cache.Name, cacheSizeDetails); } } else { if (cacheSize.Value == defaultSize.Value) { var cacheSizeDetails = new CacheSizeDetails { Value = cacheSize, Comment = "cache size is default" }; databaseCaches.Add(cache.Name, cacheSizeDetails); } else if (cacheSize.Value < defaultSize.Value) { var cacheSizeDetails = new CacheSizeDetails { Value = cacheSize, Comment = $"cache size is below than default: {defaultSize.Value}" }; belowDefaultCaches.Add(cache.Name, cacheSizeDetails); } } } if (databaseCaches.Any()) { defaultCachesPerDatabase.Add(databaseName, databaseCaches); } if (belowDefaultCaches.Any()) { belowDefaultCachesPerDatabase.Add(databaseName, belowDefaultCaches); } }