public void TestUploaderInvalidServerAddress() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; bool exceptionCaught = false; using (var uploader = new EventUploader(null, "http://uploader.test")) { uploader.InitializeWithToken(MockCommandCenter.SettingsBlobUri); uploader.PackageSent += (sender, e) => { eventSentCount += e.Records.Count(); }; uploader.PackageSendFailed += (sender, e) => { exceptionCaught = e.Exception != null; }; uploader.Upload(new Interaction { Value = 1, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = new int[] { 1 }, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); } Assert.AreEqual(0, joinServer.RequestCount); Assert.AreEqual(0, eventSentCount); Assert.AreEqual(0, joinServer.EventBatchList.Count); Assert.AreEqual(true, exceptionCaught); }
public void TestUploaderSingleEvent() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; using (var uploader = new EventUploader(null, MockJoinServer.MockJoinServerAddress)) { uploader.InitializeWithToken(MockCommandCenter.TestAppID); uploader.PackageSent += (sender, e) => { eventSentCount += e.Records.Count(); }; uploader.Upload(new Interaction { Value = 1, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = new int[] { 1 }, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); } Assert.AreEqual(2, eventSentCount); Assert.AreEqual(1, joinServer.RequestCount); Assert.AreEqual(1, joinServer.EventBatchList.Count); Assert.AreEqual(2, joinServer.EventBatchList[0].ExperimentalUnitFragments.Count); Assert.AreEqual(uniqueKey, joinServer.EventBatchList[0].ExperimentalUnitFragments[0].Id); Assert.IsTrue(joinServer.EventBatchList[0].ExperimentalUnitFragments[0].Value.ToLower().Contains("\"a\":1,")); Assert.AreEqual(uniqueKey, joinServer.EventBatchList[0].ExperimentalUnitFragments[1].Id); Assert.IsTrue(joinServer.EventBatchList[0].ExperimentalUnitFragments[1].Value.ToLower().Contains("\"a\":[1],")); }
public void TestUploaderMultipleEvents() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; using (var uploader = new EventUploader(null, MockJoinServer.MockJoinServerAddress)) { uploader.InitializeWithToken(MockCommandCenter.TestAppID); uploader.PackageSent += (sender, e) => { eventSentCount += e.Records.Count(); }; uploader.Upload(new Interaction { Value = 1, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = 2, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .7f, .1f, .1f, .1f, .0f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = 0, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = new int[] { 1 }, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = new int[] { 2 }, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .7f, .1f, .1f, .1f, .0f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = new int[] { 0 }, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .5f, .1f, .1f, .1f, .1f } }, Key = uniqueKey }); uploader.Upload(new Observation { Value = "1", Key = uniqueKey }); uploader.Upload(new Observation { Value = "2", Key = uniqueKey }); uploader.Upload(new Observation { Value = JsonConvert.SerializeObject(new { value = "test outcome" }), Key = uniqueKey }); } Assert.AreEqual(9, eventSentCount); Assert.AreEqual(9, joinServer.EventBatchList.Sum(batch => batch.ExperimentalUnitFragments.Count)); }
public void InitializeWithCustomAzureJoinServer( string loggingServiceBaseAddress, BatchingConfiguration batchConfig) { var eventUploader = new EventUploader(batchConfig, loggingServiceBaseAddress, developmentMode: this.developmentMode); eventUploader.InitializeWithToken(this.applicationID); this.interactionEventUploader = eventUploader; }
public void TestUploaderInvalidServerAddress() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; var uploader = new EventUploader(null, "http://uploader.test"); bool exceptionCaught = false; uploader.InitializeWithToken(MockCommandCenter.AuthorizationToken); uploader.PackageSent += (sender, e) => { eventSentCount += e.Records.Count(); }; uploader.PackageSendFailed += (sender, e) => { exceptionCaught = e.Exception != null; }; uploader.Upload(new SingleActionInteraction { Action = 1, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Upload(new MultiActionInteraction { Actions = new uint[] { 1 }, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Flush(); Assert.AreEqual(0, joinServer.RequestCount); Assert.AreEqual(0, eventSentCount); Assert.AreEqual(0, joinServer.EventBatchList.Count); Assert.AreEqual(true, exceptionCaught); }
public void TestUploaderSingleEvent() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; var uploader = new EventUploader(null, MockJoinServer.MockJoinServerAddress); uploader.InitializeWithToken(MockCommandCenter.AuthorizationToken); uploader.PackageSent += (sender, e) => { eventSentCount += e.Records.Count(); }; uploader.Upload(new SingleActionInteraction { Action = 1, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Upload(new MultiActionInteraction { Actions = new uint[] { 1 }, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Flush(); Assert.AreEqual(2, eventSentCount); Assert.AreEqual(1, joinServer.RequestCount); Assert.AreEqual(1, joinServer.EventBatchList.Count); Assert.AreEqual(2, joinServer.EventBatchList[0].ExperimentalUnitFragments.Count); Assert.AreEqual(uniqueKey, joinServer.EventBatchList[0].ExperimentalUnitFragments[0].Id); Assert.IsTrue(joinServer.EventBatchList[0].ExperimentalUnitFragments[0].Value.ToLower().Contains("\"a\":1,")); Assert.AreEqual(uniqueKey, joinServer.EventBatchList[0].ExperimentalUnitFragments[1].Id); Assert.IsTrue(joinServer.EventBatchList[0].ExperimentalUnitFragments[1].Value.ToLower().Contains("\"a\":[1],")); }
public void TestUploaderThreadSafeMock() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; int numEvents = 1000; using (var uploader = new EventUploader(null, MockJoinServer.MockJoinServerAddress)) { uploader.InitializeWithToken(MockCommandCenter.TestAppID); uploader.PackageSent += (sender, e) => { Interlocked.Add(ref eventSentCount, e.Records.Count()); }; Parallel.For(0, numEvents, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2 }, (i) => { uploader.Upload(new Interaction { Value = i, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .2f, .2f, .2f, .2f, .2f } }, Key = uniqueKey }); uploader.Upload(new Interaction { Value = new int[] { i }, Context = JsonConvert.SerializeObject(new TestContext()), ExplorerState = new GenericTopSlotExplorerState { Probabilities = new float[] { .2f, .2f, .2f, .2f, .2f } }, Key = uniqueKey }); uploader.Upload(new Observation { Value = JsonConvert.SerializeObject(new { value = "999" + i }), Key = uniqueKey }); }); } Assert.AreEqual(numEvents * 3, eventSentCount); Assert.AreEqual(numEvents * 3, joinServer.EventBatchList.Sum(batch => batch.ExperimentalUnitFragments.Count)); }
public void TestUploaderThreadSafeMock() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; var uploader = new EventUploader(null, MockJoinServer.MockJoinServerAddress); uploader.InitializeWithToken(MockCommandCenter.AuthorizationToken); uploader.PackageSent += (sender, e) => { Interlocked.Add(ref eventSentCount, e.Records.Count()); }; int numEvents = 1000; Parallel.For(0, numEvents, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2 }, (i) => { uploader.Upload(new SingleActionInteraction { Action = (uint)i, Context = JsonConvert.SerializeObject(new TestContext()), Probability = i / 1000.0, Key = uniqueKey }); uploader.Upload(new MultiActionInteraction { Actions = new uint[] { (uint)i }, Context = JsonConvert.SerializeObject(new TestContext()), Probability = i / 1000.0, Key = uniqueKey }); uploader.Upload(new Observation { Value = JsonConvert.SerializeObject(new { value = "999" + i }), Key = uniqueKey }); }); uploader.Flush(); Assert.AreEqual(numEvents * 3, eventSentCount); Assert.AreEqual(numEvents * 3, joinServer.EventBatchList.Sum(batch => batch.ExperimentalUnitFragments.Count)); }
public void TestUploaderMultipleEvents() { joinServer.Reset(); string uniqueKey = "test interaction"; int eventSentCount = 0; var uploader = new EventUploader(null, MockJoinServer.MockJoinServerAddress); uploader.InitializeWithToken(MockCommandCenter.AuthorizationToken); uploader.PackageSent += (sender, e) => { eventSentCount += e.Records.Count(); }; uploader.Upload(new SingleActionInteraction { Action = 1, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Upload(new SingleActionInteraction { Action = 2, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.7, Key = uniqueKey }); uploader.Upload(new SingleActionInteraction { Action = 0, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Upload(new MultiActionInteraction { Actions = new uint[] { 1 }, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Upload(new MultiActionInteraction { Actions = new uint[] { 2 }, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.7, Key = uniqueKey }); uploader.Upload(new MultiActionInteraction { Actions = new uint[] { 0 }, Context = JsonConvert.SerializeObject(new TestContext()), Probability = 0.5, Key = uniqueKey }); uploader.Upload(new Observation { Value = "1", Key = uniqueKey }); uploader.Upload(new Observation { Value = "2", Key = uniqueKey }); uploader.Upload(new Observation { Value = JsonConvert.SerializeObject(new { value = "test outcome" }), Key = uniqueKey }); uploader.Flush(); Assert.AreEqual(9, eventSentCount); Assert.AreEqual(9, joinServer.EventBatchList.Sum(batch => batch.ExperimentalUnitFragments.Count)); }