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()); }
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" })); }
public BrokerageService(IBrokerageServiceConfiguration configuration, IEventCache cache, ISerializer serializer) { _cache = cache; _serializer = serializer; _configuration = configuration; _cancel = new CancellationTokenSource(); }
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()); }
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" })); }
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(); }
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()); }
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); }
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"); }
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"); }
public async Task AddEvent_Null_Throws(IEventCache cache) { await cache.Add(null); }
public void AddEvent_Null_Throws(IEventCache cache) { Assert.ThrowsAsync <Keen.Core.KeenException>(() => cache.Add(null)); }
public async Task AddEvent_ValidObject_Success(IEventCache cache) { await cache.Add(new CachedEvent("url", JObject.FromObject( new { AProperty = "AValue" }))); }
public void CachingPCL_ClearEvents_Success(IEventCache cache) { var client = new KeenClient(settingsEnv, cache); Assert.DoesNotThrow(() => client.EventCache.Clear()); }
/// <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) { }
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"); }
public void CachingPCL_ClearEvents_Success(IEventCache cache) { var client = new KeenClient(SettingsEnv, cache); Assert.DoesNotThrow(() => client.EventCache.Clear()); }
public void CachingPCL_SendEmptyEvents_Success(IEventCache cache) { var client = new KeenClient(SettingsEnv, cache); Assert.DoesNotThrow(client.SendCachedEvents); }
public async Task AddEvent_ValidObject_Success(IEventCache cache) { await cache.Add(new CachedEvent("url", JObject.FromObject(new { AProperty = "AValue" }))); }
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"); }
/// <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; }
public void CachingPCL_SendEmptyEvents_Success(IEventCache cache) { var client = new KeenClient(settingsEnv, cache); Assert.DoesNotThrow(() => client.SendCachedEvents()); }
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); } }
public void AddEvent_Null_Throws(IEventCache cache) { Assert.ThrowsAsync<Keen.Core.KeenException>(() => cache.Add(null)); }