public async void RequestGetsResponseFromServer() { var clientFactory = new ServiceClientFactory(new SimpleClient(new ServiceFactory(this.resolver))); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); //Synchronous Assert.That(serviceClient.GetPerson(1), Is.Not.Null); //Asynchronous task based var persons = await serviceClient.ListPersonsAsync(5); Assert.That(persons, Is.Not.Null); Assert.AreEqual(5, persons.Count()); //Asynchronous IAsyncResult based , awaiting with Task var person = await Task.Factory.FromAsync<int, Person>(serviceClient.BeginGetPerson, serviceClient.EndGetPerson, 1, null); Assert.That(person, Is.Not.Null); var nullCollection = await serviceClient.ListPersonsAsync(-1); Assert.IsNull(nullCollection); var nullObject = serviceClient.GetPerson(-1); Assert.IsNull(nullObject); }
public long GetRecipientListId(string mailId) { var clientFactory = new ServiceClientFactory(); var mailIdClient = clientFactory.GetMailIdClient(); return(mailIdClient.getRecipientListId(_campaignToken.GetToken(), mailId)); }
public async void RequestGetsResponseFromServer() { var clientFactory = new ServiceClientFactory(new SimpleClient(new ServiceFactory(this.resolver))); var serviceClient = clientFactory.CreateServiceClient <ITestService2>(); //Synchronous Assert.That(serviceClient.GetPerson(1), Is.Not.Null); //Asynchronous task based var persons = await serviceClient.ListPersonsAsync(5); Assert.That(persons, Is.Not.Null); Assert.AreEqual(5, persons.Count()); //Asynchronous IAsyncResult based , awaiting with Task var person = await Task.Factory.FromAsync <int, Person>(serviceClient.BeginGetPerson, serviceClient.EndGetPerson, 1, null); Assert.That(person, Is.Not.Null); var nullCollection = await serviceClient.ListPersonsAsync(-1); Assert.IsNull(nullCollection); var nullObject = serviceClient.GetPerson(-1); Assert.IsNull(nullObject); }
public async void AsyncClientMethodsTest() { var serializerFactory = new MessagePackSerializerFactory(); var serviceClientFactory = new ServiceClientFactory(new LoggerStub()); using (var _ = GetTestService(serializerFactory)) { using (var client = serviceClientFactory.CreateServiceClient <ITestService>( "localhost", serializerFactory)) { var myHashcode = await client.ServiceInstance.GetHashCodeOfMeAsync(SerializableObject.GetTestInstance()); Assert.Equal(SerializableObject.TestInt, myHashcode); var constructedObject = await client.ServiceInstance.ConstructObjectAsync( SerializableObject.TestInt, SerializableObject.TestString, SerializableObject.TestDouble); Assert.NotNull(constructedObject); Assert.Equal(SerializableObject.TestInt, constructedObject.IntProperty); Assert.Equal(SerializableObject.TestString, constructedObject.StringProperty); Assert.Equal(SerializableObject.TestDouble, constructedObject.NestedObject.DoubleProperty); var(count, objects) = await client.ServiceInstance.GetObjectsAsync(1, 1); Assert.Equal(2, count); constructedObject = objects.Single(); Assert.Equal(SerializableObject.TestInt, constructedObject.IntProperty); Assert.Equal(SerializableObject.TestString, constructedObject.StringProperty); Assert.Equal(SerializableObject.TestDouble, constructedObject.NestedObject.DoubleProperty); } } }
/// <summary> /// Updates Alert on CustomerExtention table /// </summary> /// <remarks>Used only for China DO System</remarks> /// <param name="distributorId">The distributor identifier.</param> public static bool UpdateAlertCustomerExtention(string distributorId) { var result = false; var proxy = ServiceClientProvider.GetDistributorServiceProxy(); try { var request = new UpdateAlertCustomerExtentionRequest_V01 { DistributorId = distributorId, }; var response = proxy.UpdateAlertCustomerExtention(new UpdateAlertCustomerExtentionRequest1(request)).UpdateAlertCustomerExtentionResult; if (response != null && response.Status == ServiceResponseStatusType.Success) { result = true; } } catch (Exception ex) { ExceptionPolicy.HandleException( new Exception(string.Format("Error in DistributorProvider.UpdateAlertCustomerExtention, for DS id: {0}; error msg: {1}", distributorId, ex)), ProviderPolicies.SYSTEM_EXCEPTION); } finally { ServiceClientFactory.Dispose(proxy); } return(result); }
public void IntegrationTestOfFactory() { var calculator = new ServiceClientFactory().CreateClient<ICalculator>(); calculator.Add(4, 5); calculator.Add(40, 50); calculator.Add(1, 8); }
public static OrderServiceClient GetOrderServiceProxy() { return(ServiceClientFactory.CreateProxy <OrderServiceClient, IOrderService>( Settings.GetRequiredAppSetting("IAGlobalOrderingQuoteUrl"), Settings.GetRequiredAppSetting("IAGlobalOrderingQuoteSecureUrl", string.Empty), true)); }
public void CanCreateClient() { var factory = new ServiceClientFactory(new Mock<IClient>().Object); var serviceClient = factory.CreateServiceClient<ITestService>(); Assert.That(serviceClient, Is.Not.Null); }
public void SetUp() { _miaEnvConfiguration = new MiaEnvsConfigurationsImpl { USERID_HEADER_KEY = "useridkey", USER_PROPERTIES_HEADER_KEY = "userpropskey", GROUPS_HEADER_KEY = "groupskey", CLIENTTYPE_HEADER_KEY = "clienttypekey", BACKOFFICE_HEADER_KEY = "backofficekey", MICROSERVICE_GATEWAY_SERVICE_NAME = "gateway-name" }; _serviceClientFactory = new ServiceClientFactory(_miaEnvConfiguration); var miaHeaders = new HeaderDictionary { { "useridkey", "_" }, { "userpropskey", "_" }, { "groupskey", "_" }, { "clienttypekey", "_" }, { "backofficekey", "_" }, { "gateway-name", "bar" }, }; var miaHeadersPropagator = new MiaHeadersPropagator(miaHeaders, _miaEnvConfiguration); ServiceClientFactory.SetMiaHeaders(miaHeadersPropagator); }
public async void TestSendAndReceiveWithPoller() { var resolver = new DependencyResolver(); using (var broker = new ZmqPollBroker(this.zmqContext, ClientInboundAddress, ServerInboundAddress)) { broker.Listen(); using (var server = new ZmqPollServer(this.zmqContext, ServerInboundAddress, new ServiceFactory(resolver))) { server.Listen(); using (var client = new ZmqPollClient(this.zmqContext, ClientInboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); Assert.That(serviceClient.GetPerson(1), Is.Not.Null); var persons = await serviceClient.ListPersonsAsync(5); Assert.That(persons, Is.Not.Null); Assert.AreEqual(5, persons.Count()); var nullCollection = await serviceClient.ListPersonsAsync(-1); Assert.IsNull(nullCollection); var nullObject = serviceClient.GetPerson(-1); Assert.IsNull(nullObject); } } } }
//public static OrderServiceClient GetOrderServiceProxy() //{ // return ServiceClientFactory.CreateProxy<OrderServiceClient, IOrderService>( // Settings.GetRequiredAppSetting("IAGlobalOrderingQuoteUrl"), // Settings.GetRequiredAppSetting("IAGlobalOrderingQuoteSecureUrl", string.Empty), // true); //} public static SubmitOrderClient GetSubmitOrderProxy() { return(ServiceClientFactory.CreateProxy <SubmitOrderClient, SubmitOrder>( Settings.GetRequiredAppSetting("IAGlobalOrderingUrl"), Settings.GetRequiredAppSetting("IAGlobalOrderingSecureUrl", string.Empty), true)); }
//public static CatalogInterfaceClient GetCatalogServiceProxy() //{ // return ServiceClientFactory.CreateProxy<CatalogInterfaceClient, ICatalogInterface>( // Settings.GetRequiredAppSetting("IAGlobalOrderingCatalogUrl"), // Settings.GetRequiredAppSetting("IAGlobalOrderingCatalogSecureUrl", string.Empty), // true); //} public static ShoppingCartServiceClient GetShoppingCartServiceProxy() { return(ServiceClientFactory.CreateProxy <ShoppingCartServiceClient, IShoppingCartService>( Settings.GetRequiredAppSetting("IAShoppingCartUrl"), Settings.GetRequiredAppSetting("IAShoppingCartSecureUrl", string.Empty), true)); }
public static Inbox_PortTypeClient GetEmailPublisherServiceProxy() { return(ServiceClientFactory.CreateProxy <EmailPublisherSR.Inbox_PortTypeClient, EmailPublisherSR.Inbox_PortType>( Settings.GetRequiredAppSetting("IAEmailPublisherV03Url"), Settings.GetRequiredAppSetting("IAEmailPublisherV03SecureUrl", string.Empty), true)); }
public static MobileAnalyticsClient GetMobileAnalyticsServiceProxy() { return(ServiceClientFactory.CreateProxy <MobileAnalyticsClient, MobileAnalyticsSvc.IMobileAnalytics>( Settings.GetRequiredAppSetting("IAMobileAnalyticsUrl"), Settings.GetRequiredAppSetting("IAMobileAnalyticsUrlSecureUrl", string.Empty), true)); }
public static AddressValidation_PortTypeClient GetAddressValidationServiceProxy() { return(ServiceClientFactory.CreateProxy <AddressValidation_PortTypeClient, AddressValidation_PortType>( Settings.GetRequiredAppSetting("IALegacyAddressValidationV02Url"), Settings.GetRequiredAppSetting("IALegacyAddressValidationV02SecureUrl", string.Empty), true)); }
public static ShippingMexicoSVC.ShippingClient GetMexicoShippingServiceProxy() { return(ServiceClientFactory.CreateProxy <ShippingMexicoSVC.ShippingClient, ShippingMexicoSVC.IShipping>( Settings.GetRequiredAppSetting("IAShippingMexicoUrl"), Settings.GetRequiredAppSetting("IAShippingMexicoSecureUrl", string.Empty), true)); }
public static ChinaShippingClient GetChinaShippingServiceProxy() { return(ServiceClientFactory.CreateProxy <ChinaShippingClient, IChinaShipping>( Settings.GetRequiredAppSetting("IAChinaShippingUrl"), Settings.GetRequiredAppSetting("IAChinaShippingSecureUrl", string.Empty), true)); }
public bool IsCouponUsed(long couponBlockId, string couponCode) { var clientFactory = new ServiceClientFactory(); var couponClient = clientFactory.GetCouponCodeWebserviceClient(); return(couponClient.isUsed(_campaignToken.GetToken(), couponBlockId, couponCode)); }
//public static ChinaInterfaceClient GetChinaOrderServiceProxy() //{ // return ServiceClientFactory.CreateProxy<ChinaInterfaceClient, IChinaInterface>( // Settings.GetRequiredAppSetting("IAChinaOrderUrl"), // Settings.GetRequiredAppSetting("IAChinaOrderSecureUrl", string.Empty), // true); //} public static CommunicationServiceClient GetCommunicationServiceProxy() { return(ServiceClientFactory.CreateProxy <CommunicationServiceClient, ICommunicationService>( Settings.GetRequiredAppSetting("IACommunicationUrl"), Settings.GetRequiredAppSetting("IACommunicationSecureUrl", string.Empty), true)); }
public void Setup() { _mockMiaEnvConfig = new MiaEnvConfiguration { USERID_HEADER_KEY = "userid", USER_PROPERTIES_HEADER_KEY = "userproperties", GROUPS_HEADER_KEY = "groups", CLIENTTYPE_HEADER_KEY = "clienttype", BACKOFFICE_HEADER_KEY = "isbackoffice", MICROSERVICE_GATEWAY_SERVICE_NAME = "gateway-name" }; _mockHeaderDictionary = new HeaderDictionary { { "userid", "user" }, { "userproperties", "props" }, { "groups", "groups" }, { "clienttype", "client" }, { "isbackoffice", "true" }, { "gateway-name", "gateway" } }; _httpContext = new DefaultHttpContext();; var miaHeadersPropagator = new MiaHeadersPropagator(_mockHeaderDictionary, _mockMiaEnvConfig); _httpContext.Items = new Dictionary <object, object> { { "MiaHeadersPropagator", miaHeadersPropagator } }; _mockServiceClientFactory = new ServiceClientFactory(_mockMiaEnvConfig); _mockDecoratorResponseFactory = new DecoratorResponseFactory(); }
public static DistributorSVC.DistributorServiceClient GetDistributorServiceProxyChina() { return(ServiceClientFactory.CreateProxy <DistributorSVC.DistributorServiceClient, DistributorSVC.IDistributorService>( Settings.GetRequiredAppSetting("IADistributorUrl"), Settings.GetRequiredAppSetting("IADistributorSecureUrl", string.Empty), true)); }
static void Main(string[] args) { var logger = new LoggerStub(); // using (var logger = new ConsoleLoggerWrapper(new LoggerStub())) // { Helpers.LogCurrentMemoryUsage(logger); // Console.ReadLine(); var messagePackSerializerFactory = new MessagePackSerializerFactory(); using (var testServiceClient = ServiceClientFactory.CreateServiceClient <ITestService>( "localhost", logger, messagePackSerializerFactory)) { using (var wcfTestServiceClient = CommonWcfComponents.ServiceClient <ITestService> .Create()) { Console.WriteLine("Test service client created."); RunTest(wcfTestServiceClient.Service, logger); Helpers.LogCurrentMemoryUsage(logger); Console.WriteLine("All requests send."); Console.ReadLine(); } } // } }
public static EventInterfaceClient GetEventServiceProxy() { return(ServiceClientFactory.CreateProxy <EventInterfaceClient, IEventInterface>( Settings.GetRequiredAppSetting("IAEventUrl"), Settings.GetRequiredAppSetting("IAEventSecureUrl", string.Empty), true)); }
public async void TestSendAndReceiveWithPoller() { var resolver = new DependencyResolver(); using (var broker = new ZmqPollBroker(this.zmqContext, ClientInboundAddress, ServerInboundAddress)) { broker.Listen(); using (var server = new ZmqPollServer(this.zmqContext, ServerInboundAddress, new ServiceFactory(resolver))) { server.Listen(); using (var client = new ZmqPollClient(this.zmqContext, ClientInboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient <ITestService2>(); Assert.That(serviceClient.GetPerson(1), Is.Not.Null); var persons = await serviceClient.ListPersonsAsync(5); Assert.That(persons, Is.Not.Null); Assert.AreEqual(5, persons.Count()); var nullCollection = await serviceClient.ListPersonsAsync(-1); Assert.IsNull(nullCollection); var nullObject = serviceClient.GetPerson(-1); Assert.IsNull(nullObject); } } } }
/// <summary> /// Creates an instance of a serviceclient and configures it to send an event notification. /// See: https://developer.github.com/webhooks/#payloads for specification /// </summary> private IServiceClient CreateServiceClient(SubscriptionRelayConfig relayConfig, string eventName, TimeSpan?timeout) { try { var client = ServiceClientFactory.Create(relayConfig.Config.Url); client.Timeout = timeout; client.RequestFilter = request => { request.ContentType = MimeTypes.Json; request.Headers.Remove(WebhookEventConstants.SecretSignatureHeaderName); request.Headers.Remove(WebhookEventConstants.RequestIdHeaderName); request.Headers.Remove(WebhookEventConstants.EventNameHeaderName); if (relayConfig.Config.ContentType.HasValue()) { request.ContentType = relayConfig.Config.ContentType; } if (relayConfig.Config.Secret.HasValue()) { request.Headers.Add(WebhookEventConstants.SecretSignatureHeaderName, CreateContentHmacSignature(request, relayConfig.Config.Secret)); } request.Headers.Add(WebhookEventConstants.RequestIdHeaderName, CreateRequestIdentifier()); request.Headers.Add(WebhookEventConstants.EventNameHeaderName, eventName); }; return(client); } catch (Exception ex) { logger.Error(@"Failed to connect to subscriber: {0}, this URL is not valid".Fmt(relayConfig.Config.Url), ex); return(null); } }
static void Main(string[] args) { var logger = new LoggerStub(); Helpers.LogCurrentMemoryUsage(logger); var serviceClientFactory = new ServiceClientFactory(logger); using (var testServiceClient = serviceClientFactory.CreateServiceClient <ITestService>( "localhost")) { Console.WriteLine("Test service client created."); // Warm up const int warmUpCallsCount = 5000; Enumerable .Range(0, warmUpCallsCount) .ParallelForEach(_ => SendRequestAndLogResult(testServiceClient.ServiceInstance, logger)); Console.WriteLine("Warmup done"); GC.Collect(2, GCCollectionMode.Forced); // Thread.Sleep(TimeSpan.FromSeconds(5)); const int callsCount = 10000; RunTests(() => TestAsyncOperations(testServiceClient.ServiceInstance, logger, callsCount), logger); Console.WriteLine("All requests send."); Console.ReadLine(); } }
public static Order_V02 GetOrderDetail(string orderNumber) { Order_V02 order = null; var proxy = ServiceClientProvider.GetOrderServiceProxy(); try { using (new OperationContextScope(proxy.InnerChannel)) { var req = new GetOrderDetailRequest_V01(); req.OrderNumber = orderNumber; req.Locale = Thread.CurrentThread.CurrentCulture.Name; var response = proxy.GetOrderDetail(new GetOrderDetailRequest1(req)).GetOrderDetailResult as GetOrderDetailResponse_V01; if (response != null) { return(response.Order); } } } catch (Exception ex) { WebUtilities.LogServiceExceptionWithContext(ex, proxy); } finally { ServiceClientFactory.Dispose(proxy); } return(order); }
private void BtnConnect_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(TbAddress.Text)) { return; } try { var serverProxy = new ServiceClientFactory <IServerEngine>().Create(TbAddress.Text); var result = serverProxy.Connect(); if (!result.Success) { return; } Hide(); var explorerWindow = new ExplorerWindow(serverProxy); explorerWindow.ShowDialog(); Show(); } catch { MessageBox.Show("Cannot connect to server", "Connection error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void MarkCouponAsUsed(long couponBlockId, string couponCode) { var clientFactory = new ServiceClientFactory(); var couponClient = clientFactory.GetCouponCodeWebserviceClient(); couponClient.markAsUsed(_campaignToken.GetToken(), couponBlockId, couponCode); }
public void CanCreateClient() { var factory = new ServiceClientFactory(new Mock <IClient>().Object); var serviceClient = factory.CreateServiceClient <ITestService>(); Assert.That(serviceClient, Is.Not.Null); }
public static CustomerOrderServiceClient GetCustomerOrderServiceProxy() { var trySecure = Settings.GetRequiredAppSetting("WcfSslEnabled", true); return(ServiceClientFactory.CreateProxy <CustomerOrderServiceClient, ICustomerOrderService>( Settings.GetRequiredAppSetting("IACustomerOrderUrl"), Settings.GetRequiredAppSetting("IACustomerOrderSecureUrl", string.Empty), trySecure)); }
public static PaymentGatewayBridgeInterfaceClient GetPaymentGatewayBridgeProxy() { var trySecure = Settings.GetRequiredAppSetting("WcfSslEnabled", true); return(ServiceClientFactory.CreateProxy <PaymentGatewayBridgeInterfaceClient, IPaymentGatewayBridgeInterface>( Settings.GetRequiredAppSetting("IAPaymentGatewayBridgeUrl"), Settings.GetRequiredAppSetting("IAPaymentGatewayBridgeSecureUrl", string.Empty), trySecure)); }
public bool IsCouponAssigned(string userEmail, long couponBlockId, string couponCode) { var clientFactory = new ServiceClientFactory(); var couponClient = clientFactory.GetCouponCodeWebserviceClient(); var assignedRecipientId = couponClient.getAssignedRecipientId(_campaignToken.GetToken(), couponBlockId, couponCode); return(userEmail == assignedRecipientId); }
/// <summary> /// Create a service client using the bus as the response endpoint for all requests and control traffic. /// </summary> /// <param name="bus">The bus instance</param> /// <param name="timeout">The default timeout for requests</param> /// <returns></returns> public static IClientFactory CreateServiceClient(this IBus bus, RequestTimeout timeout = default) { var clientFactory = bus.CreateClientFactory(timeout); var serviceClient = new ServiceClient(clientFactory); var serviceClientFactory = new ServiceClientFactory(serviceClient, clientFactory); return(serviceClientFactory); }
public void should_return_IClientChannel() { var serviceClientFactory = new ServiceClientFactory(); var calculator = serviceClientFactory.CreateClient<ICalculator>(); IClientChannel clientChannel = calculator as IClientChannel; Assert.NotNull(clientChannel); }
public void CanUseClientWithNonComplexTypes() { var clientMock = new Mock<IClient>(); this.SetupClient(clientMock); var factory = new ServiceClientFactory(clientMock.Object); var serviceClient = factory.CreateServiceClient<ITestService>(); var sum = serviceClient.Sum(10, 5); Assert.That(sum, Is.EqualTo(15)); var concatenated = serviceClient.Concatenate("10", "01"); Assert.That(concatenated.Result, Is.EqualTo("1001")); }
public async void TestSendAndReceiveExceptions() { var resolver = new DependencyResolver(); using (var broker = new ZmqBroker(this.zmqContext, ClientInboundAddress, ClientOutboundAddress, ServerInboundAddress, ServerOutboundAddress)) { broker.Listen(); using (var server = new ZmqServer(this.zmqContext, ServerInboundAddress, ServerOutboundAddress, new ServiceFactory(resolver))) { server.Listen(); using (var client = new ZmqClient(this.zmqContext, ClientInboundAddress, ClientOutboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService>(); //Synchronous var err = Assert.Catch(async () => await serviceClient.FailAsync()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous task based err = Assert.Catch(() => serviceClient.Fail()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous IAsyncResult based , awaiting with Task err = Assert.Catch(async () => await Task.Factory.FromAsync(serviceClient.BeginFail, serviceClient.EndFail, null)); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Timeout exceptions var factoryWithTimeout = new ServiceClientFactory(client); var serviceClientWithTimeout = factoryWithTimeout.CreateServiceClient<ITestService>(50); //50ms Assert.Throws<TimeoutException>(async () => await serviceClientWithTimeout.ReplyAfter(1000)); } } } }
public void RequestGetsExceptionFromServer() { var clientFactory = new ServiceClientFactory(new SimpleClient(new ServiceFactory(this.resolver))); var serviceClient = clientFactory.CreateServiceClient<ITestService>(); //Synchronous var err = Assert.Catch(async () => await serviceClient.FailAsync()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous task based err = Assert.Catch(() => serviceClient.Fail()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous IAsyncResult based , awaiting with Task err = Assert.Catch(async () => await Task.Factory.FromAsync(serviceClient.BeginFail, serviceClient.EndFail, null)); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); }
//[TestCase(5, 1000000)] public async void TestLoadBalancing(int nServers, int nMsgs) { var resolver = new DependencyResolver(); var servers = Enumerable.Range(0, nServers) .Select(i => new RedisServer(new RedisConnection(RedisHost, RedisPort, RedisPassword), ServerQueue, new ServiceFactory(resolver))) .ToArray(); try { foreach (var server in servers) server.Listen(); using (var client = new RedisClient(new RedisConnection(RedisHost, RedisPort, RedisPassword), ClientQueue, ServerQueue)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); var tasks = Enumerable.Range(0, nMsgs) //.Select(i => serviceClient.SumAsync(5, 15)) .Select(i => serviceClient.ListPersonsAsync(7)) .ToArray(); await Task.WhenAll(tasks); Assert.True(tasks.All(t => t.Result.Count() == 7)); } } finally { foreach (var server in servers) server.Dispose(); } }
//[TestCase(5, 1000000)] public async void TestLoadBalancingWithPoll(int nServers, int nMsgs) { var resolver = new DependencyResolver(); using (var broker = new ZmqPollBroker(this.zmqContext, ClientInboundAddress, ServerInboundAddress)) { broker.Listen(); var servers = Enumerable.Range(0, nServers) .Select(i => new ZmqPollServer(this.zmqContext, ServerInboundAddress, new ServiceFactory(resolver))) .ToArray(); try { foreach (var server in servers) server.Listen(); using (var client = new ZmqPollClient(this.zmqContext, ClientInboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); var tasks = Enumerable.Range(0, nMsgs) //.Select(i => serviceClient.SumAsync(5, 15)) .Select(i => serviceClient.ListPersonsAsync(7)) .ToArray(); await Task.WhenAll(tasks); Assert.True(tasks.All(t => t.Result.Count() == 7)); } } finally { foreach (var server in servers) server.Dispose(); } } }
public async void TestSendAndReceiveExceptions() { var resolver = new DependencyResolver(); using (var server = new RedisServer(new RedisConnection(RedisHost, RedisPort, RedisPassword), ServerQueue, new ServiceFactory(resolver))) { server.Listen(); using (var client = new RedisClient(new RedisConnection(RedisHost, RedisPort, RedisPassword), ClientQueue, ServerQueue)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService>(); //Synchronous var err = Assert.Catch(async () => await serviceClient.FailAsync()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous task based err = Assert.Catch(() => serviceClient.Fail()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous IAsyncResult based , awaiting with Task err = Assert.Catch(async () => await Task.Factory.FromAsync(serviceClient.BeginFail, serviceClient.EndFail, null)); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Timeout exceptions var factoryWithTimeout = new ServiceClientFactory(client); var serviceClientWithTimeout = factoryWithTimeout.CreateServiceClient<ITestService>(50); //50ms Assert.Throws<TimeoutException>(async () => await serviceClientWithTimeout.ReplyAfter(1000)); } } }
public void CanHandleTimeouts() { var clientMock = new Mock<IClient>(); this.SetupClient(clientMock, 1000); //takes 100ms to reply var factory = new ServiceClientFactory(clientMock.Object); var serviceClient = factory.CreateServiceClient<ITestService>(50); //50ms timeout Assert.Throws<TimeoutException>(() => serviceClient.Sum(10, 5)); }