public void EventCache_RemoveEventsPerActor() { RoomEventCacheManager manager = new RoomEventCacheManager(); string msg; manager.AddEventToCurrentSlice(new CustomEvent(0, 0, null), out msg); manager.AddEventToCurrentSlice(new CustomEvent(1, 0, null), out msg); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); manager.RemoveEventsFromCache(new RaiseEventRequest { Actors = new [] { 3 }, }); Assert.That(manager.CachedEventsCount, Is.EqualTo(3)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 1, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 2, null), out msg)); Assert.That(manager.CachedEventsCount, Is.EqualTo(6)); manager.RemoveEventsFromCache(0, new int[] { 3 }, null); Assert.That(manager.CachedEventsCount, Is.EqualTo(4)); }
public void EventCache_ClearCache() { RoomEventCacheManager manager = new RoomEventCacheManager(); string msg; manager.AddEventToCurrentSlice(new CustomEvent(0, 0, null), out msg); manager.AddEventToCurrentSlice(new CustomEvent(1, 0, null), out msg); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.CachedEventsCount, Is.Not.Zero); manager.RemoveEventsFromCache(new RaiseEventRequest()); Assert.That(manager.CachedEventsCount, Is.Zero); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.CachedEventsCount, Is.Not.Zero); manager.RemoveEventsFromCache(0, null, null); Assert.That(manager.CachedEventsCount, Is.Zero); }
public void EventCacheCachedEventsTotalLimitTests() { RoomEventCacheManager manager = new RoomEventCacheManager(); const int SlicesCountLimit = 2; const int ChchedEventsCountLimit = 4; manager.SlicesCountLimit = SlicesCountLimit; manager.CachedEventsCountLimit = ChchedEventsCountLimit; string msg; manager.AddEventToCurrentSlice(new CustomEvent(0, 0, null), out msg); manager.AddEventToCurrentSlice(new CustomEvent(1, 0, null), out msg); ++manager.Slice; Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.IsTotalLimitExceeded, Is.True); manager.RemoveEventsByActor(2); Assert.That(manager.IsTotalLimitExceeded, Is.False); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 0, null), out msg)); Assert.That(manager.IsTotalLimitExceeded, Is.True); }
public void EventCache_RemoveEventsPerEventCodeAndActor() { RoomEventCacheManager manager = new RoomEventCacheManager(); string msg; manager.AddEventToCurrentSlice(new CustomEvent(0, 0, null), out msg); manager.AddEventToCurrentSlice(new CustomEvent(1, 0, null), out msg); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 0, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 1, null), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 2, null), out msg)); Assert.That(manager.CachedEventsCount, Is.EqualTo(5)); byte eventCode = 2; manager.RemoveEventsFromCache(eventCode, new int[] { 3 }, null); Assert.That(manager.CachedEventsCount, Is.EqualTo(4)); eventCode = 1; manager.RemoveEventsFromCache(eventCode, new int[] { 3 }, null); Assert.That(manager.CachedEventsCount, Is.EqualTo(3)); }
private static RoomEventCacheManager AddEventsToCacheManager() { RoomEventCacheManager manager = new RoomEventCacheManager(); string msg; manager.AddEventToCurrentSlice(new CustomEvent(0, 0, GetTestData(DataOptions.Frst)), out msg); manager.AddEventToCurrentSlice(new CustomEvent(1, 0, GetTestData(DataOptions.Frst)), out msg); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(2, 3, GetTestData(DataOptions.Scnd)), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 1, GetTestData(DataOptions.Frst)), out msg)); Assert.That(manager.AddEventToCurrentSlice(new CustomEvent(3, 2, null), out msg)); Assert.That(manager.CachedEventsCount, Is.EqualTo(5)); return(manager); }
public void EventCacheSliceLimitTests() { RoomEventCacheManager manager = new RoomEventCacheManager(); const int SlicesCountLimit = 2; const int ChchedEventsCountLimit = 4; manager.SlicesCountLimit = SlicesCountLimit; manager.CachedEventsCountLimit = ChchedEventsCountLimit; manager.AddSlice(0); manager.AddSlice(1); Assert.Throws <EventCacheException>(() => manager.AddSlice(3), "Slice limit is exceeded. Limit is 2"); manager.RemoveSlice(1); Assert.DoesNotThrow(() => manager.AddSlice(3)); }