public async void should_correctly_do_a_full_send_then_receive_in_single_pipeline() { var filename = "example_save.json"; _testOutputHelper.WriteLine("{0}/{1}", Environment.CurrentDirectory, filename); var serializer = new JsonSerializer(); var deserializer = new JsonDeserializer(); var memoryEndpoint = new InMemoryEndpoint(); var encryptor = new AesEncryptor("some-password"); var encryptionProcessor = new EncryptDataProcessor(encryptor); var decryptionProcessor = new DecryptDataProcessor(encryptor); var saveToBinaryFilePipeline = new PipelineBuilder() .StartFromInput() .SerializeWith(serializer) .ProcessWith(encryptionProcessor) .ThenSendTo(memoryEndpoint) .ThenReceiveFrom(memoryEndpoint) .ProcessWith(decryptionProcessor) .DeserializeWith <GameData>(deserializer) .Build(); var dummyData = GameData.CreateRandom(); var outputModel = await saveToBinaryFilePipeline.Execute(dummyData); Assert.AreEqual(dummyData, outputModel); }
public void CreateInlineJob() { var pipeline = new PipelineBuilder <string, int>() .Register <string, string>(s => s.Trim()) .Register <string, int>(int.Parse) .Register <int, int>(i => i % 2) .OnError((sender, exception) => Console.WriteLine(exception)) .Build(); int result = pipeline.Execute(" 123 "); }
public void Cancel() { var pipeline = new PipelineBuilder() .AddStep(new ToStringStep()) .AddStep(new CancellingStep()) .AddStep(new ToIntStep()) .Build(); var result = pipeline.Execute(12); Assert.Equal(default(int), result.Value); }
public void Simple() { var pipeline = new PipelineBuilder() .AddStep(new ToStringStep()) .AddStep(new DoublerStep()) .AddStep(new DoublerStep()) .Build(); var result = pipeline.Execute(12); Assert.Equal("12121212", result.Value); }
public async void should_stop_wiretap_correctly() { var dummyPipeline = new PipelineBuilder() .StartFrom(x => Task.FromResult((object)"hello")) .ThenInvoke(x => Task.FromResult((object)"there")) .Build() .AsWireTappable(); Action <object, object> action = (x, y) => { Assert.True(false); }; dummyPipeline.StartWiretap(1, action); dummyPipeline.StartWiretap(2, action); dummyPipeline.StopWiretap(1, action); dummyPipeline.StopWiretap(2, action); dummyPipeline.Execute(); }
static void Main(string[] args) { var context = new HttpContext() { Response = "monica" }; var pipeline = new PipelineBuilder <HttpContext>() .Register(new ReverseStringFilter()) .Register(new UppercaseStringFilter()) .Register(new ResponseFilter()) .Build(); pipeline.Execute(context).Wait(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public async void should_correctly_fork_stream_for_object_with_builder() { var expectedString = "hello there some new pipeline"; var data = "hello"; var dummyPipeline = new PipelineBuilder() .StartFromInput() .ThenInvoke(x => Task.FromResult((object)(x + " there"))) .ThenInvoke(x => Task.FromResult((object)(x + " some"))) .ThenInvoke(x => Task.FromResult((object)(x + " old"))) .ThenInvoke(x => Task.FromResult((object)(x + " pipeline"))) .Build(); var forkedPipeline = new PipelineBuilder() .ForkObjectFrom(dummyPipeline, 2) .ThenInvoke(x => Task.FromResult((object)(x + " new"))) .ThenInvoke(x => Task.FromResult((object)(x + " pipeline"))) .Build(); var actualOutput = await forkedPipeline.Execute(data); Assert.Equal(expectedString, actualOutput); }
public async void should_unsubscribe_wiretap_correctly() { var dummyPipeline = new PipelineBuilder() .StartFrom(x => Task.FromResult((object)"hello")) .ThenInvoke(x => Task.FromResult((object)"there")) .Build() .AsWireTappable(); var sub1 = dummyPipeline.StartWiretap(1, (x, y) => { Assert.True(false); }); var sub2 = dummyPipeline.StartWiretap(2, (x, y) => { Assert.True(false); }); sub1.Unsubscribe(); sub2.Unsubscribe(); dummyPipeline.Execute(); }
public void RecordGoal(string clientId, string goal, IDatabase dbContext = null) { var db = dbContext ?? _dbConnector.GetDatabase(); var participant = _participantContext.GetParticipant(clientId, db); if (participant == null) { return; } var goalsAsSet = _participantContext.GetParticipantsGoals(clientId, db); var pipelineBuilder = new PipelineBuilder(db); foreach (var test in participant.EnrolledTests) { if (goalsAsSet.ContainsKey("{0}:{1}".FormatWith(test.Name, goal))) { _logger.LogDebug("Previously recorded {0} for test {1}".FormatWith(goal, test.Name)); continue; } _logger.LogDebug("Tracking {0} for test {1}".FormatWith(goal, test.Name)); pipelineBuilder.SetAdd( DatabaseKeys.ParticipantGoalsFormat.FormatWith(clientId), "{0}:{1}".FormatWith(test.Name, goal)); pipelineBuilder.StringIncrement( DatabaseKeys.ExperimentGoalCountKeyFormat.FormatWith( test.Name, test.VersionAtSelection, test.SelectedVariant, goal)); } pipelineBuilder.Execute(); }
public async void should_wiretap_correctly() { var dummyPipeline = new PipelineBuilder() .StartFrom(x => Task.FromResult((object)"hello")) .ThenInvoke(x => Task.FromResult((object)"there")) .Build() .AsWireTappable(); var ranCount = 0; dummyPipeline.StartWiretap(1, (x, y) => { Assert.Equal("hello", x); ranCount++; }); dummyPipeline.StartWiretap(2, (x, y) => { Assert.Equal("there", x); ranCount++; }); dummyPipeline.Execute(); Assert.Equal(2, ranCount); }
public string EnrollParticipantInTest(string clientId, string test) { var db = _dbConnector.GetDatabase(); var currentTest = _testContext.GetTest(test, dbContext: db); // check to see if the test is valid if (currentTest == null) { throw new Exception( "Test {0} has not been configured, cannot enroll".FormatWith(test)); } var participant = _participantContext.GetParticipant(clientId); var selectedVariant = _variantPicker.SelectVariant(currentTest); // check to see if the user has already been setup if (participant == null) { _logger.LogDebug("User was not setup with any tests, creating key"); participant = new Participant { ClientId = clientId, EnrolledTests = new List <Test> () }; } var existingTest = participant.EnrolledTests.Where(x => x.Name == test).FirstOrDefault(); var pipelineBuilder = new PipelineBuilder(db); if (existingTest == null) { _logger.LogDebug("User did not have test, setting up"); participant.EnrolledTests = participant.EnrolledTests.Append(new Test { Name = test, SelectedVariant = selectedVariant, VersionAtSelection = currentTest.Version }); pipelineBuilder.StringIncrement(DatabaseKeys.ExperimentCurrentCountKeyFormat.FormatWith(test)); pipelineBuilder.StringIncrement(DatabaseKeys.ExperimentVariantVersionKeyFormat.FormatWith(test, currentTest.Version, selectedVariant)); } else { if (existingTest.VersionAtSelection == currentTest.Version) { _logger.LogDebug("User already had variant"); return(existingTest.SelectedVariant); } else { _logger.LogDebug("User variant version differs, updating"); existingTest.SelectedVariant = selectedVariant; existingTest.VersionAtSelection = currentTest.Version; pipelineBuilder.StringIncrement(DatabaseKeys.ExperimentCurrentCountKeyFormat.FormatWith(test)); // clean existing recorded goals for the new test var goalsAsSet = _participantContext.GetParticipantsGoals(participant.ClientId, db); var experimentGoals = goalsAsSet.Keys.Where(x => x.StartsWith(test + ":")).ToList(); pipelineBuilder.StringIncrement(DatabaseKeys.ExperimentVariantVersionKeyFormat.FormatWith(test, currentTest.Version, selectedVariant)); pipelineBuilder.SetRemoveRange(DatabaseKeys.ParticipantGoalsFormat.FormatWith(clientId), experimentGoals); } } var participantBytes = participant.SerializeAsJson(); pipelineBuilder.StringSet(DatabaseKeys.ParticipantKeyFormat.FormatWith(clientId), participantBytes); pipelineBuilder.Execute(); return(selectedVariant); }