public void WhenNewValueIsLessThanOneSetToDefault() { var buffer = new TelemetryBuffer(); buffer.Capacity = 0; Assert.Equal(buffer.Capacity, 500); }
/// <summary> /// Initializes a new instance of the <see cref="PersistenceChannel"/> class. /// </summary> /// <param name="storageFolderName"> /// A folder name. Under this folder all the transmissions will be saved. /// Setting this value groups channels, even from different processes. /// If 2 (or more) channels has the same <c>storageFolderName</c> only one channel will perform the sending even if the channel is in a different process/AppDomain/Thread. /// </param> /// <param name="sendersCount"> /// Defines the number of senders. A sender is a long-running thread that sends telemetry batches in intervals defined by <see cref="SendingInterval"/>. /// So the amount of senders also defined the maximum amount of http channels opened at the same time. /// </param> public PersistenceChannel(string storageFolderName, int sendersCount = 1) { this.TelemetryBuffer = new TelemetryBuffer(); this.storage = ServiceLocator.GetService<BaseStorageService>(); this.storage.Init(storageFolderName); this.Transmitter = new PersistenceTransmitter(this.storage, sendersCount); this.flushManager = new FlushManager(this.storage, this.TelemetryBuffer); this.EndpointAddress = TelemetryServiceEndpoint; this.developerMode = false; }
public void TelemetryBufferCallingOnFullActionWhenBufferCapacityReached() { IEnumerable<ITelemetry> items = null; TelemetryBuffer buffer = new TelemetryBuffer { Capacity = 2 }; buffer.OnFull = () => { items = buffer.Dequeue(); }; buffer.Enqueue(new EventTelemetry("Event1")); buffer.Enqueue(new EventTelemetry("Event2")); Assert.NotNull(items); Assert.Equal(2, items.Count()); }
/// <summary> /// Initializes a new instance of the <see cref="FlushManager"/> class. /// </summary> /// <param name="storage">The storage that persists the telemetries.</param> /// <param name="telemetryBuffer">In memory buffer that holds telemetries.</param> /// <param name="supportAutoFlush">A boolean value that determines if flush will happen automatically. Used by unit tests.</param> internal FlushManager(BaseStorageService storage, TelemetryBuffer telemetryBuffer, bool supportAutoFlush = true) { this.storage = storage; this.telemetryBuffer = telemetryBuffer; this.telemetryBuffer.OnFull = this.OnTelemetryBufferFull; this.FlushDelay = TimeSpan.FromSeconds(30); if (supportAutoFlush) { Task.Factory.StartNew(this.FlushLoop, TaskCreationOptions.LongRunning) .ContinueWith(t => CoreEventSource.Log.LogVerbose("FlushManager: Failure in FlushLoop: Exception: " + t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted); } }
internal InMemoryTransmitter(TelemetryBuffer buffer) { this.buffer = buffer; this.buffer.OnFull = this.OnBufferFull; // It is currently possible for the long - running InMemoryTransmitter.Runner // task to be executed(and thereby block during WaitOne) on the UI thread when // called by a task scheduled on the UI thread. Explicitly specifying TaskScheduler.Default // when calling StartNew guarantees that InMemoryTransmitter.Runner never blocks the main thread. Task.Factory.StartNew(this.Runner, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith( task => { string msg = string.Format(CultureInfo.InvariantCulture, "InMemoryTransmitter: Unhandled exception in Runner: {0}", task.Exception); CoreEventSource.Log.LogVerbose(msg); }, TaskContinuationOptions.OnlyOnFaulted); }
internal InMemoryTransmitter(TelemetryBuffer buffer) { this.buffer = buffer; this.buffer.OnFull = this.OnBufferFull; // It is currently possible for the long - running InMemoryTransmitter.Runner // task to be executed(and thereby block during WaitOne) on the UI thread when // called by a task scheduled on the UI thread. Explicitly specifying TaskScheduler.Default // when calling StartNew guarantees that InMemoryTransmitter.Runner never blocks the main thread. Task.Factory.StartNew(this.Runner, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith( task => { string msg = string.Format(CultureInfo.InvariantCulture, "InMemoryTransmitter: Unhandled exception in Runner: {0}", task.Exception); CoreEventSource.Log.LogVerbose(msg); }, TaskContinuationOptions.OnlyOnFaulted); }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryChannel" /> class. Used in unit tests for constructor injection. /// </summary> /// <param name="telemetryBuffer">The telemetry buffer that will be used to enqueue new events.</param> /// <param name="transmitter">The in memory transmitter that will send the events queued in the buffer.</param> internal InMemoryChannel(TelemetryBuffer telemetryBuffer, InMemoryTransmitter transmitter) { this.buffer = telemetryBuffer; this.transmitter = transmitter; }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryChannel" /> class. /// </summary> public InMemoryChannel() { this.buffer = new TelemetryBuffer(); this.transmitter = new InMemoryTransmitter(this.buffer); }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryChannel" /> class. Used in unit tests for constructor injection. /// </summary> /// <param name="telemetryBuffer">The telemetry buffer that will be used to enqueue new events.</param> /// <param name="transmitter">The in memory transmitter that will send the events queued in the buffer.</param> internal InMemoryChannel(TelemetryBuffer telemetryBuffer, InMemoryTransmitter transmitter) { this.buffer = telemetryBuffer; this.transmitter = transmitter; }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryChannel" /> class. /// </summary> public InMemoryChannel() { this.buffer = new TelemetryBuffer(); this.transmitter = new InMemoryTransmitter(this.buffer); }
public void DefaultValueIsAppropriateForProductionEnvironmentAndUnitTests() { var buffer = new TelemetryBuffer(); Assert.Equal(500, buffer.Capacity); }
public void CanBeSetByChannelToTunePerformance() { var buffer = new TelemetryBuffer(); buffer.Capacity = 42; Assert.Equal(42, buffer.Capacity); }
public void DefaultValueIsAppropriateForProductionEnvironmentAndUnitTests() { var buffer = new TelemetryBuffer(); Assert.Equal(500, buffer.Capacity); }