Option to exclude blockReceivedEvents from transcript
This commit is contained in:
parent
5aa3edbda2
commit
5bbb95f1ff
|
@ -8,11 +8,13 @@ namespace CodexPlugin.OverwatchSupport
|
|||
public class CodexLogConverter
|
||||
{
|
||||
private readonly ITranscriptWriter writer;
|
||||
private readonly CodexTranscriptWriterConfig config;
|
||||
private readonly IdentityMap identityMap;
|
||||
|
||||
public CodexLogConverter(ITranscriptWriter writer, IdentityMap identityMap)
|
||||
public CodexLogConverter(ITranscriptWriter writer, CodexTranscriptWriterConfig config, IdentityMap identityMap)
|
||||
{
|
||||
this.writer = writer;
|
||||
this.config = config;
|
||||
this.identityMap = identityMap;
|
||||
}
|
||||
|
||||
|
@ -20,7 +22,7 @@ namespace CodexPlugin.OverwatchSupport
|
|||
{
|
||||
var name = DetermineName(log);
|
||||
var identityIndex = identityMap.GetIndex(name);
|
||||
var runner = new ConversionRunner(writer, identityMap, log.ContainerName, identityIndex);
|
||||
var runner = new ConversionRunner(writer, config, identityMap, identityIndex);
|
||||
runner.Run(log);
|
||||
}
|
||||
|
||||
|
@ -37,22 +39,27 @@ namespace CodexPlugin.OverwatchSupport
|
|||
{
|
||||
private readonly ITranscriptWriter writer;
|
||||
private readonly IdentityMap nameIdMap;
|
||||
private readonly string name;
|
||||
private readonly int nodeIdentityIndex;
|
||||
private readonly ILineConverter[] converters = new ILineConverter[]
|
||||
{
|
||||
new BlockReceivedLineConverter(),
|
||||
new BootstrapLineConverter(),
|
||||
new DialSuccessfulLineConverter(),
|
||||
new PeerDroppedLineConverter()
|
||||
};
|
||||
private readonly ILineConverter[] converters;
|
||||
|
||||
public ConversionRunner(ITranscriptWriter writer, IdentityMap nameIdMap, string name, int nodeIdentityIndex)
|
||||
public ConversionRunner(ITranscriptWriter writer, CodexTranscriptWriterConfig config, IdentityMap nameIdMap, int nodeIdentityIndex)
|
||||
{
|
||||
this.name = name;
|
||||
this.nodeIdentityIndex = nodeIdentityIndex;
|
||||
this.writer = writer;
|
||||
this.nameIdMap = nameIdMap;
|
||||
|
||||
converters = CreateConverters(config).ToArray();
|
||||
}
|
||||
|
||||
private IEnumerable<ILineConverter> CreateConverters(CodexTranscriptWriterConfig config)
|
||||
{
|
||||
if (config.IncludeBlockReceivedEvents)
|
||||
{
|
||||
yield return new BlockReceivedLineConverter();
|
||||
}
|
||||
yield return new BootstrapLineConverter();
|
||||
yield return new DialSuccessfulLineConverter();
|
||||
yield return new PeerDroppedLineConverter();
|
||||
}
|
||||
|
||||
public void Run(IDownloadedLog log)
|
||||
|
|
|
@ -10,16 +10,18 @@ namespace CodexPlugin.OverwatchSupport
|
|||
{
|
||||
private const string CodexHeaderKey = "cdx_h";
|
||||
private readonly ILog log;
|
||||
private readonly CodexTranscriptWriterConfig config;
|
||||
private readonly ITranscriptWriter writer;
|
||||
private readonly CodexLogConverter converter;
|
||||
private readonly IdentityMap identityMap = new IdentityMap();
|
||||
private readonly KademliaPositionFinder positionFinder = new KademliaPositionFinder();
|
||||
|
||||
public CodexTranscriptWriter(ILog log, ITranscriptWriter transcriptWriter)
|
||||
public CodexTranscriptWriter(ILog log, CodexTranscriptWriterConfig config, ITranscriptWriter transcriptWriter)
|
||||
{
|
||||
this.log = log;
|
||||
this.config = config;
|
||||
writer = transcriptWriter;
|
||||
converter = new CodexLogConverter(writer, identityMap);
|
||||
converter = new CodexLogConverter(writer, config, identityMap);
|
||||
}
|
||||
|
||||
public void Finalize(string outputFilepath)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
namespace CodexPlugin.OverwatchSupport
|
||||
{
|
||||
public class CodexTranscriptWriterConfig
|
||||
{
|
||||
public CodexTranscriptWriterConfig(bool includeBlockReceivedEvents)
|
||||
{
|
||||
IncludeBlockReceivedEvents = includeBlockReceivedEvents;
|
||||
}
|
||||
|
||||
public bool IncludeBlockReceivedEvents { get; }
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@
|
|||
nodes.Add(identity);
|
||||
|
||||
shortToLong.Add(CodexUtils.ToShortId(identity.PeerId), identity.PeerId);
|
||||
shortToLong.Add(CodexUtils.ToShortId(identity.NodeId), identity.NodeId);
|
||||
shortToLong.Add(CodexUtils.ToNodeIdShortId(identity.NodeId), identity.NodeId);
|
||||
}
|
||||
|
||||
public CodexNodeIdentity[] Get()
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace CodexTests.BasicTests
|
|||
{
|
||||
[Test]
|
||||
[Combinatorial]
|
||||
[CreateTranscript(nameof(MarketplaceTests), includeBlockReceivedEvents: false)]
|
||||
public void MarketplaceExample(
|
||||
[Values(64)] int numBlocks,
|
||||
[Values(0)] int plusSizeKb,
|
||||
|
|
|
@ -136,10 +136,15 @@ namespace CodexTests
|
|||
|
||||
private void SetupTranscript(TestLifecycle lifecycle)
|
||||
{
|
||||
if (GetTranscriptAttributeOfCurrentTest() == null) return;
|
||||
var attr = GetTranscriptAttributeOfCurrentTest();
|
||||
if (attr == null) return;
|
||||
|
||||
var config = new CodexTranscriptWriterConfig(
|
||||
attr.IncludeBlockReceivedEvents
|
||||
);
|
||||
|
||||
var log = new LogPrefixer(lifecycle.Log, "(Transcript) ");
|
||||
var writer = new CodexTranscriptWriter(log, Transcript.NewWriter(log));
|
||||
var writer = new CodexTranscriptWriter(log, config, Transcript.NewWriter(log));
|
||||
Ci.SetCodexHooksProvider(writer);
|
||||
writers.Add(lifecycle, writer);
|
||||
}
|
||||
|
@ -190,11 +195,13 @@ namespace CodexTests
|
|||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public class CreateTranscriptAttribute : PropertyAttribute
|
||||
{
|
||||
public CreateTranscriptAttribute(string outputFilename)
|
||||
public CreateTranscriptAttribute(string outputFilename, bool includeBlockReceivedEvents = true)
|
||||
{
|
||||
OutputFilename = outputFilename;
|
||||
IncludeBlockReceivedEvents = includeBlockReceivedEvents;
|
||||
}
|
||||
|
||||
public string OutputFilename { get; }
|
||||
public bool IncludeBlockReceivedEvents { get; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue