Removes core-interface associate methods.

This commit is contained in:
benbierens 2023-09-13 08:55:04 +02:00
parent dd6b99c670
commit 7e7414d491
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
12 changed files with 52 additions and 78 deletions

View File

@ -37,22 +37,5 @@ namespace CodexPlugin
{
return codexStarter.WrapCodexContainers(containers);
}
public IOnlineCodexNode SetupCodexNode(Action<ICodexSetup> setup)
{
return SetupCodexNodes(1, setup)[0];
}
public ICodexNodeGroup SetupCodexNodes(int number, Action<ICodexSetup> setup)
{
var rc = StartCodexNodes(number, setup);
return WrapCodexContainers(rc);
}
public ICodexNodeGroup SetupCodexNodes(int number)
{
var rc = StartCodexNodes(number, s => { });
return WrapCodexContainers(rc);
}
}
}

View File

@ -17,22 +17,23 @@ namespace CodexPlugin
public static IOnlineCodexNode SetupCodexNode(this CoreInterface ci)
{
return Plugin(ci).SetupCodexNode(s => { }); // do more unification here. Keep plugin simpler.
return ci.SetupCodexNodes(1)[0];
}
public static IOnlineCodexNode SetupCodexNode(this CoreInterface ci, Action<ICodexSetup> setup)
{
return Plugin(ci).SetupCodexNode(setup);
return ci.SetupCodexNodes(1, setup)[0];
}
public static ICodexNodeGroup SetupCodexNodes(this CoreInterface ci, int number, Action<ICodexSetup> setup)
{
return Plugin(ci).SetupCodexNodes(number, setup);
var rc = ci.StartCodexNodes(number, setup);
return ci.WrapCodexContainers(rc);
}
public static ICodexNodeGroup SetupCodexNodes(this CoreInterface ci, int number)
{
return Plugin(ci).SetupCodexNodes(number);
return ci.SetupCodexNodes(number, s => { });
}
private static CodexPlugin Plugin(CoreInterface ci)

View File

@ -1,28 +1,17 @@
namespace Core
{
public class CoreInterface
public sealed class CoreInterface
{
private static readonly Dictionary<CoreInterface, EntryPoint> coreAssociations = new Dictionary<CoreInterface, EntryPoint>();
private readonly EntryPoint entryPoint;
internal CoreInterface(EntryPoint entryPoint)
{
this.entryPoint = entryPoint;
}
public T GetPlugin<T>() where T : IProjectPlugin
{
return coreAssociations[this].GetPlugin<T>();
}
internal static void Associate(CoreInterface coreInterface, EntryPoint entryPoint)
{
coreAssociations.Add(coreInterface, entryPoint);
}
internal static void Desociate(EntryPoint entryPoint)
{
var keys = coreAssociations.Where(p => p.Value == entryPoint).ToArray();
if (keys.Length == 0) return;
foreach (var key in keys)
{
coreAssociations.Remove(key.Key);
}
return entryPoint.GetPlugin<T>();
}
}
}

View File

@ -38,21 +38,13 @@ namespace Core
manager.InitializePlugins(this);
}
public void ManuallyAssociateCoreInterface(CoreInterface ci)
{
CoreInterface.Associate(ci, this);
}
public CoreInterface CreateInterface()
{
var ci = new CoreInterface();
CoreInterface.Associate(ci, this);
return ci;
return new CoreInterface(this);
}
public void Decommission()
{
CoreInterface.Desociate(this);
manager.FinalizePlugins(log);
}

View File

@ -8,7 +8,7 @@ using Utils;
namespace DistTestCore
{
[Parallelizable(ParallelScope.All)]
public abstract class DistTest : CoreInterface
public abstract class DistTest
{
private const string TestsType = "dist-tests";
private const string TestNamespacePrefix = "ct-";
@ -91,6 +91,14 @@ namespace DistTestCore
}
}
public CoreInterface Ci
{
get
{
return Get().CoreInterface;
}
}
public TrackedFile GenerateTestFile(ByteSize size, string label = "")
{
return Get().EntryPoint.GetFileManager().GenerateTestFile(size, label);
@ -213,7 +221,6 @@ namespace DistTestCore
{
var testNamespace = TestNamespacePrefix + Guid.NewGuid().ToString();
var lifecycle = new TestLifecycle(fixtureLog.CreateTestLog(), configuration, GetTimeSet(), testNamespace);
lifecycle.EntryPoint.ManuallyAssociateCoreInterface(this);
lifecycles.Add(testName, lifecycle);
DefaultContainerRecipe.TestsType = TestsType;
//DefaultContainerRecipe.ApplicationIds = lifecycle.GetApplicationIds();

View File

@ -17,6 +17,7 @@ namespace DistTestCore
EntryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(timeSet, testNamespace), configuration.GetFileManagerFolder(), timeSet);
EntryPoint.Initialize();
CoreInterface = EntryPoint.CreateInterface();
log.WriteLogTag();
}
@ -25,6 +26,7 @@ namespace DistTestCore
public Configuration Configuration { get; }
public ITimeSet TimeSet { get; }
public EntryPoint EntryPoint { get; }
public CoreInterface CoreInterface { get; }
public void DeleteAllResources()
{

View File

@ -13,7 +13,7 @@ namespace Tests
public IOnlineCodexNode AddCodex(Action<ICodexSetup> setup)
{
return this.SetupCodexNode(s =>
return Ci.SetupCodexNode(s =>
{
setup(s);
s.WithBootstrapNode(BootstrapNode);
@ -22,12 +22,12 @@ namespace Tests
public ICodexNodeGroup AddCodex(int numberOfNodes)
{
return this.SetupCodexNodes(numberOfNodes, s => s.WithBootstrapNode(BootstrapNode));
return Ci.SetupCodexNodes(numberOfNodes, s => s.WithBootstrapNode(BootstrapNode));
}
public ICodexNodeGroup AddCodex(int numberOfNodes, Action<ICodexSetup> setup)
{
return this.SetupCodexNodes(numberOfNodes, s =>
return Ci.SetupCodexNodes(numberOfNodes, s =>
{
setup(s);
s.WithBootstrapNode(BootstrapNode);
@ -37,7 +37,7 @@ namespace Tests
[SetUp]
public void SetUpBootstrapNode()
{
BootstrapNode = this.SetupCodexNode(s => s.WithName("BOOTSTRAP"));
BootstrapNode = Ci.SetupCodexNode(s => s.WithName("BOOTSTRAP"));
}
protected IOnlineCodexNode BootstrapNode { get; private set; } = null!;

View File

@ -11,7 +11,7 @@ namespace Tests.BasicTests
[Test]
public void CodexLogExample()
{
var primary = this.SetupCodexNode();
var primary = Ci.SetupCodexNode();
primary.UploadFile(GenerateTestFile(5.MB()));
@ -23,8 +23,8 @@ namespace Tests.BasicTests
[Test]
public void TwoMetricsExample()
{
//var group = this.SetupCodexNodes(2, s => s.EnableMetrics());
//var group2 = this.SetupCodexNodes(2, s => s.EnableMetrics());
//var group = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
//var group2 = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
//var primary = group[0];
//var secondary = group[1];
@ -47,7 +47,7 @@ namespace Tests.BasicTests
//var buyerInitialBalance = 1000.TestTokens();
//var fileSize = 10.MB();
//var seller = this.SetupCodexNode(s => s
//var seller = Ci.SetupCodexNode(s => s
// .WithStorageQuota(11.GB())
// .EnableMarketplace(sellerInitialBalance));
@ -60,7 +60,7 @@ namespace Tests.BasicTests
//var testFile = GenerateTestFile(fileSize);
//var buyer = this.SetupCodexNode(s => s
//var buyer = Ci.SetupCodexNode(s => s
// .WithBootstrapNode(seller)
// .EnableMarketplace(buyerInitialBalance));

View File

@ -17,7 +17,7 @@ namespace Tests.BasicTests
[Test]
public void SetUpANodeAndWait()
{
node = this.SetupCodexNode();
node = Ci.SetupCodexNode();
Time.WaitUntil(() => node == null, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5));
}
@ -25,7 +25,7 @@ namespace Tests.BasicTests
[Test]
public void ForeignNodeConnects()
{
var myNode = this.SetupCodexNode();
var myNode = Ci.SetupCodexNode();
Time.WaitUntil(() => node != null, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(5));

View File

@ -11,7 +11,7 @@ namespace Tests.BasicTests
[Test]
public void OneClientTest()
{
var primary = this.SetupCodexNode();
var primary = Ci.SetupCodexNode();
PerformOneClientTest(primary);
}
@ -19,7 +19,7 @@ namespace Tests.BasicTests
[Test]
public void RestartTest()
{
var primary = this.SetupCodexNode();
var primary = Ci.SetupCodexNode();
//var setup = primary.BringOffline();

View File

@ -12,7 +12,7 @@ namespace Tests.BasicTests
[Test]
public void TwoClientTest()
{
var group = this.SetupCodexNodes(2);
var group = Ci.SetupCodexNodes(2);
var primary = group[0];
var secondary = group[1];
@ -23,8 +23,8 @@ namespace Tests.BasicTests
[Test]
public void TwoClientsTwoLocationsTest()
{
var primary = this.SetupCodexNode(s => s.At(Location.One));
var secondary = this.SetupCodexNode(s => s.At(Location.Two));
var primary = Ci.SetupCodexNode(s => s.At(Location.One));
var secondary = Ci.SetupCodexNode(s => s.At(Location.Two));
PerformTwoClientTest(primary, secondary);
}

View File

@ -10,10 +10,10 @@ namespace Tests.PeerDiscoveryTests
[Test]
public void TwoLayersTest()
{
var root = this.SetupCodexNode();
var l1Source = this.SetupCodexNode(s => s.WithBootstrapNode(root));
var l1Node = this.SetupCodexNode(s => s.WithBootstrapNode(root));
var l2Target = this.SetupCodexNode(s => s.WithBootstrapNode(l1Node));
var root = Ci.SetupCodexNode();
var l1Source = Ci.SetupCodexNode(s => s.WithBootstrapNode(root));
var l1Node = Ci.SetupCodexNode(s => s.WithBootstrapNode(root));
var l2Target = Ci.SetupCodexNode(s => s.WithBootstrapNode(l1Node));
AssertAllNodesConnected();
}
@ -21,11 +21,11 @@ namespace Tests.PeerDiscoveryTests
[Test]
public void ThreeLayersTest()
{
var root = this.SetupCodexNode();
var l1Source = this.SetupCodexNode(s => s.WithBootstrapNode(root));
var l1Node = this.SetupCodexNode(s => s.WithBootstrapNode(root));
var l2Node = this.SetupCodexNode(s => s.WithBootstrapNode(l1Node));
var l3Target = this.SetupCodexNode(s => s.WithBootstrapNode(l2Node));
var root = Ci.SetupCodexNode();
var l1Source = Ci.SetupCodexNode(s => s.WithBootstrapNode(root));
var l1Node = Ci.SetupCodexNode(s => s.WithBootstrapNode(root));
var l2Node = Ci.SetupCodexNode(s => s.WithBootstrapNode(l1Node));
var l3Target = Ci.SetupCodexNode(s => s.WithBootstrapNode(l2Node));
AssertAllNodesConnected();
}
@ -36,10 +36,10 @@ namespace Tests.PeerDiscoveryTests
[TestCase(20)]
public void NodeChainTest(int chainLength)
{
var node = this.SetupCodexNode();
var node = Ci.SetupCodexNode();
for (var i = 1; i < chainLength; i++)
{
node = this.SetupCodexNode(s => s.WithBootstrapNode(node));
node = Ci.SetupCodexNode(s => s.WithBootstrapNode(node));
}
AssertAllNodesConnected();