Exemplo n.º 1
0
 public async Task AddEvent_AddNotEmpty_Success(IEventCache cache)
 {
     await cache.Clear();
     Assert.Null(await cache.TryTake());
     await cache.Add(new CachedEvent("url", JObject.FromObject( new { AProperty = "AValue" })));
     Assert.NotNull(await cache.TryTake());
 }
Exemplo n.º 2
0
        public void CachingPCL_AddEvents_Success(IEventCache cache)
        {
            var client = new KeenClient(SettingsEnv, cache);

            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
        }
Exemplo n.º 3
0
        public BrokerageService(IBrokerageServiceConfiguration configuration, IEventCache cache, ISerializer serializer)
        {
            _cache         = cache;
            _serializer    = serializer;
            _configuration = configuration;

            _cancel = new CancellationTokenSource();
        }
Exemplo n.º 4
0
        public async Task AddEvent_AddClearEmpty_Success(IEventCache cache)
        {
            await cache.Add(new CachedEvent("url", JObject.FromObject(new { AProperty = "AValue" })));

            await cache.Clear();

            Assert.Null(await cache.TryTake());
        }
Exemplo n.º 5
0
        public void CachingPCL_AddEvents_Success(IEventCache cache)
        {
            var client = new KeenClient(settingsEnv, cache);

            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
        }
Exemplo n.º 6
0
        public async Task AddEvent_AddNotEmpty_Success(IEventCache cache)
        {
            await cache.ClearAsync();

            Assert.Null(await cache.TryTakeAsync());
            await cache.AddAsync(new CachedEvent("url", JObject.FromObject(new { Property = "Value" })));

            Assert.NotNull(await cache.TryTakeAsync());
        }
        public BrokerageService(IBrokerageServiceConfiguration configuration, ILogger <BrokerageService> logger, IEventCache cache, ISerializer serializer) : base(logger)
        {
            _cache         = cache;
            _serializer    = serializer;
            _configuration = configuration;

            Errors = new ObservableCollection <ActorMonitoringError>();

            _cancel = new CancellationTokenSource();
        }
Exemplo n.º 8
0
        public async void AddEvent_Iterate_Success(IEventCache cache)
        {
            await cache.Clear();

            await cache.Add(new CachedEvent("url", JObject.FromObject(new { AProperty = "AValue" })));

            await cache.Add(new CachedEvent("url", JObject.FromObject(new { AProperty = "AValue" })));

            Assert.NotNull(await cache.TryTake());
            Assert.NotNull(await cache.TryTake());
            Assert.Null(await cache.TryTake());
        }
Exemplo n.º 9
0
        private KeenClient(IProjectSettings prjSettings,
                           IEventCache eventCache,
                           IKeenHttpClientProvider keenHttpClientProvider)
        {
            // Preconditions
            if (null == prjSettings)
            {
                throw new KeenException("An IProjectSettings instance is required.");
            }
            if (string.IsNullOrWhiteSpace(prjSettings.ProjectId))
            {
                throw new KeenException("A Project ID is required.");
            }
            if ((string.IsNullOrWhiteSpace(prjSettings.MasterKey) &&
                 string.IsNullOrWhiteSpace(prjSettings.WriteKey) &&
                 string.IsNullOrWhiteSpace(prjSettings.ReadKey)))
            {
                throw new KeenException("An API key is required.");
            }
            if (string.IsNullOrWhiteSpace(prjSettings.KeenUrl))
            {
                throw new KeenException("A URL for the server address is required.");
            }

            _prjSettings = prjSettings;

            if (null != eventCache)
            {
                EventCache = eventCache;
            }

            // Use the default provider if none was passed in.
            keenHttpClientProvider = (keenHttpClientProvider ?? new KeenHttpClientProvider());

            // These interfaces normally should not need to be set by client code, so the default
            // implementation is set up here. These may be overridden by injecting an
            // implementation via their respective properties.
            EventCollection = new EventCollection(_prjSettings, keenHttpClientProvider);
            Event           = new Event(_prjSettings, keenHttpClientProvider);
            Queries         = new Queries(_prjSettings, keenHttpClientProvider);
        }
Exemplo n.º 10
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.º 11
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");
        }
Exemplo n.º 12
0
 public async Task AddEvent_Null_Throws(IEventCache cache)
 {
     await cache.Add(null);
 }
Exemplo n.º 13
0
 public void AddEvent_Null_Throws(IEventCache cache)
 {
     Assert.ThrowsAsync <Keen.Core.KeenException>(() => cache.Add(null));
 }
Exemplo n.º 14
0
 public async Task AddEvent_ValidObject_Success(IEventCache cache)
 {
     await cache.Add(new CachedEvent("url", JObject.FromObject( new { AProperty = "AValue" })));
 }
Exemplo n.º 15
0
        public void CachingPCL_ClearEvents_Success(IEventCache cache)
        {
            var client = new KeenClient(settingsEnv, cache);

            Assert.DoesNotThrow(() => client.EventCache.Clear());
        }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="prjSettings">A ProjectSettings instance containing the ProjectId and API keys</param>
 /// <param name="eventCache">An IEventCache instance providing a caching strategy</param>
 public KeenClient(IProjectSettings prjSettings, IEventCache eventCache)
     : this(prjSettings, eventCache, null)
 {
 }
Exemplo n.º 17
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.º 18
0
 public async Task AddEvent_Null_Throws(IEventCache cache)
 {
     await cache.Add(null);
 }
Exemplo n.º 19
0
 public void CachingPCL_ClearEvents_Success(IEventCache cache)
 {
     var client = new KeenClient(SettingsEnv, cache);
     Assert.DoesNotThrow(() => client.EventCache.Clear());
 }
Exemplo n.º 20
0
 public void CachingPCL_SendEmptyEvents_Success(IEventCache cache)
 {
     var client = new KeenClient(SettingsEnv, cache);
     Assert.DoesNotThrow(client.SendCachedEvents);
 }
Exemplo n.º 21
0
 public async Task AddEvent_ValidObject_Success(IEventCache cache)
 {
     await cache.Add(new CachedEvent("url", JObject.FromObject(new { AProperty = "AValue" })));
 }
Exemplo n.º 22
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");
        }
Exemplo n.º 23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="prjSettings">A ProjectSettings instance containing the ProjectId and API keys</param>
 /// <param name="eventCache">An IEventCache instance providing a caching strategy</param>
 public KeenClient(IProjectSettings prjSettings, IEventCache eventCache)
     : this(prjSettings)
 {
     EventCache = eventCache;
 }
Exemplo n.º 24
0
        public void CachingPCL_SendEmptyEvents_Success(IEventCache cache)
        {
            var client = new KeenClient(settingsEnv, cache);

            Assert.DoesNotThrow(() => client.SendCachedEvents());
        }
Exemplo n.º 25
0
        private void SetupFakeBroker(
            CancellationToken cancel,
            IEventCache eventCache,
            bool useHeartbeat       = true,
            bool useEventLoop       = true,
            bool useStateOfTheWorld = true)
        {
            if (useHeartbeat)
            {
                //heartbeat
                Task.Run(() =>
                {
                    using (var heartbeatSocket = new ResponseSocket(HeartbeatEndpoint))
                    {
                        while (!cancel.IsCancellationRequested)
                        {
                            var hasResponse = heartbeatSocket.TryReceiveFrameBytes(TimeSpan.FromSeconds(1), out var messageBytes);

                            if (hasResponse)
                            {
                                heartbeatSocket.SendFrame(_serializer.Serialize(Heartbeat.Response));
                            }
                        }
                    }
                }, cancel);
            }

            if (useEventLoop)
            {
                //event loop
                Task.Run(async() =>
                {
                    using (var stateUpdate = new SubscriberSocket())
                    {
                        stateUpdate.SubscribeToAnyTopic();
                        stateUpdate.Bind(ToPublishersEndpoint);

                        while (!cancel.IsCancellationRequested)
                        {
                            NetMQMessage message = null;

                            var hasResponse = stateUpdate.TryReceiveMultipartMessage(TimeSpan.FromSeconds(1), ref message);

                            if (hasResponse)
                            {
                                var subject = message[0];
                                var payload = message[1];

                                await eventCache.AppendToStream(subject.Buffer, payload.Buffer);
                            }
                        }
                    }
                }, cancel);
            }

            if (useStateOfTheWorld)
            {
                //stateOfTheWorld
                Task.Run(async() =>
                {
                    using (var stateRequestSocket = new RouterSocket())
                    {
                        stateRequestSocket.Bind(StateOfTheWorldEndpoint);

                        while (!cancel.IsCancellationRequested)
                        {
                            NetMQMessage message = null;

                            var hasResponse = stateRequestSocket.TryReceiveMultipartMessage(TimeSpan.FromSeconds(1), ref message);

                            if (hasResponse)
                            {
                                var sender  = message[0].Buffer;
                                var request = _serializer.Deserialize <StateRequest>(message[1].Buffer);

                                var stream = await eventCache.GetStreamBySubject(request.Subject);

                                var response = new StateReply()
                                {
                                    Subject = request.Subject,
                                    Events  = stream.ToList()
                                };

                                stateRequestSocket.SendMoreFrame(sender)
                                .SendFrame(_serializer.Serialize(response));
                            }
                        }
                    }
                }, cancel);
            }
        }
Exemplo n.º 26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="prjSettings">A ProjectSettings instance containing the ProjectId and API keys</param>
 /// <param name="eventCache">An IEventCache instance providing a caching strategy</param>
 public KeenClient(IProjectSettings prjSettings, IEventCache eventCache)
     : this(prjSettings)
 {
     EventCache = eventCache;
 }
Exemplo n.º 27
0
 public void AddEvent_Null_Throws(IEventCache cache)
 {
     Assert.ThrowsAsync<Keen.Core.KeenException>(() => cache.Add(null));
 }