From 7e7414d4913d017cc673ede91805bd57c125aaa0 Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 13 Sep 2023 08:55:04 +0200 Subject: [PATCH] Removes core-interface associate methods. --- CodexPlugin/CodexPlugin.cs | 17 ------------ CodexPlugin/CoreInterfaceExtensions.cs | 9 ++++--- Core/CoreInterface.cs | 27 ++++++------------- Core/EntryPoint.cs | 10 +------ DistTestCore/DistTest.cs | 11 ++++++-- DistTestCore/TestLifecycle.cs | 2 ++ Tests/AutoBootstrapDistTest.cs | 8 +++--- Tests/BasicTests/ExampleTests.cs | 10 +++---- Tests/BasicTests/NetworkIsolationTest.cs | 4 +-- Tests/BasicTests/OneClientTests.cs | 4 +-- Tests/BasicTests/TwoClientTests.cs | 6 ++--- .../LayeredDiscoveryTests.cs | 22 +++++++-------- 12 files changed, 52 insertions(+), 78 deletions(-) diff --git a/CodexPlugin/CodexPlugin.cs b/CodexPlugin/CodexPlugin.cs index dbc18b1..7f20f6f 100644 --- a/CodexPlugin/CodexPlugin.cs +++ b/CodexPlugin/CodexPlugin.cs @@ -37,22 +37,5 @@ namespace CodexPlugin { return codexStarter.WrapCodexContainers(containers); } - - public IOnlineCodexNode SetupCodexNode(Action setup) - { - return SetupCodexNodes(1, setup)[0]; - } - - public ICodexNodeGroup SetupCodexNodes(int number, Action setup) - { - var rc = StartCodexNodes(number, setup); - return WrapCodexContainers(rc); - } - - public ICodexNodeGroup SetupCodexNodes(int number) - { - var rc = StartCodexNodes(number, s => { }); - return WrapCodexContainers(rc); - } } } diff --git a/CodexPlugin/CoreInterfaceExtensions.cs b/CodexPlugin/CoreInterfaceExtensions.cs index 58b1920..75b779f 100644 --- a/CodexPlugin/CoreInterfaceExtensions.cs +++ b/CodexPlugin/CoreInterfaceExtensions.cs @@ -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 setup) { - return Plugin(ci).SetupCodexNode(setup); + return ci.SetupCodexNodes(1, setup)[0]; } public static ICodexNodeGroup SetupCodexNodes(this CoreInterface ci, int number, Action 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) diff --git a/Core/CoreInterface.cs b/Core/CoreInterface.cs index 31bed2d..cad0eea 100644 --- a/Core/CoreInterface.cs +++ b/Core/CoreInterface.cs @@ -1,28 +1,17 @@ namespace Core { - public class CoreInterface + public sealed class CoreInterface { - private static readonly Dictionary coreAssociations = new Dictionary(); + private readonly EntryPoint entryPoint; + + internal CoreInterface(EntryPoint entryPoint) + { + this.entryPoint = entryPoint; + } public T GetPlugin() where T : IProjectPlugin { - return coreAssociations[this].GetPlugin(); - } - - 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(); } } } diff --git a/Core/EntryPoint.cs b/Core/EntryPoint.cs index 96fdd19..aa061ad 100644 --- a/Core/EntryPoint.cs +++ b/Core/EntryPoint.cs @@ -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); } diff --git a/DistTestCore/DistTest.cs b/DistTestCore/DistTest.cs index 2d7c5e6..594b8d3 100644 --- a/DistTestCore/DistTest.cs +++ b/DistTestCore/DistTest.cs @@ -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(); diff --git a/DistTestCore/TestLifecycle.cs b/DistTestCore/TestLifecycle.cs index 8f9f600..66be2e1 100644 --- a/DistTestCore/TestLifecycle.cs +++ b/DistTestCore/TestLifecycle.cs @@ -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() { diff --git a/Tests/AutoBootstrapDistTest.cs b/Tests/AutoBootstrapDistTest.cs index 950b082..b22b439 100644 --- a/Tests/AutoBootstrapDistTest.cs +++ b/Tests/AutoBootstrapDistTest.cs @@ -13,7 +13,7 @@ namespace Tests public IOnlineCodexNode AddCodex(Action 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 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!; diff --git a/Tests/BasicTests/ExampleTests.cs b/Tests/BasicTests/ExampleTests.cs index 8934386..15c82f5 100644 --- a/Tests/BasicTests/ExampleTests.cs +++ b/Tests/BasicTests/ExampleTests.cs @@ -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)); diff --git a/Tests/BasicTests/NetworkIsolationTest.cs b/Tests/BasicTests/NetworkIsolationTest.cs index da1be63..38e9a49 100644 --- a/Tests/BasicTests/NetworkIsolationTest.cs +++ b/Tests/BasicTests/NetworkIsolationTest.cs @@ -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)); diff --git a/Tests/BasicTests/OneClientTests.cs b/Tests/BasicTests/OneClientTests.cs index 5fa2636..dd74924 100644 --- a/Tests/BasicTests/OneClientTests.cs +++ b/Tests/BasicTests/OneClientTests.cs @@ -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(); diff --git a/Tests/BasicTests/TwoClientTests.cs b/Tests/BasicTests/TwoClientTests.cs index 909f29c..7c34053 100644 --- a/Tests/BasicTests/TwoClientTests.cs +++ b/Tests/BasicTests/TwoClientTests.cs @@ -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); } diff --git a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index aee601b..b5e7edf 100644 --- a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -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();