Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: unique name filtering for call interceptors #79

Merged
merged 5 commits into from
Sep 3, 2020

Conversation

mikel785
Copy link
Contributor

@mikel785 mikel785 commented Sep 2, 2020

Hello guys:

Found and fixed a strange behavior when call interception mechanics works perfect with unnamed services but always failing for named services. Down there is slightly modified test code to reproduce the problem:

		[TestMethod]
		public void CallInterceptionBug()
		{
			using (var host = new ZyanComponentHost("FirstTestServer", 18888))
			{
				host.RegisterComponent<ITestService, TestService>("Blah", ActivationType.Singleton);

				using (var connection = new ZyanConnection("tcp://127.0.0.1:18888/FirstTestServer") { CallInterceptionEnabled = true })
				{
					// add a call interceptor for the TestService.TestMethod
					connection.CallInterceptors.Add(CallInterceptor.For<ITestService>().Action(service => service.TestMethod(), data =>
					{
						data.Intercepted = true;
						data.MakeRemoteCall();
						data.ReturnValue = nameof(TestService);
					}));

					var testService = connection.CreateProxy<ITestService>("Blah");
					var result = testService.TestMethod();
					Assert.AreEqual(nameof(TestService), result);
				}
			}
		}

Also implemented name filtering feature for CallInterceptor to specify unique via regex not by just equality compare to make interceptor declaration more flexible:

					connection.CallInterceptors.Add(CallInterceptor.For<ITestService>()
						.WithUniqueNameFilter(@"NamedService\d+")
						.Action(service => service.TestMethod(), data =>
						{
							data.ReturnValue = $"intercepted_{data.MakeRemoteCall()}";
							data.Intercepted = true;
						})); 

@mikel785 mikel785 marked this pull request as draft September 3, 2020 01:20
@mikel785 mikel785 force-pushed the feature-unique-name-filtering branch from 608b967 to 7158c00 Compare September 3, 2020 02:32
@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2020

Codecov Report

Merging #79 into master will increase coverage by 0.16%.
The diff coverage is 78.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #79      +/-   ##
==========================================
+ Coverage   68.46%   68.63%   +0.16%     
==========================================
  Files         297      297              
  Lines       22488    22639     +151     
  Branches     1952     1978      +26     
==========================================
+ Hits        15397    15538     +141     
- Misses       6271     6273       +2     
- Partials      820      828       +8     
Impacted Files Coverage Δ
source/Zyan.Communication/CallInterceptorHelper.cs 32.53% <63.15%> (+6.45%) ⬆️
source/Zyan.Communication/CallInterceptionData.cs 81.48% <66.66%> (-2.52%) ⬇️
source/Zyan.Tests/CallInterceptionTests.cs 85.47% <77.08%> (-5.57%) ⬇️
...ource/Zyan.Communication/CallInterceptorBuilder.cs 98.79% <87.50%> (+0.06%) ⬆️
source/Zyan.Communication/CallInterceptor.cs 66.00% <100.00%> (+7.46%) ⬆️
...ce/Zyan.Communication/CallInterceptorCollection.cs 63.41% <100.00%> (-2.50%) ⬇️
source/Zyan.Communication/ZyanProxy.cs 77.74% <100.00%> (ø)
...an.Communication/Threading/SimpleLockThreadPool.cs 84.90% <0.00%> (+0.94%) ⬆️
...yan.Communication/InterLinq/Types/TypeConverter.cs 74.01% <0.00%> (+9.44%) ⬆️
...ation/InterLinq/Types/Anonymous/AnonymousObject.cs 17.85% <0.00%> (+14.28%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bfd674d...7158c00. Read the comment docs.

@mikel785 mikel785 marked this pull request as ready for review September 3, 2020 02:37
@yallie
Copy link
Member

yallie commented Sep 3, 2020

Hi Mikel, looks great! 👍
Is it ready for merging?

@yallie yallie added this to the 2.14 milestone Sep 3, 2020
@mikel785
Copy link
Contributor Author

mikel785 commented Sep 3, 2020

Hello, Alexey! Seems ok now, all tests passing and by-default interception performance not changed. I am using both bug fixing and name filtering in production already. Таки будем посмотреть)

Yep it is ready

@yallie yallie merged commit f2a05b4 into zyanfx:master Sep 3, 2020
@yallie
Copy link
Member

yallie commented Sep 3, 2020

Great! Thanks a lot :)

@mikel785
Copy link
Contributor Author

mikel785 commented Sep 3, 2020

You are welcome 👍

@mikel785 mikel785 deleted the feature-unique-name-filtering branch September 3, 2020 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants