2025-01-16 13:51:29 +01:00
|
|
|
|
using CodexClient;
|
|
|
|
|
|
using CodexPlugin;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
using DistTestCore;
|
2023-09-12 15:43:30 +02:00
|
|
|
|
|
2023-10-09 16:59:52 +02:00
|
|
|
|
namespace CodexTests
|
2023-09-12 15:43:30 +02:00
|
|
|
|
{
|
2025-04-23 14:18:11 +02:00
|
|
|
|
public class AutoBootstrapComponent : ILifecycleComponent
|
2023-09-12 15:43:30 +02:00
|
|
|
|
{
|
2025-04-23 14:18:11 +02:00
|
|
|
|
public ICodexNode? BootstrapNode { get; private set; } = null;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
|
2025-04-23 14:18:11 +02:00
|
|
|
|
public void Start(ILifecycleComponentAccess access)
|
2023-09-12 15:43:30 +02:00
|
|
|
|
{
|
2025-04-23 14:18:11 +02:00
|
|
|
|
if (BootstrapNode != null) return;
|
|
|
|
|
|
|
|
|
|
|
|
var tl = access.Get<TestLifecycle>();
|
|
|
|
|
|
var ci = tl.CoreInterface;
|
|
|
|
|
|
var testNamespace = tl.TestNamespace;
|
|
|
|
|
|
|
|
|
|
|
|
BootstrapNode = ci.StartCodexNode(s => s.WithName("BOOTSTRAP_" + testNamespace));
|
2023-09-12 15:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-23 14:18:11 +02:00
|
|
|
|
public void ApplyBootstrapNode(ICodexSetup setup)
|
2023-09-28 14:23:48 +02:00
|
|
|
|
{
|
2025-04-23 14:18:11 +02:00
|
|
|
|
if (BootstrapNode == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
setup.WithBootstrapNode(BootstrapNode);
|
2023-09-28 14:23:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-23 14:18:11 +02:00
|
|
|
|
public void Stop(ILifecycleComponentAccess access, DistTestResult result)
|
2023-09-12 15:43:30 +02:00
|
|
|
|
{
|
2025-04-23 14:18:11 +02:00
|
|
|
|
if (BootstrapNode == null) return;
|
|
|
|
|
|
BootstrapNode.Stop(waitTillStopped: false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-22 17:11:34 +02:00
|
|
|
|
|
2025-04-23 14:18:11 +02:00
|
|
|
|
public class AutoBootstrapDistTest : CodexDistTest
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
protected override void CreateComponents(ILifecycleComponentCollector collector)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.CreateComponents(collector);
|
|
|
|
|
|
collector.AddComponent(new AutoBootstrapComponent());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnCodexSetup(ICodexSetup setup)
|
|
|
|
|
|
{
|
|
|
|
|
|
Get<AutoBootstrapComponent>().ApplyBootstrapNode(setup);
|
2023-09-12 15:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-22 17:11:34 +02:00
|
|
|
|
protected ICodexNode BootstrapNode
|
2024-09-24 10:10:59 +02:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2025-04-23 14:18:11 +02:00
|
|
|
|
var bn = Get<AutoBootstrapComponent>().BootstrapNode;
|
|
|
|
|
|
if (bn == null) throw new InvalidOperationException("BootstrapNode accessed before initialized.");
|
|
|
|
|
|
return bn;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-09-12 15:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|