public static void Init(ILogger logger = null, IAssert assert = null, TimeoutSettings timeouts = null, IDriver <IWebDriver> driverFactory = null) { DriverFactory = driverFactory ?? new WebDriverFactory(); Asserter = assert ?? new WebAssert(); Timeouts = timeouts ?? new WebTimeoutSettings(); Logger = logger ?? new LogAgregator(new NUnitLogger(), new Log4Net()); MapInterfaceToElement.Init(DefaultInterfacesMap); }
internal CompositionRoot( ISessionStorage sessionStorage, CookieSettings cookieSettings, TimeoutSettings timeoutSettings, ISessionIdGenerator sessionIdGenerator) { _sessionStorage = sessionStorage; _cookieSettings = cookieSettings; _timeoutSettings = timeoutSettings; _sessionIdGenerator = sessionIdGenerator; }
public byte[] Process(Type serviceInterface, string pathSeparatedBySlashes, string serviceScope, byte[] data, TimeoutSettings timeoutSettings) { try { return ProcessAsync(serviceInterface, pathSeparatedBySlashes, serviceScope, data, timeoutSettings).Result; } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1) throw ex.InnerExceptions[0]; throw; } }
public static void InitFromProperties(ILogger logger = null, IAssert assert = null, TimeoutSettings timeouts = null, IDriver <IWebDriver> driverFactory = null) { Init(logger, assert, timeouts, driverFactory); JDISettings.InitFromProperties(); FillFromSettings(p => Domain = p, "domain"); FillFromSettings(p => DriverFactory.DriverPath = p, "drivers.folder"); // var isMultithread = Default["multithread"].ToString(); // TODO /*Logger = isMultithread.Equals("true") || isMultithread.Equals("1") * ? new TestNGLogger("JDI Logger", s -> String.format("[ThreadId: {0}] {0}", Thread.currentThread().getId(), s)) * : new TestNGLogger("JDI Logger");*/ }
public void UsesProvidedValues() { var idleTimeout = TimeSpan.FromDays(1); var absoluteTimeout = TimeSpan.FromDays(2); var expectedSettings = new TimeoutSettings(idleTimeout, absoluteTimeout); var settings = new TimeoutSettingsBuilder() .IdleTimeout(idleTimeout) .AbsoluteTimeout(absoluteTimeout) .Build(); Assert.Equal(expectedSettings, settings); }
public void TrivialWithScopeAndTimeout() { var timeoutSettings = new TimeoutSettings(); var proxy = factory.CreateProxy <ITrivialService>()(requestProcessor, "my scope", timeoutSettings); requestProcessor.Process(null, null, null, null, null).ReturnsForAnyArgs((byte[])null); proxy.DoSomething(); var arguments = requestProcessor.ReceivedCalls().Single().GetArguments(); Assert.That(arguments[0], Is.EqualTo(typeof(ITrivialService))); Assert.That(arguments[1], Is.EqualTo("TrivialService/DoSomething")); Assert.That(arguments[2], Is.EqualTo("my scope")); Assert.That(arguments[3], Is.Null); Assert.That(arguments[4], Is.EqualTo(timeoutSettings)); }
public static T GetService <T>(this IRpcClient rpcClient, TimeoutSettings timeoutSettings) where T : class { return(rpcClient.GetService <T>(null, timeoutSettings)); }
public MyServiceProxy(IOutgoingRequestProcessor processor, string scope, TimeoutSettings timeoutSettings) { Processor = processor; Scope = scope; TimeoutSettings = timeoutSettings; }
public MyServiceProxy(IOutgoingMethodCallProcessor processor, string scope, TimeoutSettings timeoutSettings) { Processor = processor; Scope = scope; TimeoutSettings = timeoutSettings; }
public T GetForScope(string scope, TimeoutSettings timeoutSettings) { return(scopedProxies.GetOrAdd(new ProxyKey(scope, timeoutSettings), s => constructor(processor, scope, timeoutSettings))); }
public CompositionRootBuilder TimeoutSettings(TimeoutSettings timeoutSettings) => ShallowClone(timeoutSettings: timeoutSettings);
public byte[] Process(Type serviceInterface, string pathSeparatedBySlashes, string serviceScope, byte[] data, TimeoutSettings timeoutSettings) { ServicePath path; if (!ServicePath.TryParse(pathSeparatedBySlashes, out path)) { throw new InvalidOperationException(string.Format("'{0}' is not a valid service path", pathSeparatedBySlashes)); } var serviceName = serviceInterface.GetServiceName(); var endPoint = topology.GetEndPoint(serviceName, serviceScope); try { string protocol = endPoint.Protocol.ToLower(); if (protocol.Equals("http")) { return(ProcessAsync(serviceInterface, pathSeparatedBySlashes, serviceScope, data, timeoutSettings).Result); } else if (protocol.Equals("tcp")) { var sender = requestSenderContainer.GetSender(endPoint.Protocol); var request = new Request(path, serviceScope, data); var response = sender.Send(endPoint.Host, endPoint.Port, request, -1); switch (response.Status) { case ResponseStatus.Ok: return(response.Data); case ResponseStatus.BadRequest: throw new ServiceTopologyException(string.Format("'{0}' seems to be a bad request for {1}", pathSeparatedBySlashes, endPoint)); case ResponseStatus.InternalServerError: throw new Exception(string.Format("'{0}' request caused {1} to encounter an internal server error(maybe timeout)", pathSeparatedBySlashes, endPoint)); case ResponseStatus.Exception: { Exception remoteException; if (exceptionCodec.TryDecodeSingle(response.Data, out remoteException)) { throw remoteException; } throw new ServiceNetworkException( string.Format("'{0}' request caused {1} to return an unknown exception", pathSeparatedBySlashes, endPoint)); } case ResponseStatus.ServiceNotFound: throw new ServiceTopologyException(string.Format("'{0}' service was not present at {1}", serviceName, endPoint)); default: throw new Exception(string.Format("'{0}' request caused {1} to return an undefined status '{2}'", pathSeparatedBySlashes, endPoint, (int)response.Status)); } } return(null); } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } throw; } }
public byte[] Process(Type serviceInterface, string pathSeparatedBySlashes, string serviceScope, byte[] data, TimeoutSettings timeoutSettings) { try { return(ProcessAsync(serviceInterface, pathSeparatedBySlashes, serviceScope, data, timeoutSettings).Result); } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } throw; } }
public ProxyKey(string scope, TimeoutSettings timeoutSettings) { Scope = scope; TimeoutSettings = timeoutSettings; }
public async Task<byte[]> ProcessAsync(Type serviceInterface, string pathSeparatedBySlashes, string serviceScope, byte[] data, TimeoutSettings timeoutSettings) { ServicePath path; if (!ServicePath.TryParse(pathSeparatedBySlashes, out path)) throw new InvalidOperationException(string.Format("'{0}' is not a valid service path", pathSeparatedBySlashes)); var serviceName = serviceInterface.GetServiceName(); var endPoint = topology.GetEndPoint(serviceName, serviceScope); var sender = requestSenderContainer.GetSender(endPoint.Protocol); var request = new Request(path, serviceScope, data); timeoutSettings = timeoutSettings ?? TimeoutSettings.NoTimeout; bool hasNetworkTimeout = timeoutSettings.MaxMilliseconds != -1 && timeoutSettings.MaxMilliseconds != 0 && timeoutSettings.MaxMilliseconds != int.MaxValue; var startTime = DateTime.Now; int remainingTriesMinusOne = timeoutSettings.NotReadyRetryCount; while (remainingTriesMinusOne >= 0) { remainingTriesMinusOne--; Response response; try { int? networkTimeout = hasNetworkTimeout ? timeoutSettings.MaxMilliseconds - (DateTime.Now - startTime).Milliseconds : (int?)null; response = await sender.SendAsync(endPoint.Host, endPoint.Port, request, networkTimeout); } catch (TimeoutException ex) { throw new ServiceTimeoutException(request, timeoutSettings.MaxMilliseconds, ex); } catch (Exception ex) { throw new ServiceNetworkException(string.Format("Sending a '{0}' request to {1} failed", pathSeparatedBySlashes, endPoint), ex); } switch (response.Status) { case ResponseStatus.Ok: return response.Data; case ResponseStatus.NotReady: if (remainingTriesMinusOne >= 0) await Task.Delay(timeoutSettings.NotReadyRetryMilliseconds); break; case ResponseStatus.BadRequest: throw new ServiceTopologyException(string.Format("'{0}' seems to be a bad request for {1}", pathSeparatedBySlashes, endPoint)); case ResponseStatus.ServiceNotFound: throw new ServiceTopologyException(string.Format("'{0}' service was not present at {1}", serviceName, endPoint)); case ResponseStatus.Exception: { Exception remoteException; if (exceptionCodec.TryDecodeSingle(response.Data, out remoteException)) throw remoteException; throw new ServiceNetworkException( string.Format("'{0}' request caused {1} to return an unknown exception", pathSeparatedBySlashes, endPoint)); } case ResponseStatus.InternalServerError: throw new Exception(string.Format("'{0}' request caused {1} to encounter an internal server error", pathSeparatedBySlashes, endPoint)); default: throw new Exception(string.Format("'{0}' request caused {1} to return an undefined status '{2}'", pathSeparatedBySlashes, endPoint, (int)response.Status)); } } throw new ServiceTimeoutException(request, timeoutSettings.NotReadyRetryCount, timeoutSettings.NotReadyRetryMilliseconds); }
public static void InitFromProperties(ILogger logger = null, IAssert assert = null, TimeoutSettings timeouts = null, IDriver <IWebDriver> driverFactory = null) { Init(logger, assert, timeouts, driverFactory); JDISettings.InitFromProperties(); FillFromSettings(p => Domain = p, "Domain"); FillFromSettings(p => DriverFactory.DriverPath = p, "DriversFolder"); FillFromSettings(p => GetLatestDriver = p.ToLower().Equals("true") || p.ToLower().Equals("1"), "GetLatest"); // FillFromSettings(p => DriverFactory.DriverVersion = p, "DriversVersion"); // fillAction(p->getDriverFactory().getLatestDriver = // p.toLowerCase().equals("true") || p.toLowerCase().equals("1"), "driver.getLatest"); // fillAction(p->asserter.doScreenshot(p), "screenshot.strategy"); FillFromSettings(p => { p = p.ToLower(); if (p.Equals("soft")) { p = "any,multiple"; } if (p.Equals("strict")) { p = "visible,single"; } if (p.Split(',').Length != 2) { return; } var parameters = p.Split(',').ToList(); if (parameters.Contains("visible") || parameters.Contains("displayed")) { WebDriverFactory.ElementSearchCriteria = el => el.Displayed; } if (parameters.Contains("any") || parameters.Contains("all")) { WebDriverFactory.ElementSearchCriteria = el => el != null; } if (parameters.Contains("single") || parameters.Contains("displayed")) { OnlyOneElementAllowedInSearch = true; } if (parameters.Contains("multiple") || parameters.Contains("displayed")) { OnlyOneElementAllowedInSearch = false; } }, "SearchElementStrategy"); FillFromSettings(p => { string[] split = null; if (p.Split(',').Length == 2) { split = p.Split(','); } if (p.ToLower().Split('x').Length == 2) { split = p.ToLower().Split('x'); } if (split != null) { BrowserSize = new Size(Parse(split[0]), Parse(split[1])); } }, "BrowserSize"); }
public byte[] Process(Type serviceInterface, string pathSeparatedBySlashes, string serviceScope, byte[] data, TimeoutSettings timeoutSettings) { ServicePath path; if (!ServicePath.TryParse(pathSeparatedBySlashes, out path)) { throw new InvalidOperationException(string.Format("'{0}' is not a valid service path", pathSeparatedBySlashes)); } var serviceName = serviceInterface.GetServiceName(); var endPoint = topology.GetEndPoint(serviceName, serviceScope); var sender = requestSenderContainer.GetSender(endPoint.Protocol); var request = new Request(path, serviceScope, data); timeoutSettings = timeoutSettings ?? TimeoutSettings.NoTimeout; bool hasNetworkTimeout = timeoutSettings.MaxMilliseconds != -1 && timeoutSettings.MaxMilliseconds != 0 && timeoutSettings.MaxMilliseconds != int.MaxValue; var startTime = DateTime.Now; int remainingTriesMinusOne = timeoutSettings.NotReadyRetryCount; while (remainingTriesMinusOne >= 0) { remainingTriesMinusOne--; Response response; try { int?networkTimeout = hasNetworkTimeout ? timeoutSettings.MaxMilliseconds - (DateTime.Now - startTime).Milliseconds : (int?)null; response = sender.Send(endPoint.Host, endPoint.Port, request, networkTimeout); } catch (TimeoutException ex) { throw new ServiceTimeoutException(request, timeoutSettings.MaxMilliseconds, ex); } catch (Exception ex) { throw new ServiceNetworkException(string.Format("Sending a '{0}' request to {1} failed", pathSeparatedBySlashes, endPoint), ex); } switch (response.Status) { case ResponseStatus.Ok: return(response.Data); case ResponseStatus.NotReady: if (remainingTriesMinusOne >= 0) { Thread.Sleep(timeoutSettings.NotReadyRetryMilliseconds); } break; case ResponseStatus.BadRequest: throw new ServiceTopologyException(string.Format("'{0}' seems to be a bad request for {1}", pathSeparatedBySlashes, endPoint)); case ResponseStatus.ServiceNotFound: throw new ServiceTopologyException(string.Format("'{0}' service was not present at {1}", serviceName, endPoint)); case ResponseStatus.Exception: { Exception remoteException; if (exceptionCodec.TryDecodeSingle(response.Data, out remoteException)) { throw remoteException; } throw new ServiceNetworkException( string.Format("'{0}' request caused {1} to return an unknown exception", pathSeparatedBySlashes, endPoint)); } case ResponseStatus.InternalServerError: throw new Exception(string.Format("'{0}' request caused {1} to encounter an internal server error", pathSeparatedBySlashes, endPoint)); default: throw new ArgumentOutOfRangeException("response.Status"); } } throw new ServiceTimeoutException(request, timeoutSettings.NotReadyRetryCount, timeoutSettings.NotReadyRetryMilliseconds); }
public T GetProxy <T>(string scope, TimeoutSettings timeoutSettings) where T : class { var set = (ProxySet <T>)proxySets.GetOrAdd(typeof(T), t => new ProxySet <T>(processor, factory.CreateProxyClass <T>())); return(set.GetForScope(scope, timeoutSettings)); }