public async Task Resolve_by_contract_should_be_success() { await(await new IxHostBuilder() .Configure( rootNodes => rootNodes .Add(new DummyImplementationConfig()) .Add(new DummyContractConsumerConfig())) .Build()) .AsyncUsing( async host => { using (IxLock <IDummyConsumer> consumer = await host.Resolver.Get <IDummyConsumer>()) { var consumerImpl = consumer.Target as DummyContractConsumer; consumerImpl.Should().NotBeNull(); consumerImpl.Dummy.Should().NotBeNull(); } using (IxLock <IDummyContract> impl = await host.Resolver.Get <IDummyContract>()) { IDummyContract i = impl.Target; i.Should().NotBeNull(); } }); }
public void GetSession_EnsureSameDistributedSession() { List <string> sessions = new List <string>(); Callback = new Mock <IDummyContract>(MockBehavior.Strict); DistributedCache.Setup(c => c.RefreshAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(true)) .Callback <string, CancellationToken>( (v, t) => { sessions.Add(v); }).Verifiable(); Callback.Setup(c => c.OnExecute(It.IsAny <object>())).Callback <object>( v => { sessions.Add(((DummyContract)v).HttpSessionProvider.SessionId); }).Verifiable(); IDummyContract channel = CreateChannel(); channel.OnExecute(null); channel.OnExecute(null); channel.OnExecute(null); Assert.True(sessions.Distinct().Count() == 1, "Multiple sessions were created."); DistributedCache.Verify(); }
private static void StartClient() { Console.WriteLine("Starting Client ... "); IServerProvider serverProvider = new RandomServerProvider(new Uri("http://localhost:5000"), new Uri("http://localhost:5001")); ClientConfiguration configuration = new ClientConfiguration(); IDummyContract proxy1 = CreateProxy(configuration, serverProvider); TestProxy(proxy1).GetAwaiter().GetResult(); IDummyContract proxy2 = CreateProxy(configuration, serverProvider); TestProxy(proxy2).GetAwaiter().GetResult(); Console.WriteLine(); }
private static async Task TestBoltAsync(ILogger <Program> logger, ISerializer serializer, CancellationToken cancellationToken) { // create Bolt proxy ClientConfiguration configuration = new ClientConfiguration() { Serializer = serializer }; IDummyContract proxy = configuration.CreateProxy <IDummyContract>("http://localhost:5000"); logger.LogInformation("Testing Bolt Proxy ... "); for (int i = 0; i < 10; i++) { try { string payload = Guid.NewGuid().ToString(); string result = await proxy.ExecuteAsync(payload); if (result != payload) { throw new InvalidOperationException("Wrong data received."); } } catch (Exception e) { logger.LogInformation("Client: Error {0}", e.Message); _result = 1; } logger.LogInformation("---------------------------------------------"); try { await Task.Delay(10, cancellationToken); } catch (OperationCanceledException) { return; } } Console.WriteLine("Test finished. Application will now exit ... "); }
private static async Task TestBolt(ILogger <Program> logger, CancellationToken cancellationToken) { // create Bolt proxy ClientConfiguration configuration = new ClientConfiguration(); IDummyContract proxy = configuration.CreateProxy <IDummyContract>("http://localhost:5000"); logger.LogInformation("Testing Bolt Proxy ... "); for (int i = 0; i < 10; i++) { logger.LogInformation("Client: Sending {0}", i); // we can add timeout and CancellationToken to each Bolt call using (new RequestScope(TimeSpan.FromSeconds(5), cancellationToken)) { try { await proxy.ExecuteAsync(i.ToString(CultureInfo.InvariantCulture)); } catch (OperationCanceledException) { // ok } catch (Exception e) { logger.LogInformation("Client: Error {0}", e.Message); } } logger.LogInformation("Client: Received {0}", i); logger.LogInformation("--------------------------------------------"); try { await Task.Delay(10, cancellationToken); } catch (OperationCanceledException) { return; } } }
private static async Task TestProxy(IDummyContract proxy) { Console.WriteLine("Sending {0} requests to multiple servers with session", 10); int numRequests = 0; for (int i = 0; i < 10; i++) { numRequests = await proxy.IncrementRequestCount(); Console.WriteLine(); await Task.Delay(TimeSpan.FromSeconds(0.2)); } if (numRequests != 10) { throw new InvalidOperationException( $"Distributed session failed. Expected number of requests processed: {10}, Actual: {numRequests}"); } Console.WriteLine("Test finished. Press any key to continue ... "); }
private DummyContractConsumer(IDummyContract dummy, DummyContractConsumerConfig config) { Dummy = dummy; }