|
| 1 | +using EasyNetQ; |
| 2 | + |
| 3 | +namespace EasyNetQ.Benchmarks; |
| 4 | + |
| 5 | +public class SmallMessage |
| 6 | +{ |
| 7 | + public int Id { get; set; } |
| 8 | + public string Name { get; set; } = ""; |
| 9 | +} |
| 10 | + |
| 11 | +public class MediumMessage |
| 12 | +{ |
| 13 | + public int Id { get; set; } |
| 14 | + public string Name { get; set; } = ""; |
| 15 | + public string Email { get; set; } = ""; |
| 16 | + public string Description { get; set; } = ""; |
| 17 | + public DateTime CreatedAt { get; set; } |
| 18 | + public List<string> Tags { get; set; } = []; |
| 19 | + public Dictionary<string, string> Metadata { get; set; } = []; |
| 20 | +} |
| 21 | + |
| 22 | +public class LargeMessage |
| 23 | +{ |
| 24 | + public int Id { get; set; } |
| 25 | + public string Name { get; set; } = ""; |
| 26 | + public string Email { get; set; } = ""; |
| 27 | + public string Description { get; set; } = ""; |
| 28 | + public DateTime CreatedAt { get; set; } |
| 29 | + public List<string> Tags { get; set; } = []; |
| 30 | + public Dictionary<string, string> Metadata { get; set; } = []; |
| 31 | + public List<LargeMessageItem> Items { get; set; } = []; |
| 32 | +} |
| 33 | + |
| 34 | +public class LargeMessageItem |
| 35 | +{ |
| 36 | + public int Id { get; set; } |
| 37 | + public string Title { get; set; } = ""; |
| 38 | + public decimal Price { get; set; } |
| 39 | + public int Quantity { get; set; } |
| 40 | +} |
| 41 | + |
| 42 | +[Exchange(Name = "custom-exchange")] |
| 43 | +[Queue(Name = "custom-queue")] |
| 44 | +public class AttributedMessage |
| 45 | +{ |
| 46 | + public int Id { get; set; } |
| 47 | + public string Name { get; set; } = ""; |
| 48 | +} |
| 49 | + |
| 50 | +public static class SampleMessages |
| 51 | +{ |
| 52 | + public static SmallMessage CreateSmall() => new() |
| 53 | + { |
| 54 | + Id = 1, |
| 55 | + Name = "Test" |
| 56 | + }; |
| 57 | + |
| 58 | + public static MediumMessage CreateMedium() => new() |
| 59 | + { |
| 60 | + Id = 42, |
| 61 | + Name = "John Doe", |
| 62 | + Email = "john@example.com", |
| 63 | + Description = "A medium-sized message with several properties for benchmarking purposes.", |
| 64 | + CreatedAt = new DateTime(2024, 1, 15, 10, 30, 0, DateTimeKind.Utc), |
| 65 | + Tags = ["benchmark", "test", "performance", "easynetq"], |
| 66 | + Metadata = new Dictionary<string, string> |
| 67 | + { |
| 68 | + ["source"] = "benchmark", |
| 69 | + ["version"] = "1.0", |
| 70 | + ["environment"] = "production" |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + public static LargeMessage CreateLarge() => new() |
| 75 | + { |
| 76 | + Id = 99, |
| 77 | + Name = "Jane Smith", |
| 78 | + Email = "jane@example.com", |
| 79 | + Description = "A large message containing a collection of items for benchmarking serialization performance with realistic payloads.", |
| 80 | + CreatedAt = new DateTime(2024, 6, 1, 14, 0, 0, DateTimeKind.Utc), |
| 81 | + Tags = ["benchmark", "test", "performance", "easynetq", "large", "payload", "serialization"], |
| 82 | + Metadata = new Dictionary<string, string> |
| 83 | + { |
| 84 | + ["source"] = "benchmark", |
| 85 | + ["version"] = "2.0", |
| 86 | + ["environment"] = "production", |
| 87 | + ["region"] = "us-east-1", |
| 88 | + ["priority"] = "high" |
| 89 | + }, |
| 90 | + Items = Enumerable.Range(1, 50).Select(i => new LargeMessageItem |
| 91 | + { |
| 92 | + Id = i, |
| 93 | + Title = $"Item {i} - Product with a moderately long description for realism", |
| 94 | + Price = 9.99m + i, |
| 95 | + Quantity = i * 2 |
| 96 | + }).ToList() |
| 97 | + }; |
| 98 | + |
| 99 | + public static object Create(string size) => size switch |
| 100 | + { |
| 101 | + "Small" => CreateSmall(), |
| 102 | + "Medium" => CreateMedium(), |
| 103 | + "Large" => CreateLarge(), |
| 104 | + _ => throw new ArgumentException($"Unknown size: {size}", nameof(size)) |
| 105 | + }; |
| 106 | + |
| 107 | + public static Type GetType(string size) => size switch |
| 108 | + { |
| 109 | + "Small" => typeof(SmallMessage), |
| 110 | + "Medium" => typeof(MediumMessage), |
| 111 | + "Large" => typeof(LargeMessage), |
| 112 | + _ => throw new ArgumentException($"Unknown size: {size}", nameof(size)) |
| 113 | + }; |
| 114 | +} |
0 commit comments