You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConsumerServiceSelectorTest.cs 5.3 KiB

7 years ago
Release 2.1 (#55) * add dashboard branch. * add dashboard * add helper methods. * Add data model. * add options. * add empty implement * add dashbaord * add dashboard * Fixed spelling error * rename file. * add dashbaord feature * impl dashboard storage * update nuget reference. * add pages. * deleted unused fiels. * modify resource. * update resource. * rename * update dashboard * rename * impl monitoring api interface. * update solution files. * update samples. * dashboard. * add jsonview resource files. * add json dispatcher. * modify published pages. * add routes. * update pages. * update resources. * update dashboard. * add dashboard of sql server storage impl * nesting files. * fixed query bug. * update resource. * remove some api. * add subscriber page. * update sample * add resource. * remove api. * add SubscriberPage * add resource * generate cshtml. * modify html two table to one table. * update resource. * update css * update subscriber page. * refactor. * cleanup. * cleanup code. * impl history monitoring api. * add home page recevied message real-time * add legend styles. * update js. * modify axis color. * add resource. * update dashboard home page. * update css. * update resource. * modify DefaultSucceedMessageExpirationAfter to 24 hours. * add resx, * add consul discovery. * remove unused file. * add node page. * add node page * node discovery * add kafka sqlserver sample. * update sample. * add okstats. * refactor. * fixed kafka client bugs. * modify node and subscriber pages * refactor. * add Gateway middleware * remove unused files. * update resource. * update gateway. * refactor. * update samples. * remove base middleware * add node switch click event. * add NodeId config to options. * upgrade dependent version. * add PathMatch configuration * update NodePage.cshtml * remove session * remove matchPath * refactor * refactor dashboard middleware * gateway proxy middleware function maturation * remove cookie exp * refactor and remove files. * add CapCache to cache server nodes. * refactor. * renamed message dto. * add extended interface of IContentSerializer and JsonContentSerializer * modify unit test * check the requirement when CAP start. * correct spelling * cleanup code. * add resources. * processing pages will contains Scheduled and Enqueued messages. * processing pages will contains Scheduled and Enqueued messages. * ignore NU1701 Warning. * renamed file. * refactor * implements dashboard interface. * rename reference class. * add mysql monitoring api impl * fix bug of connection driver. * remove cap.UseDashboard. It's will be automatically enabled by registerd services. * fix sql bug * cleanup code and fix spelling * fix postgre sql bug. * fix mysql sql bug. * when storage a received message raising an eception, we will reject the message to queue. * fix spelling mistake * add dashboard instructions to readme * modify error log content. * fix postger sql bug. * fix consul discovery bug. * add dashboard introduction to readme.md * update english resource. * Update README.md * renamed files. * fix postgre sql bug. * cleanup code. * update tests. * rename file. * update samples. * Improved query performance without lock table. (#36) * update sample. * update samples. * fix data reader uncolsed bug. * update add jsonproperty * refactor * revert FetchNextMessageAsync sql * add helper method. * rafactor subscriber handler. * add FailedRetryCount options. * rafactor publisher excutor. * add IPublishExecutor * add failed message processor. * inject failed message processor. * refactor sql storage. * fixed unit tests. * fixed unit test. * fixed postgresql tests. * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * add LAN ip to LocalRequestsOnlyAuthorizationFilter * add and update resource. * add current node name to layout page if user enabled node discovery * modify unit tests. * add callback message sende tests. * add deserlizer by type to IContentSerializer * refactor unit tests * add summary comment. * refactor async method. * add comment and fixed spell error. * refactor. * add custom content serializer extension to CapBuilder * add IMessagePacker * refactor. * add connection pool for kafka producer. * add determines whether the query is null. * add connection pool size config to KafkaOption. * fixed json JObject bug * add custom message wapper interface * remove unused code. * fixed callback topic send error bug. * refactor. * update unit tests. * update samples. * upgrade dependent package. * remove some class from Abstraction namespce to Internal. * optimize consumer related code * add ICallbackMessageSender to DI with singleton. * add and fixed some unit tests. * refactor namespace. * modify class protected level * assemblies internal class are visible to test project * add DeSerialize method to IContentSerializer with type deseralize * refactoring * Fix the phone style dispaly problem * add logs * refactoring * upgrading `Confluent.Kafka` package * Optimize message queue error message prompt. * reorganize error message prompts. * modify error message prompt * add summary comments. * modify dependent * disabled print connection closed log. see: https://github.com/edenhill/librdkafka/issues/516 * Update README.md * Update README.md * Update README.zh-cn.md * Update README.zh-cn.md * fix dashboard not config discovery throw exceptions bug. * Update README.md * update readme * Fixed serialized the message type bug. (#53) * Update README.md * Update README.md * refactoring * refactoring * update readme. * update readme. * add summary comment. * refactoring * optimizing publisher interface * update readme * update readme. * add summary comment. * add summary comment. * add summary comment. * add summary comment. * upgrading package * add summary comment. * optimize the RabbitMQ connection pool * fix the producer connection returned * dispose resource when connection pool is full
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP.Abstractions;
  4. using DotNetCore.CAP.Internal;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Xunit;
  7. namespace DotNetCore.CAP.Test
  8. {
  9. public class ConsumerServiceSelectorTest
  10. {
  11. private IServiceProvider _provider;
  12. public ConsumerServiceSelectorTest()
  13. {
  14. var services = new ServiceCollection();
  15. //services.AddSingleton<IConsumerServiceSelector, DefaultConsumerServiceSelector>();
  16. services.AddScoped<IFooTest, CandidatesFooTest>();
  17. services.AddScoped<IBarTest, CandidatesBarTest>();
  18. services.AddLogging();
  19. services.AddCap(x => { });
  20. _provider = services.BuildServiceProvider();
  21. }
  22. [Fact]
  23. public void CanFindAllConsumerService()
  24. {
  25. var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
  26. var candidates = selector.SelectCandidates();
  27. Assert.Equal(6, candidates.Count);
  28. }
  29. [Fact]
  30. public void CanFindSpecifiedTopic()
  31. {
  32. var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
  33. var candidates = selector.SelectCandidates();
  34. var bestCandidates = selector.SelectBestCandidate("Candidates.Foo", candidates);
  35. Assert.NotNull(bestCandidates);
  36. Assert.NotNull(bestCandidates.MethodInfo);
  37. Assert.Equal(typeof(Task), bestCandidates.MethodInfo.ReturnType);
  38. }
  39. [Theory]
  40. [InlineData("Candidates.Asterisk")]
  41. [InlineData("candidates.Asterisk")]
  42. [InlineData("AAA.BBB.Asterisk")]
  43. [InlineData("aaa.bbb.Asterisk")]
  44. public void CanFindAsteriskTopic(string topic)
  45. {
  46. var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
  47. var candidates = selector.SelectCandidates();
  48. var bestCandidates = selector.SelectBestCandidate(topic, candidates);
  49. Assert.NotNull(bestCandidates);
  50. }
  51. [Theory]
  52. [InlineData("Candidates.Asterisk.AAA")]
  53. [InlineData("AAA.BBB.CCC.Asterisk")]
  54. [InlineData("aaa.BBB.ccc.Asterisk")]
  55. [InlineData("Asterisk.aaa.bbb")]
  56. public void CanNotFindAsteriskTopic(string topic)
  57. {
  58. var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
  59. var candidates = selector.SelectCandidates();
  60. var bestCandidates = selector.SelectBestCandidate(topic, candidates);
  61. Assert.Null(bestCandidates);
  62. }
  63. [Theory]
  64. [InlineData("Candidates.Pound.AAA")]
  65. [InlineData("Candidates.Pound.AAA.BBB")]
  66. [InlineData("AAA.Pound")]
  67. [InlineData("aaa.Pound")]
  68. [InlineData("aaa.bbb.Pound")]
  69. [InlineData("aaa.BBB.Pound")]
  70. public void CanFindPoundTopic(string topic)
  71. {
  72. var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
  73. var candidates = selector.SelectCandidates();
  74. var bestCandidates = selector.SelectBestCandidate(topic, candidates);
  75. Assert.NotNull(bestCandidates);
  76. }
  77. [Theory]
  78. [InlineData("Pound")]
  79. [InlineData("aaa.Pound.AAA.BBB")]
  80. [InlineData("Pound.AAA")]
  81. [InlineData("Pound.aaa")]
  82. [InlineData("AAA.Pound.aaa")]
  83. public void CanNotFindPoundTopic(string topic)
  84. {
  85. var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
  86. var candidates = selector.SelectCandidates();
  87. var bestCandidates = selector.SelectBestCandidate(topic, candidates);
  88. Assert.Null(bestCandidates);
  89. }
  90. }
  91. public class CandidatesTopic : TopicAttribute
  92. {
  93. public CandidatesTopic(string topicName) : base(topicName)
  94. {
  95. }
  96. }
  97. public interface IFooTest
  98. {
  99. }
  100. public interface IBarTest
  101. {
  102. }
  103. public class CandidatesFooTest : IFooTest, ICapSubscribe
  104. {
  105. [CandidatesTopic("Candidates.Foo")]
  106. public Task GetFoo()
  107. {
  108. Console.WriteLine("GetFoo() method has bee excuted.");
  109. return Task.CompletedTask;
  110. }
  111. [CandidatesTopic("Candidates.Foo2")]
  112. public void GetFoo2()
  113. {
  114. Console.WriteLine("GetFoo2() method has bee excuted.");
  115. }
  116. [CandidatesTopic("*.*.Asterisk")]
  117. [CandidatesTopic("*.Asterisk")]
  118. public void GetFooAsterisk()
  119. {
  120. Console.WriteLine("GetFoo2Asterisk() method has bee excuted.");
  121. }
  122. [CandidatesTopic("Candidates.Pound.#")]
  123. [CandidatesTopic("#.Pound")]
  124. public void GetFooPound()
  125. {
  126. Console.WriteLine("GetFoo2Pound() method has bee excuted.");
  127. }
  128. }
  129. public class CandidatesBarTest : IBarTest
  130. {
  131. [CandidatesTopic("Candidates.Bar")]
  132. public Task GetBar()
  133. {
  134. Console.WriteLine("GetBar() method has bee excuted.");
  135. return Task.CompletedTask;
  136. }
  137. [CandidatesTopic("Candidates.Bar2")]
  138. public void GetBar2()
  139. {
  140. Console.WriteLine("GetBar2() method has bee excuted.");
  141. }
  142. public void GetBar3()
  143. {
  144. Console.WriteLine("GetBar3() method has bee excuted.");
  145. }
  146. }
  147. }