|
32 | 32 | using System;
|
33 | 33 | using System.Diagnostics;
|
34 | 34 | using System.IO;
|
35 |
| -using System.Text.RegularExpressions; |
36 | 35 | using System.Threading.Tasks;
|
37 |
| -using RabbitMQ.Client; |
38 | 36 | using Xunit.Abstractions;
|
39 | 37 |
|
40 | 38 | namespace Test
|
41 | 39 | {
|
42 | 40 | public class RabbitMQCtl
|
43 | 41 | {
|
44 |
| - private static readonly char[] newLine = new char[] { '\n' }; |
45 |
| - // NOTE: \r? |
46 |
| - // https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options#multiline-mode |
47 |
| - private static readonly Regex s_getConnectionProperties = |
48 |
| - new Regex(@"^(?<pid><[^>]*>)\s\[.*""connection_name"",""(?<connection_name>[^""]*)"".*\]\r?$", RegexOptions.Multiline | RegexOptions.Compiled); |
49 |
| - |
50 | 42 | private readonly ITestOutputHelper _output;
|
51 | 43 |
|
52 | 44 | public RabbitMQCtl(ITestOutputHelper output)
|
53 | 45 | {
|
54 | 46 | _output = output;
|
55 | 47 | }
|
56 | 48 |
|
57 |
| - public async Task CloseConnectionAsync(IConnection conn) |
58 |
| - { |
59 |
| - string pid = await GetConnectionPidAsync(conn.ClientProvidedName); |
60 |
| - await CloseConnectionAsync(pid); |
61 |
| - } |
62 |
| - |
63 |
| - public Task AddUserAsync(string username, string password) |
64 |
| - { |
65 |
| - return ExecRabbitMQCtlAsync($"add_user {username} {password}"); |
66 |
| - } |
67 |
| - |
68 |
| - public Task ChangePasswordAsync(string username, string password) |
69 |
| - { |
70 |
| - return ExecRabbitMQCtlAsync($"change_password {username} {password}"); |
71 |
| - } |
72 |
| - |
73 |
| - public Task SetPermissionsAsync(string username, string conf, string write, string read) |
74 |
| - { |
75 |
| - return ExecRabbitMQCtlAsync($"set_permissions {username} \"{conf}\" \"{write}\" \"${read}\" "); |
76 |
| - } |
77 |
| - |
78 |
| - public Task DeleteUserAsync(string username) |
79 |
| - { |
80 |
| - return ExecRabbitMQCtlAsync($"delete_user {username}"); |
81 |
| - } |
82 |
| - |
83 | 49 | public async Task<string> ExecRabbitMQCtlAsync(string args)
|
84 | 50 | {
|
85 | 51 | try
|
@@ -139,28 +105,6 @@ private static ProcessStartInfo GetRabbitMqCtlStartInfo(string args)
|
139 | 105 | return CreateProcessStartInfo(path, args);
|
140 | 106 | }
|
141 | 107 |
|
142 |
| - private async Task<string> GetConnectionPidAsync(string connectionName) |
143 |
| - { |
144 |
| - string stdout = await ExecRabbitMQCtlAsync("list_connections --silent pid client_properties"); |
145 |
| - Match match = s_getConnectionProperties.Match(stdout); |
146 |
| - while (match.Success) |
147 |
| - { |
148 |
| - if (match.Groups["connection_name"].Value == connectionName) |
149 |
| - { |
150 |
| - return match.Groups["pid"].Value; |
151 |
| - } |
152 |
| - |
153 |
| - match = match.NextMatch(); |
154 |
| - } |
155 |
| - |
156 |
| - throw new Exception($"No connection found with name: {connectionName}"); |
157 |
| - } |
158 |
| - |
159 |
| - private Task CloseConnectionAsync(string pid) |
160 |
| - { |
161 |
| - return ExecRabbitMQCtlAsync($"close_connection \"{pid}\" \"Closed via rabbitmqctl\""); |
162 |
| - } |
163 |
| - |
164 | 108 | private static ProcessStartInfo CreateProcessStartInfo(string cmd, string arguments, string workDirectory = null)
|
165 | 109 | {
|
166 | 110 | return new ProcessStartInfo
|
|
0 commit comments