blob: 400dbf3ef3a96b077d5a0af182d074f378d4d866 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Tango.Telemetry;
namespace Tango.TelemetryTester.CLI
{
public class MockDestinationWithFailure : ITelemetryDestination
{
public string Name { get; set; }
public List<string> ReceivedPayloads { get; } = new List<string>();
public int FailCountRemaining { get; private set; }
public int TotalAttempts { get; private set; } = 0;
public MockDestinationWithFailure(string name, int failCount)
{
Name = name;
FailCountRemaining = failCount;
}
public IReadOnlyList<TelemetrySourceTypes> SupportedSourceTypes => new[]
{
TelemetrySourceTypes.Streaming,
TelemetrySourceTypes.ExternalStorage,
TelemetrySourceTypes.PendingStorage
};
public Task<bool> IsAvailable() => Task.FromResult(true);
public Task Publish(TelemetryPublishPackage package, List<KeyValuePair<string, string>> properties)
{
TotalAttempts++;
if (FailCountRemaining-- > 0)
{
throw new Exception("Simulated publish failure");
}
var payload = package.ToPayload();
ReceivedPayloads.Add(payload);
Logger.LogInfo($"Destination '{Name}' received payload: {payload}");
return Task.CompletedTask;
}
public void Dispose() { }
}
}
|