Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed May 16, 2022
2 parents 37bcd6c + 8bfad81 commit 34edc3b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 27 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
3.4.2
17 changes: 8 additions & 9 deletions src/Moryx.Runtime.Kernel/Modules/Components/ModuleStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,21 @@ public void StartAll()

private void StartModule(IServerModule module)
{
// Check for any failed dependencies
var hasfailedDependecies = _dependencyManager.GetDependencyBranch(module).Dependencies
.Any(item => item.RepresentedModule.State == ServerModuleState.Failure);
// Don't try to start modules which initialization has been failed or for which dependency initializations have failed
if (module.State == ServerModuleState.Failure || hasfailedDependecies)
return;

// Now we check for any not running dependencies and start them
var awaitingDependecies = _dependencyManager.GetDependencyBranch(module).Dependencies
.Where(item => !item.RepresentedModule.State.HasFlag(ServerModuleState.Running))
.Select(item => item.RepresentedModule).ToArray();
if (awaitingDependecies.Any())
{
EnqueServiceAndStartDependencies(awaitingDependecies, module);
}
else
{
// Don't try to start modules which initialization has been failed
if (module.State != ServerModuleState.Failure)
{
ThreadPool.QueueUserWorkItem(ExecuteModuleStart, module);
}
}
ThreadPool.QueueUserWorkItem(ExecuteModuleStart, module);
}

private void ExecuteModuleStart(object moduleObj)
Expand Down
16 changes: 4 additions & 12 deletions src/Moryx.Runtime.Kestrel/EndpointCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,24 @@ namespace Moryx.Runtime.Kestrel
{
internal class EndpointCollector
{
private readonly Dictionary<string, Endpoint> _endpoints = new Dictionary<string, Endpoint>();
private readonly ICollection<Endpoint> _endpoints = new List<Endpoint>();

public Endpoint[] AllEndpoints
{
get
{
lock (_endpoints)
{
return _endpoints.Values.ToArray();
return _endpoints.ToArray();
}
}
}

public void AddEndpoint(string address, Endpoint endpoint)
public void AddEndpoint(Endpoint endpoint)
{
lock (_endpoints)
{
_endpoints[address] = endpoint;
}
}

public void RemoveEndpoint(string address)
{
lock (_endpoints)
{
_endpoints.Remove(address);
_endpoints.Add(endpoint);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Moryx.Runtime.Kestrel/KestrelEndpointHosting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ internal void LinkController(Type controller, IContainer moduleContainer)

var authorizeAttr = controller.GetCustomAttribute<AuthorizeAttribute>();
var endpointAtt = controller.GetCustomAttribute<EndpointAttribute>();
_hostingContainer.Resolve<EndpointCollector>().AddEndpoint(address, new Endpoint

var endpointCollector = _hostingContainer.Resolve<EndpointCollector>();
endpointCollector.AddEndpoint(new Endpoint
{
Address = address,
Path = route,
Expand Down
2 changes: 2 additions & 0 deletions src/Moryx.Runtime.Kestrel/VersionController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2021, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Moryx.Communication.Endpoints;
Expand All @@ -25,6 +26,7 @@ public Endpoint[] FilteredEndpoints(string service)
return Collector.AllEndpoints.Where(e => e.Service == service).ToArray();
}

[Obsolete("Will be removed or returns array in the next major")]
[HttpGet("endpoint/{endpoint}")]
public Endpoint GetEndpointConfig(string endpoint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class DefaultCanWriteValueProviderFilter : IValueProviderFilter
/// <inheritdoc />
public bool CheckProperty(PropertyInfo propertyInfo)
{
return propertyInfo.CanWrite;
return propertyInfo.GetSetMethod() != null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2022, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Moryx.Configuration;
using NUnit.Framework;

namespace Moryx.Tests.Configuration.ValueProvider
{
[TestFixture]
public class DefaultCanWriteValueProviderFilterTests
{
[Test(Description = "Test detects private setter right")]
public void DetectPrivateSetter()
{
// Arrange
var filter = new DefaultCanWriteValueProviderFilter();
var classType = typeof(PrivateSetterClass);
var privateSetterProperty = classType.GetProperty(nameof(PrivateSetterClass.PrivateSetterBool));
var noSetterProperty = classType.GetProperty(nameof(PrivateSetterClass.NoSetterBool));

// Act
var canWritePrivateSetter = filter.CheckProperty(privateSetterProperty);
var canWriteNoSetter = filter.CheckProperty(noSetterProperty);

// Assert
Assert.IsFalse(canWritePrivateSetter, "Private setter should be treated as not writable");
Assert.IsFalse(canWriteNoSetter, "No setter should be treated as not writable");
}

public class PrivateSetterClass
{
public bool PrivateSetterBool { get; private set; }

public bool NoSetterBool => false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;
using System.Linq;
using Moryx.Configuration;
using NUnit.Framework;

Expand All @@ -18,7 +17,6 @@ public void SetDefaultsOnlyOnWritableProperties()
var config = new TestConfig1();

// Act

ValueProviderExecutor.Execute(config, new ValueProviderExecutorSettings().AddDefaultValueProvider());

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void TestActiveEndpointsLifeCycle()

_hogController.StartService(ModuleController.ModuleName);
result = _hogController.WaitForService(DependentTestModule.ModuleController.ModuleName, ServerModuleState.Running, 5);
Assert.IsTrue(result, "Service '{0}' did not reach state 'Running' ", ModuleController.ModuleName);
Assert.IsTrue(result, "Service '{0}' did not reach state 'Running' ", DependentTestModule.ModuleController.ModuleName);

endpoints = _versionService.ActiveEndpoints();

Expand Down

0 comments on commit 34edc3b

Please sign in to comment.