/// <summary> /// Adds API contract controllers, and registers integration api-service implementation. /// </summary> /// <param name="services">Collection of services</param> /// <param name="connectionStringManager">Connection string to integration Azure account storage</param> /// <param name="apiFactory">Factory of <see cref="IBlockchainApi"/></param> /// <returns></returns> public static IServiceCollection AddBlockchainApi(this IServiceCollection services, IReloadingManager <string> connectionStringManager, Func <IServiceProvider, IBlockchainApi> apiFactory, ChaosSettings chaosSettings = null) { connectionStringManager = connectionStringManager ?? throw new ArgumentNullException(nameof(connectionStringManager)); apiFactory = apiFactory ?? throw new ArgumentNullException(nameof(apiFactory)); services .AddSingleton(apiFactory) .AddBlockchainCommonRepositories(connectionStringManager) .AddBlockchainControllers(new[] { typeof(AddressesController), typeof(AssetsController), typeof(BalancesController), typeof(CapabilitiesController), typeof(ConstantsController), typeof(TestingController), typeof(TransactionsController) }) .AddChaos(chaosSettings) .AddTransient <IValidator <BuildSingleTransactionRequest>, BuildSingleTransactionRequestValidator>() .AddTransient <IValidator <BuildTransactionWithManyInputsRequest>, BuildTransactionWithManyInputsRequestValidator>() .AddTransient <IValidator <BuildTransactionWithManyOutputsRequest>, BuildTransactionWithManyOutputsRequestValidator>() .AddTransient <IValidator <BroadcastTransactionRequest>, BroadcastTransactionRequestValidator>() .AddTransient <IValidator <CreateAssetRequest>, CreateAssetRequestValidator>() .AddTransient <IValidator <TestingTransferRequest>, TestingTransferRequestValidator>() .ConfigureInvalidModelStateResponse(); return(services); }
/// <summary> /// Registers periodical handler and integration job-service implementation. /// </summary> /// <typeparam name="TState">Type of object to keep state between calls of <see cref="IBlockchainJob.TraceDepositsAsync()"/>.</typeparam> /// <param name="services">Collection of services</param> /// <param name="connectionStringManager">Connection string to integration Azure account storage</param> /// <param name="period">Interval used to call <see cref="IBlockchainJob.TraceDepositsAsync()"/></param> /// <param name="jobFactory">Factory of <see cref="IBlockchainJob"/></param> /// <returns></returns> public static IServiceCollection AddBlockchainJob <TState>(this IServiceCollection services, IReloadingManager <string> connectionStringManager, TimeSpan period, Func <IServiceProvider, IBlockchainJob <TState> > jobFactory, ChaosSettings chaosSettings = null) { jobFactory = jobFactory ?? throw new ArgumentNullException(nameof(jobFactory)); services .AddSingleton(jobFactory) .AddBlockchainCommonRepositories(connectionStringManager) .AddSingleton(sp => new StateRepository <TState>(connectionStringManager, sp.GetRequiredService <ILogFactory>())) .AddBlockchainControllers(Type.EmptyTypes) // there are no specific controllers in job .AddSingleton <IStartable>(sp => new DepositHandler <TState>( period, sp.GetRequiredService <ILogFactory>(), sp.GetRequiredService <DepositWalletRepository>(), sp.GetRequiredService <OperationRepository>(), sp.GetRequiredService <AssetRepository>(), sp.GetRequiredService <StateRepository <TState> >(), sp.GetRequiredService <IBlockchainJob <TState> >(), sp.GetService <IChaosKitty>() ) ) .AddChaos(chaosSettings); return(services); }
public async Task Should_Amend_Matched_Values_With_Fiddled_Response() { var chaosSettings = new ChaosSettings(); chaosSettings.ResponseFiddles.Add(new ResponseFiddle { Match = "http://some-endpoint.com", ReplaceMatchingWith = "Fiddled!" }); var responseObject = new TestResponse { AnotherField = "This-should-be-left-alone", Resource = "http://some-endpoint.com" }; var responseMessage = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(JsonConvert.SerializeObject(responseObject)), RequestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri("http://some-api-call.com")) }; var result = await _responseFiddler.Fiddle(responseMessage, chaosSettings); var resultContent = await result.Content.ReadAsStringAsync(); var deserialisedResponse = JsonConvert.DeserializeObject <TestResponse>(resultContent); deserialisedResponse.Resource.Should().Be("Fiddled!"); }
private void pLHS() { ChaosSettings[] newSettings = new ChaosSettings[sampleCount]; int[] sampleIndices = new int[sampleCount]; for (int i = 0; i < sampleCount; i++) { sampleIndices[i] = i; } for (int dimension = 0; dimension < dimensions; dimension++) { // Reshuffle for each dimension sampleIndices.Shuffle(); for (int i = 0; i < sampleCount; i++) { newSettings[i] = new ChaosSettings(samples[i]); for (int s = 0; s < CentralProperties.maxLayersForMC; s++) { // Get value from the new index in for our dimension double newValue = samples[sampleIndices[i]].getValue((ChaosSettings.properties)dimension, s); newSettings[i].setValue((ChaosSettings.properties)dimension, s, newValue); } } } samples = newSettings; }
public JobModule( AssetsSettings assetsSettings, ChaosSettings chaosSettings, MatchingEngineSettings matchingEngineSettings) { _assetsSettings = assetsSettings; _chaosSettings = chaosSettings; _meSettings = matchingEngineSettings; }
static IServiceCollection AddChaos(this IServiceCollection services, ChaosSettings chaosSettings) { if (chaosSettings != null) { services.AddSingleton <IChaosKitty>(sp => new ChaosKitty(chaosSettings.StateOfChaos)); } return(services); }
public TeleportChaoticPacketBuffer(ChaosSettings settings) { _internalBuffer = new TeleportPacketBuffer(); _incomingDisorderList = new List <QueuedPacket>(); _outgoingDisorderList = new List <QueuedPacket>(); _incomingDelayQueue = new PacketQueue(); _outgoingDelayQueue = new PacketQueue(); _random = new Random(settings.RandomSeed); _settings = settings; }
private void init(int number, bool previewMode, bool doPASearch, ref CommonVars commonVars) { dimensions = ChaosSettings.getDimensions(); _commonVars = commonVars; if (_commonVars.getSimulationSettings().getValue(EntropySettings.properties_i.linkCDU) == 1) { dimensions -= 3; } sampleCount = number; pMode = previewMode; paSearch = doPASearch; }
public JobModule(AssetsSettings assetsSettings, ChaosSettings chaosSettings) { _assetsSettings = assetsSettings; _chaosSettings = chaosSettings; }
public void Setup() { _chaosSettings = new ChaosSettings(); }
public MiscModule( IReloadingManager <AppSettings> appSettings) { _chaosSettings = appSettings.CurrentValue.Chaos; }
public static ChaosConfiguration ToChaosConfiguration(UpdateConfigurationRequest updateRequest) { var config = new ChaosConfiguration { ChaosInterval = new TimeSpan(0, 0, updateRequest.ChaosInterval), ConfigurationRotationInterval = new TimeSpan(0, 0, updateRequest.ConfigurationRotationInterval), Enabled = updateRequest.Enabled, HttpClientTimeoutInSeconds = updateRequest.HttpClientTimeoutInSeconds }; foreach (var updateChaosSettings in updateRequest.ChaosSettings) { var chaosConfiguration = new ChaosSettings { Name = updateChaosSettings.Name, MaxResponseDelayTime = updateChaosSettings.MaxResponseDelayTime, MinResponseDelayTime = updateChaosSettings.MinResponseDelayTime, PercentageOfChaos = updateChaosSettings.PercentageOfChaos, PercentageOfSlowResponses = updateChaosSettings.PercentageOfSlowResponses, ResponseTypeMediaType = updateChaosSettings.ResponseTypeMediaType }; if (updateChaosSettings.IgnoreUrls != null) { foreach (var url in updateChaosSettings.IgnoreUrls) { chaosConfiguration.IgnoreUrlPattern.Add(url.Pattern); } } foreach (var updateResponse in updateChaosSettings.HttpResponses) { var httpResponse = new ResponseDetails { StatusCode = updateResponse.StatusCode }; foreach (var payload in updateResponse.Payloads.Select(chaosResponsePayload => new ChaosResponsePayload { Code = chaosResponsePayload.Code, Content = chaosResponsePayload.Content })) { httpResponse.Payloads.Add(payload); } chaosConfiguration.HttpResponses.Add(httpResponse); } foreach (var responseFiddle in updateChaosSettings.ResponseFiddles) { var fiddle = new ResponseFiddle { Match = responseFiddle.Match, ReplaceMatchingWith = responseFiddle.ReplaceMatchingWith }; chaosConfiguration.ResponseFiddles.Add(fiddle); } config.ChaosSettings.Add(chaosConfiguration); } return(config); }