Exemple #1
0
 /// <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 = 3)
 {
     this.TelemetryBuffer = new TelemetryBuffer();
     this.storage         = new Storage(storageFolderName);
     this.Transmitter     = new PersistenceTransmitter(this.storage, sendersCount);
     this.flushManager    = new FlushManager(this.storage, this.TelemetryBuffer);
     this.EndpointAddress = Constants.TelemetryServiceEndpoint;
 }
 /// <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 = 3)
 {   
     this.TelemetryBuffer = new TelemetryBuffer();
     this.storage = new Storage(storageFolderName);
     this.Transmitter = new PersistenceTransmitter(this.storage, sendersCount);
     this.flushManager = new FlushManager(this.storage, this.TelemetryBuffer);
     this.EndpointAddress = Constants.TelemetryServiceEndpoint;
     this.developerMode = false;
 }
        public void WhenEnqueueingToAFullTelemetryBufferThenFlushManagerFlushesToDisk()
        {
            // Setup
            var autoResetEvent = new AutoResetEvent(false);
            this.OnEnqueue = () => autoResetEvent.Set();            
            FlushManager flushManager = new FlushManager(this.StorageBaseMock.Object, this.TelemetryBufferMock, supportAutoFlush: true);
            flushManager.EndpointAddress = new Uri("http://some.test.com");

            // Act
            this.TelemetryBufferMock.Enqueue(new TraceTelemetry("mock_item"));
            
            // wait until Enqueue is called. 
            autoResetEvent.WaitOne();

            // Asserts
            Assert.AreEqual(1, this.numberOfCallsToStorageEnqueue);
        }
        public void WhenEnqueueingToTelemetryBufferAndTelemetryBufferIsNotFullThenFlushManagerDoesNotFlushToDisk()
        {
            // Setup
            var autoResetEvent = new AutoResetEvent(false);
            this.OnEnqueue = () => autoResetEvent.Set();
            FlushManager flushManager = new FlushManager(this.StorageBaseMock.Object, this.TelemetryBufferMock, supportAutoFlush: false);
            flushManager.EndpointAddress = new Uri("http://some.test.com");
            this.TelemetryBufferMock.Capacity = 10;

            // Act
            this.TelemetryBufferMock.Enqueue(new TraceTelemetry("mock_item"));

            // wait for 500 milliseconds for Storage.Enqueue to be called.
            var didStorageEnqueueWasCalled = autoResetEvent.WaitOne(500);

            // Asserts
            Assert.AreEqual(false, didStorageEnqueueWasCalled);
            Assert.AreEqual(0, this.numberOfCallsToStorageEnqueue);
        }