private LightStepHttpClient GetClient(TransportOptions t = TransportOptions.BinaryProto) { var satelliteOptions = new SatelliteOptions("localhost", 80, true); var tracerOptions = new Options("TEST").WithSatellite(satelliteOptions).WithAutomaticReporting(false).WithTransport(t); return(new LightStepHttpClient("http://localhost:80", tracerOptions)); }
private SplunkTracingHttpClient GetClient(TransportOptions t = TransportOptions.JsonHttp) { var collectorOptions = new CollectorOptions("localhost", 8088, true); var tracerOptions = new Options("TEST").WithCollector(collectorOptions).WithAutomaticReporting(false).WithTransport(t); return(new SplunkTracingHttpClient("http://localhost:80", tracerOptions)); }
public void KeepAliveThrowsWhenZero() { // Arrange var config = new TransportOptions(); // Assert Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.KeepAlive = TimeSpan.FromSeconds(0)); }
public void SetReadOnly_Test() { var options = new TransportOptions(); Assert.False(options.IsReadOnly); options.SetReadOnly(); Assert.True(options.IsReadOnly); }
public void DisconnectTimeoutThrowsWhenZero() { // Arrange var config = new TransportOptions(); // Assert Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.DisconnectTimeout = TimeSpan.FromSeconds(0)); }
public void DisconnectTimeoutThrowsWhenNegative() { // Arrange var config = new TransportOptions(); // Assert Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.KeepAlive = TimeSpan.FromSeconds(-1)); }
protected OutgoingServiceBase( ILogger <OutgoingServiceBase> logger, IOptions <TransportOptions> options, IConnectionsRepository connections) { _logger = logger; _options = options.Value; _connections = connections; }
public void ValidConfiguration_Test() { var options = new TransportOptions(); var valid = options.ValidConfiguration(); Assert.True(valid.Valid); options.SetReadOnly(); valid = options.ValidConfiguration(); Assert.True(valid.Valid); }
/// <inheritdoc/> public override async Task <IList <string> > PublishAsync <TEvent>(IList <EventContext <TEvent> > events, EventRegistration registration, DateTimeOffset?scheduled = null, CancellationToken cancellationToken = default) { // log warning when trying to publish scheduled message if (scheduled != null) { Logger.LogWarning("Amazon Kinesis does not support delay or scheduled publish"); } using var scope = CreateScope(); var records = new List <PutRecordsRequestEntry>(); // work on each event foreach (var @event in events) { using var ms = new MemoryStream(); await SerializeAsync(body : ms, @event : @event, registration : registration, scope : scope, cancellationToken : cancellationToken); var record = new PutRecordsRequestEntry { Data = ms, PartitionKey = TransportOptions.PartitionKeyResolver(@event), }; records.Add(record); } // prepare the request var streamName = registration.EventName; var request = new PutRecordsRequest { StreamName = streamName, Records = records, }; // send the events Logger.LogInformation("Sending {EventsCount} messages to '{StreamName}'. Scheduled: {Scheduled}. Events:\r\n- {Ids}", events.Count, streamName, scheduled, string.Join("\r\n- ", events.Select(e => e.Id))); var response = await kinesisClient.PutRecordsAsync(request, cancellationToken); response.EnsureSuccess(); // Should we check for failed records and throw exception? // return the sequence numbers return(response.Records.Select(m => m.SequenceNumber.ToString()).ToList()); }
public void TopicTopicTimeToLiveIsDoubleTheDisconnectTimeoutWhenKeepAliveIsNull() { var config = new TransportOptions(); var random = new Random(); config.DisconnectTimeout = TimeSpan.FromSeconds(random.Next(6, 31536000)); // 12 seconds to a year config.KeepAlive = null; // Assert Assert.Equal(TimeSpan.FromTicks(config.DisconnectTimeout.Ticks * 2), config.TopicTtl()); }
public void HeartbeatIntervalIsHalfTheKeepAlive() { // Arrange var config = new TransportOptions(); var random = new Random(); config.KeepAlive = TimeSpan.FromSeconds(random.NextDouble() * 8 + 2); // 2 to 10 seconds // Assert Assert.Equal(TimeSpan.FromTicks(config.KeepAlive.Value.Ticks / 2), config.HeartbeatInterval()); }
/// <summary> /// Configuration to use kafka in Transport. /// </summary> /// <param name="options">Transport configuration options</param> /// <param name="configure">Provides programmatic configuration for the kafka .</param> /// <returns></returns> public static TransportOptions UseKafka(this TransportOptions options, Action <KafkaOptions> configure) { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } options.RegisterExtension(new KafkaTransportOptionsExtension(configure)); return(options); }
string GetQueryString() { if (TransportOptions.Count == 0) { return(""); } var queryString = string.Join("&", TransportOptions.Select(pair => $"{pair.Key}={pair.Value}")); return($"?{queryString}"); }
/// <summary> /// Initializes a new instance of the <see cref="EventBusHostedService"/> class. /// </summary> /// <param name="consumerClientFactory">The consumer client factory.</param> /// <param name="subscribers">The subscribers.</param> /// <param name="transportOptions">The transport options.</param> /// <exception cref="ArgumentNullException">subscribers</exception> public EventBusHostedService( IConsumerClientFactory consumerClientFactory, IServiceScopeFactory serviceScopeFactory, IOptions <TransportOptions> transportOptions) { _serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory)); _options = transportOptions.Value; //TODO think groups id _consumerClient = consumerClientFactory.Create(_options.DefaultGroup); }
/// <summary> /// Initializes a new instance of the <see cref="EventBusHostedService"/> class. /// </summary> /// <param name="consumerClientFactory">The consumer client factory.</param> /// <param name="subscribers">The subscribers.</param> /// <param name="transportOptions">The transport options.</param> /// <exception cref="ArgumentNullException">subscribers</exception> public EventBusHostedService( IConsumerClientFactory consumerClientFactory, IEnumerable <ISubscriber> subscribers, IOptions <TransportOptions> transportOptions) { _subscribers = subscribers ?? throw new ArgumentNullException(nameof(subscribers)); _options = transportOptions.Value; //TODO think groups id _consumerClient = consumerClientFactory.Create("group_1"); }
public void SettingDisconnectTimeoutSetKeepAliveToAThirdOfItself() { // Arrange var config = new TransportOptions(); var random = new Random(); config.DisconnectTimeout = TimeSpan.FromSeconds(random.Next(6, 31536000)); // 6 seconds to a year // Assert Assert.Equal(TimeSpan.FromTicks(config.DisconnectTimeout.Ticks / 3), config.KeepAlive); }
public void HeartbeatIntervalIsASixthOfTheDisconnectTimeoutIfTheKeepAliveIsNull() { // Arrange var config = new TransportOptions(); var random = new Random(); config.DisconnectTimeout = TimeSpan.FromSeconds(random.Next(6, 31536000)); // 6 seconds to a year config.KeepAlive = null; // Assert Assert.Equal(TimeSpan.FromTicks(config.DisconnectTimeout.Ticks / 6), config.HeartbeatInterval()); }
public void TopicTimeToLiveIsDoubleTheDisconnectAndKeepAliveTimeouts() { var config = new TransportOptions(); var random = new Random(); config.DisconnectTimeout = TimeSpan.FromSeconds(random.Next(12, 31536000)); // 12 seconds to a year config.KeepAlive = TimeSpan.FromTicks(config.DisconnectTimeout.Ticks / 6); // Set custom keep-alive to half the default // Assert Assert.Equal(TimeSpan.FromTicks(config.DisconnectTimeout.Ticks * 2 + config.KeepAliveTimeout().Value.Ticks * 2), config.TopicTtl()); }
public void DefaultValues() { // Arrange var config = new TransportOptions(); // Assert Assert.Equal(110, config.LongPolling.PollTimeout.TotalSeconds); Assert.Equal(30, config.DisconnectTimeout.TotalSeconds); Assert.Equal(10, config.KeepAlive.Value.TotalSeconds); Assert.Equal(20, config.KeepAliveTimeout().Value.TotalSeconds); Assert.Equal(5, config.HeartbeatInterval().TotalSeconds); Assert.Equal(100, config.TopicTtl().TotalSeconds); }
string GetQueryString() { var queryPart = string.Empty; if (TransportOptions?.Count > 0) { var queryString = string.Join("&", TransportOptions .Select(pair => $"{pair.Key}={pair.Value}")); queryString = $"?{queryString}"; } return(queryPart); }
/// <summary> /// Initializes and instance of the <see cref="TransportHeartbeat"/> class. /// </summary> /// <param name="serviceProvider">The <see cref="IDependencyResolver"/>.</param> public TransportHeartbeat(IOptions <SignalROptions> optionsAccessor, IPerformanceCounterManager counters, ILoggerFactory loggerFactory) { _transportOptions = optionsAccessor.Value.Transports; _counters = counters; _logger = loggerFactory.CreateLogger <TransportHeartbeat>(); // REVIEW: When to dispose the timer? _timer = new Timer(Beat, null, _transportOptions.HeartbeatInterval(), _transportOptions.HeartbeatInterval()); }
/// <summary> /// Send a WAAPI call to create a transport in Wwise. /// Subscribe to the ak.wwise.core.transport.stateChanged topic of the new transport. /// Add the transport info to ItemTransports. /// </summary> /// <param name="guid">GUID of the Event</param> /// <returns></returns> static async private Task <TransportInfo> CreateTransport(System.Guid guid) { var args = new ArgsObject(guid.ToString("B")); var result = await WaapiClient.Call(ak.wwise.core.transport.create, args, null, timeout : 1000); int transportID = UnityEngine.JsonUtility.FromJson <ReturnTransport>(result).transport; var options = new TransportOptions(transportID); uint subscriptionID = await WaapiClient.Subscribe(ak.wwise.core.transport.stateChanged, options, HandleTransportStateChanged); var transport = new TransportInfo(transportID, subscriptionID); ItemTransports.Add(guid, transport); return(transport); }
public void TwoSecondsAndNullOnlyValidKeepAliveValuesWhenDisconnectTimeoutIsSixSeconds() { // Arrange var config = new TransportOptions(); config.DisconnectTimeout = TimeSpan.FromSeconds(6); // Assert Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.KeepAlive = TimeSpan.FromSeconds(1.99)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.KeepAlive = TimeSpan.FromSeconds(2.01)); // Assert doesn't throw config.KeepAlive = TimeSpan.FromSeconds(2); config.KeepAlive = null; }
public void TouchOut(TransportOptions options, string startingPoint, string stoppingPoint) { if (_objJourney != null) { if (_objJourney.complete(stoppingPoint.ToLower())) { RefundMoney(_objJourney.Fare_Difference(startingPoint.ToLower(), stoppingPoint.ToLower())); } else { _objJourney = new Journey(options, startingPoint.ToLower(), stoppingPoint.ToLower()); Charge(_objJourney.Basic_Fare()); } } }
public void KeepAliveThrowsWhenGreaterThanAThirdOfTheDisconnectTimeout() { // Arrange var config = new TransportOptions(); // Assert Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.KeepAlive = TimeSpan.FromSeconds(10.01)); config.KeepAlive = TimeSpan.FromSeconds(10); // Arrange config = new TransportOptions(); config.DisconnectTimeout = TimeSpan.FromSeconds(15); // Assert Assert.Throws(typeof(ArgumentOutOfRangeException), () => config.KeepAlive = TimeSpan.FromSeconds(5.01)); config.KeepAlive = TimeSpan.FromSeconds(5); }
public void KeepAliveCannotBeConfiguredBeforeDisconnectTimeout() { // Arrange var config = new TransportOptions(); config.KeepAlive = TimeSpan.FromSeconds(5); // Assert Assert.Throws(typeof(InvalidOperationException), () => config.DisconnectTimeout = TimeSpan.FromSeconds(40)); // Arrange config = new TransportOptions(); config.KeepAlive = null; // Assert Assert.Throws(typeof(InvalidOperationException), () => config.DisconnectTimeout = TimeSpan.FromSeconds(40)); }
public void KeepAliveTimeoutIsTwiceTheKeepAlive() { // Arrange var config = new TransportOptions(); var random = new Random(); config.KeepAlive = TimeSpan.FromSeconds(random.NextDouble() * 8 + 2); // 2 to 10 seconds // Assert Assert.Equal(TimeSpan.FromTicks(config.KeepAlive.Value.Ticks * 2), config.KeepAliveTimeout()); // Arrange config.KeepAlive = null; // Assert Assert.Equal(null, config.KeepAliveTimeout()); }
protected IngoingServiceBase( ILogger <IngoingServiceBase> logger, IOptions <TransportOptions> options, IBehaviorExecutor behaviorExecutor, IPlatformDatabase database, ServiceContext serviceContext ) { _logger = logger; _options = options.Value; _behaviorExecutor = behaviorExecutor; _serviceContext = serviceContext; using (database) { _behaviorExecutor.Initialize(_serviceContext.ScriptId, database); } }
private static SenderDelegate CreateAjaxSender(AjaxObjectFactory ajaxObject) { return((url, payload, callback) => { Log.Debug($"{nameof(CreateAjaxSender)}: Create ajax sender {url} {payload}"); var opt = new TransportOptions(); if (!payload.IsNullOrEmpty()) { opt.Headers = new Dictionary <string, string> { { "Content-type", "text/plain" } } } ; var ajaxUrl = new Uri(url).AddPath("/xhr_send"); var xo = ajaxObject("POST", ajaxUrl.OriginalString, payload, opt); xo.Once("finish", (sender, e) => { var status = (int)e[0]; Log.Debug($"{nameof(CreateAjaxSender)}: Finish {status}"); xo = null; if (status != 200 && status != 204) { callback(new Exception($"http status {status}")); return; } callback(null); }); return () => { Log.Debug($"{nameof(CreateAjaxSender)}: Abort"); xo.Close(); xo = null; var err = new CodedException("Aborted", 1000); callback(err); }; }); }
/// <inheritdoc/> public override async Task <string> PublishAsync <TEvent>(EventContext <TEvent> @event, EventRegistration registration, DateTimeOffset?scheduled = null, CancellationToken cancellationToken = default) { // log warning when trying to publish scheduled message if (scheduled != null) { Logger.LogWarning("Amazon Kinesis does not support delay or scheduled publish"); } using var scope = CreateScope(); using var ms = new MemoryStream(); await SerializeAsync(body : ms, @event : @event, registration : registration, scope : scope, cancellationToken : cancellationToken); // prepare the record var streamName = registration.EventName; var request = new PutRecordRequest { Data = ms, PartitionKey = TransportOptions.PartitionKeyResolver(@event), StreamName = streamName, }; // send the event Logger.LogInformation("Sending {Id} to '{StreamName}'. Scheduled: {Scheduled}", @event.Id, streamName, scheduled); var response = await kinesisClient.PutRecordAsync(request, cancellationToken); response.EnsureSuccess(); // return the sequence number return(scheduled != null ? response.SequenceNumber : null); }