SendCachedEventsAsync() public method

Submit all events found in the event cache. If an events are rejected by the server, KeenCacheException will be thrown with a listing of the rejected events, each with the error message it received.
public SendCachedEventsAsync ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
Exemplo n.º 1
0
        public async Task Async_Caching_SendInvalidEvents_Throws()
        {
            var client = new KeenClient(settingsEnv, new EventCacheMemory());
            if (UseMocks)
                client.Event = new EventMock(settingsEnv,
                    AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
                    {
                        var err = e.SelectToken("$.AddEventTest[2]") as JObject;
                        if (null == err)
                            throw new Exception("Unexpected error, test data not found");

                        return new List<CachedEvent>() { new CachedEvent("AddEventTest", e) };
                    }));

            object invalidEvent = new ExpandoObject();
            ((IDictionary<string, object>)invalidEvent).Add("$" + new string('.', 260), "AValue");

            var events = (from i in Enumerable.Range(1, 2)
                          select new { AProperty = "AValue" + i }).ToList<object>();
            events.Add(invalidEvent);

            await client.AddEventsAsync("AddEventTest", events);
            await client.SendCachedEventsAsync();
        }
Exemplo n.º 2
0
        public async Task CachingPCL_SendEventsParallel_Success(IEventCache cache)
        {
            await cache.Clear();
            var client = new KeenClient(SettingsEnv, cache);
            if (UseMocks)
                client.Event = new EventMock(SettingsEnv,
                    addEvents: (e, p) => new List<CachedEvent>());

            (from i in Enumerable.Range(1,100)
            select new { AProperty = "AValue" })
            .AsParallel()
            .ForAll(e=>client.AddEvent("CachedEventTest", e));

            await client.SendCachedEventsAsync();
            Assert.Null(await client.EventCache.TryTake(), "Cache is empty");
        }
Exemplo n.º 3
0
        public async Task Async_Caching_SendEvents_Success()
        {
            var client = new KeenClient(settingsEnv, new EventCacheMemory());
            if (UseMocks)
                client.Event = new EventMock(settingsEnv,
                    AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
                    {
                        Assert.AreEqual(p, settingsEnv, "Unexpected settings object");
                        Assert.AreEqual(e.Property("CachedEventTest").Value.AsEnumerable().Count(), 3, "Expected exactly 3 collection members");
                        return new List<CachedEvent>();
                    }));

            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });

            await client.SendCachedEventsAsync();
            Assert.Null(await client.EventCache.TryTake(), "Cache should be empty");
        }
Exemplo n.º 4
0
        public async void CachingPCL_SendEventsParallel_Success(IEventCache cache)
        {
            await cache.Clear();
            var client = new KeenClient(settingsEnv, cache);
            if (UseMocks)
                client.Event = new EventMock(settingsEnv,
                    AddEvents: new Func<JObject, IProjectSettings, IEnumerable<CachedEvent>>((e, p) =>
                    {
                        return new List<CachedEvent>();
                    }));

            (from i in Enumerable.Range(1,100)
            select new { AProperty = "AValue" })
            .AsParallel()
            .ForAll((e)=>client.AddEvent("CachedEventTest", e));

            await client.SendCachedEventsAsync();
            Assert.Null(await client.EventCache.TryTake(), "Cache is empty");
        }