public async Task WorksCorrectlyForOneThread_InvalidateCacheAsync() { // arrange var(h3, y1) = MakeFakeHttpClientHandler(); // act var httpBuilder = HttpClientGenerator.BuildForUrl("http://fake.host"); var cacheManager = new ClientCacheManager(); var testInterface = httpBuilder .WithCachingStrategy(new AttributeBasedCachingStrategy()) .WithAdditionalDelegatingHandler(h3) .Create(cacheManager) .Generate <ITestInterface>(); var result = await testInterface.TestMethodWithCache(); var result1 = await testInterface.TestMethodWithCache(); cacheManager.InvalidateCacheAsync().Wait(); var result2 = await testInterface.TestMethodWithCache(); cacheManager.Dispose(); // assert result.Should().Be(_result1Str); result1.Should().Be(_result1Str); result2.Should().Be(_result2Str); }
public async Task GetAllSettings__CalledAfterAdd__CouldBeInvalidated() { var cacheManager = new ClientCacheManager(); var client = Factory.CreateNew(Fixture.ClientUrl, "default", true, cacheManager, new RequestInterceptorHandler(Fixture.Client)); var allSettings = await client.GetAllSettingsAsync(); await client.CreateAsync(new BlockchainSettingsCreateRequest() { HotWalletAddress = "ANY_ADDRESS_POSSIBLE", Type = "TYPE_1", SignServiceUrl = "http://fake.sign.com/", ApiUrl = "http://fake.api.com/" }); var allSettings2 = await client.GetAllSettingsAsync(); var allSettingsCountBeforeInvalidation = allSettings2.Collection.Count(); await cacheManager.InvalidateCacheAsync(); var allSettings3 = await client.GetAllSettingsAsync(); Assert.IsNotNull(allSettings.Collection); Assert.IsNotNull(allSettings2.Collection); Assert.IsNotNull(allSettings3.Collection); Assert.IsTrue(allSettings.Collection.Count() == 1); Assert.IsTrue(allSettingsCountBeforeInvalidation == 1); Assert.IsTrue(allSettings3.Collection.Count() == 2); }
public async Task GetAllExplorersAsync__CalledAfterAdd__CouldBeInvalidated() { var cacheManager = new ClientCacheManager(); var client = Factory.CreateNew(Fixture.ClientUrl, "default", true, cacheManager, new RequestInterceptorHandler(Fixture.Client)); var allSettings = await client.GetAllExplorersAsync(); await client.CreateBlockchainExplorerAsync(new BlockchainExplorerCreateRequest { Name = "Ropsten1", BlockchainType = "EthereumClassic", ExplorerUrlTemplate = "https://ropsten.etherscan.io/tx/{tx-hash}" }); var allSettings2 = await client.GetAllExplorersAsync(); var allSettingsCountBeforeInvalidation = allSettings2.Collection.Count(); await cacheManager.InvalidateCacheAsync(); var allSettings3 = await client.GetAllExplorersAsync(); Assert.IsNotNull(allSettings.Collection); Assert.IsNotNull(allSettings2.Collection); Assert.IsNotNull(allSettings3.Collection); Assert.IsTrue(allSettings.Collection.Count() == 1); Assert.IsTrue(allSettingsCountBeforeInvalidation == 1); Assert.IsTrue(allSettings3.Collection.Count() == 2); }
public async Task IsAlive__Called__ReturnsResult(bool cacheEnabled) { var cacheManager = new ClientCacheManager(); var client = Factory.CreateNew(Fixture.ClientUrl, "default", cacheEnabled, cacheManager, new RequestInterceptorHandler(Fixture.Client)); var isAliveResponse = await client.GetIsAliveAsync(); Assert.IsNotNull(isAliveResponse); }
private static async Task CreateSettingsAsync(string urlToSettingsWithBlockchainIntegrationSection, string blockchainSettingsUrl, string apiKey) { var uri = new Uri(urlToSettingsWithBlockchainIntegrationSection); var appSettings = Lykke.SettingsReader.SettingsReader.ReadGeneralSettings <AppSettings>(uri); var list = appSettings.BlockchainsIntegration.Blockchains.ToList(); var blockchainSettingsClientFactory = new BlockchainSettingsClientFactory(); var cacheManager = new ClientCacheManager(); var client = blockchainSettingsClientFactory.CreateNew(blockchainSettingsUrl, apiKey, true, cacheManager); try { var response = await client.GetIsAliveAsync(); if (response == null) { System.Console.WriteLine($"No access to {blockchainSettingsUrl}"); return; } } catch (Exception e) { System.Console.WriteLine($"No access to {blockchainSettingsUrl}"); return; } foreach (var item in list) { System.Console.WriteLine($"Processing {item.Type}"); var existing = await client.GetSettingsByTypeAsync(item.Type); if (existing != null) { System.Console.WriteLine($"{item.Type} setting already exists"); await client.UpdateAsync(new BlockchainSettingsUpdateRequest() { ETag = existing.ETag, Type = item.Type, HotWalletAddress = item.HotWalletAddress, SignServiceUrl = item.SignServiceUrl, ApiUrl = item.ApiUrl }); continue; } await client.CreateAsync(new BlockchainSettingsCreateRequest() { Type = item.Type, HotWalletAddress = item.HotWalletAddress, SignServiceUrl = item.SignServiceUrl, ApiUrl = item.ApiUrl, }); System.Console.WriteLine($"{item.Type} has been processed"); } }
public async Task GetAllSettings__Called__Returns(bool cacheEnabled) { var cacheManager = new ClientCacheManager(); var client = Factory.CreateNew(Fixture.ClientUrl, "default", cacheEnabled, cacheManager, new RequestInterceptorHandler(Fixture.Client)); var allSettings = await client.GetAllSettingsAsync(); Assert.IsNotNull(allSettings.Collection); Assert.IsTrue(allSettings.Collection.Count() == 1); }
public async Task WorksCorrectlyForManyThreads_InvalidateCacheAsync() { // arrange var(h3, y1) = MakeFakeHttpClientHandler(); var bag = new ConcurrentBag <List <string> >(); var httpBuilder = HttpClientGenerator.BuildForUrl("http://fake.host"); var cacheManager = new ClientCacheManager(); var testInterface = httpBuilder .WithCachingStrategy(new AttributeBasedCachingStrategy()) .WithAdditionalDelegatingHandler(h3) .Create(cacheManager) .Generate <ITestInterface>(); var cacheModifyingTasks = Enumerable .Range(0, 100) .Select(x => Task.Factory.StartNew(async() => { var list = new List <string>(2); var result1 = await testInterface.TestMethodWithCache(); await cacheManager.InvalidateCacheAsync(); var result2 = await testInterface.TestMethodWithCache(); list.Add($"{Thread.CurrentThread.Name} {result1}"); list.Add($"{Thread.CurrentThread.Name} {result2}"); bag.Add(list); }).Unwrap()); // act await Task.WhenAll(cacheModifyingTasks); cacheManager.Dispose(); var results = bag.ToArray().SelectMany(x => x); var res2Count = results.Count(x => x.Contains(_result2Str)); // assert res2Count.Should().BeGreaterThan(0); }
public async Task WhenObjectNotDisposed_InvalidateAllOnEachCall() { var subscribers = Enumerable.Range(0, 10) .Select(x => new MockSubscriber()) .ToList(); ClientCacheManager cacheManager = new ClientCacheManager(); foreach (var subscriber in subscribers) { cacheManager.OnInvalidate += subscriber.InvalidateCacheAsync; } await cacheManager.InvalidateCacheAsync(); await cacheManager.InvalidateCacheAsync(); foreach (var subscriber in subscribers) { //2 Time for each subscriber subscriber.CacheInvalidatedCallsCount.Should().Be(2); } }
protected override void Load(ContainerBuilder builder) { builder.RegisterClientAccountClient(_settings.ClientAccountServiceUrl); builder.RegisterHftInternalClient(_settings.HftInternalServiceUrl); builder.RegisterType <LykkeMarketProfileServiceAPI>() .As <ILykkeMarketProfileServiceAPI>() .WithParameter("baseUri", new Uri(_settings.MarketProfileUrl)); builder.RegisterOperationsClient(_settings.OperationsUrl); builder.RegisterType <LykkeRegistrationClient>() .As <ILykkeRegistrationClient>() .WithParameter("serviceUrl", _settings.RegistrationUrl); builder.RegisterClientSessionClient(new SessionServiceClientSettings { ServiceUrl = _apiSettings.CurrentValue.WalletApiv2.Services.SessionUrl }); builder.RegisterType <PersonalDataService>().As <IPersonalDataService>() .WithParameter(TypedParameter.From(_apiSettings.CurrentValue.PersonalDataServiceSettings)); builder.RegisterInstance( new KycStatusServiceClient(_apiSettings.CurrentValue.KycServiceClient, _log)) .As <IKycStatusService>() .SingleInstance(); builder.RegisterInstance( new KycProfileServiceClient(_apiSettings.CurrentValue.KycServiceClient, _log)) .As <IKycProfileService>() .SingleInstance(); builder.RegisterInstance <IAssetDisclaimersClient>( new AssetDisclaimersClient(_apiSettings.CurrentValue.AssetDisclaimersServiceClient)); _services.RegisterAssetsClient(AssetServiceSettings.Create( new Uri(_settings.AssetsServiceUrl), TimeSpan.FromMinutes(60)), _log); builder.RegisterClientDictionariesClient(_apiSettings.CurrentValue.ClientDictionariesServiceClient, _log); var socketLog = new SocketLogDynamic( i => { }, s => _log.WriteInfo("MeClient", null, s)); builder.BindMeClient(_apiSettings.CurrentValue.MatchingEngineClient.IpEndpoint.GetClientIpEndPoint(), socketLog, ignoreErrors: true); builder.RegisterFeeCalculatorClient(_apiSettings.CurrentValue.FeeCalculatorServiceClient.ServiceUrl, _log); builder.RegisterAffiliateClient(_settings.AffiliateServiceClient.ServiceUrl, _log); builder.RegisterIndicesFacadeClient(new IndicesFacadeServiceClientSettings { ServiceUrl = _settings.IndicesFacadeServiceUrl }, null); builder.RegisterInstance <IAssetDisclaimersClient>(new AssetDisclaimersClient(_apiSettings.CurrentValue.AssetDisclaimersServiceClient)); builder.RegisterPaymentSystemClient(_apiSettings.CurrentValue.PaymentSystemServiceClient.ServiceUrl, _log); builder.RegisterLimitationsServiceClient(_apiSettings.CurrentValue.LimitationServiceClient.ServiceUrl); builder.RegisterClientDialogsClient(_apiSettings.CurrentValue.ClientDialogsServiceClient); builder.Register(ctx => new BlockchainWalletsClient(_apiSettings.CurrentValue.BlockchainWalletsServiceClient.ServiceUrl, _log, new BlockchainWalletsApiFactory())) .As <IBlockchainWalletsClient>() .SingleInstance(); builder.RegisterSwiftCredentialsClient(_apiSettings.CurrentValue.SwiftCredentialsServiceClient); builder.RegisterHistoryClient(new HistoryServiceClientSettings { ServiceUrl = _settings.HistoryServiceUrl }); builder.RegisterConfirmationCodesClient(_apiSettings.Nested(r => r.ConfirmationCodesClient).CurrentValue); builder.RegisterBlockchainCashoutPreconditionsCheckClient(_apiSettings.CurrentValue.BlockchainCashoutPreconditionsCheckServiceClient.ServiceUrl); #region BlockchainSettings var settings = _blockchainSettingsServiceClient; var cacheManager = new ClientCacheManager(); var factory = new Lykke.Service.BlockchainSettings.Client.HttpClientGenerator.BlockchainSettingsClientFactory(); var client = factory.CreateNew(settings.ServiceUrl, settings.ApiKey, true, cacheManager); builder.RegisterInstance(client) .As <IBlockchainSettingsClient>(); builder.RegisterInstance(client) .As <IBlockchainSettingsClient>() .SingleInstance(); builder.RegisterInstance(cacheManager) .As <IClientCacheManager>() .SingleInstance(); builder.RegisterType <BlockchainExplorersProvider>() .As <IBlockchainExplorersProvider>() .SingleInstance(); #endregion builder.RegisterPushNotificationsClient(_apiSettings.CurrentValue.PushNotificationsServiceClient.ServiceUrl); builder.RegisterTierClient(_apiSettings.CurrentValue.TierServiceClient); builder.RegisterMarketDataClient(_apiSettings.CurrentValue.MarketDataServiceClient); builder.RegisterLink4PayClient(_apiSettings.CurrentValue.Link4PayServiceClient); builder.Populate(_services); }