|
1 | 1 | using System; |
2 | 2 | using System.Linq; |
3 | 3 | using System.Text; |
4 | | -using System.Text.RegularExpressions; |
5 | 4 | using System.Threading; |
6 | 5 | using System.Threading.Tasks; |
7 | 6 | using DotNetProjects.Migrator.Framework.Data.Common; |
|
19 | 18 |
|
20 | 19 | namespace Migrator.Tests.Database.DerivedDatabaseIntegrationTestServices; |
21 | 20 |
|
22 | | -public partial class OracleDatabaseIntegrationTestService( |
| 21 | + |
| 22 | +/// <summary> |
| 23 | +/// We use the tablespace users since the server container is recreated before the test runs (once per github workflow run) |
| 24 | +/// </summary> |
| 25 | +/// <param name="timeProvider"></param> |
| 26 | +/// <param name="databaseNameService"></param> |
| 27 | +public class OracleDatabaseIntegrationTestService( |
23 | 28 | TimeProvider timeProvider, |
24 | 29 | IDatabaseNameService databaseNameService) |
25 | 30 | : DatabaseIntegrationTestServiceBase(databaseNameService), IDatabaseIntegrationTestService |
26 | 31 | { |
27 | | - private const string TableSpacePrefix = "TS_"; |
28 | 32 | private const string UserStringKey = "User Id"; |
29 | 33 | private const string PasswordStringKey = "Password"; |
30 | 34 | private const string ReplaceString = "RandomStringThatIsNotQuotedByTheBuilderDoNotChange"; |
31 | 35 | private readonly MappingSchema _mappingSchema = new MappingSchemaFactory().CreateOracleMappingSchema(); |
32 | | - private Regex _tablespaceRegex = new("^TS_TESTS_"); |
33 | 36 |
|
34 | 37 | /// <summary> |
35 | 38 | /// Creates an oracle database for test purposes. |
@@ -109,62 +112,11 @@ await Parallel.ForEachAsync( |
109 | 112 | await DropDatabaseAsync(databaseInfoToBeDeleted, cancellationTokenInner); |
110 | 113 | }); |
111 | 114 |
|
112 | | - // To be on the safe side we check for table spaces used in tests that have not been deleted for any reason (possible connection issues/concurrent deletion attempts - there is |
113 | | - // no transaction for DDL in Oracle etc.). |
114 | | - var tableSpaceNames = await context.GetTable<DBADataFiles>() |
115 | | - .Select(x => x.TablespaceName) |
116 | | - .ToListAsync(cancellationToken); |
117 | | - |
118 | | - var toBeDeletedTableSpaces = tableSpaceNames |
119 | | - .Where(x => |
120 | | - { |
121 | | - var replacedTablespaceString = TableSpacePrefixRegex().Replace(x, ""); |
122 | | - var creationDate = DatabaseNameService.ReadTimeStampFromString(replacedTablespaceString); |
123 | | - return creationDate.HasValue && creationDate.Value < timeProvider.GetUtcNow().Subtract(_MinTimeSpanBeforeDatabaseDeletion); |
124 | | - }); |
125 | | - |
126 | | - foreach (var toBeDeletedTableSpace in toBeDeletedTableSpaces) |
127 | | - { |
128 | | - var maxAttempts = 4; |
129 | | - var delayBetweenAttempts = TimeSpan.FromSeconds(1); |
130 | | - |
131 | | - for (var i = 0; i < maxAttempts; i++) |
132 | | - { |
133 | | - try |
134 | | - { |
135 | | - await context.ExecuteAsync($"DROP TABLESPACE {toBeDeletedTableSpace} INCLUDING CONTENTS AND DATAFILES", cancellationToken); |
136 | | - } |
137 | | - catch |
138 | | - { |
139 | | - var exists = await context.GetTable<DBADataFiles>().AnyAsync(x => x.TablespaceName == toBeDeletedTableSpace, cancellationToken); |
140 | | - |
141 | | - if (!exists) |
142 | | - { |
143 | | - break; |
144 | | - } |
145 | | - |
146 | | - if (i + 1 == maxAttempts) |
147 | | - { |
148 | | - throw; |
149 | | - } |
150 | | - |
151 | | - await Task.Delay(delayBetweenAttempts, cancellationToken); |
152 | | - |
153 | | - delayBetweenAttempts = delayBetweenAttempts.Add(TimeSpan.FromSeconds(1)); |
154 | | - } |
155 | | - } |
156 | | - } |
157 | | - |
158 | | - var tableSpaceName = $"{TableSpacePrefix}{tempUserName}"; |
159 | | - |
160 | | - var createTablespaceSql = $"CREATE TABLESPACE {tableSpaceName}"; |
161 | | - await context.ExecuteAsync(createTablespaceSql, cancellationToken: cancellationToken); |
162 | | - |
163 | 115 | var stringBuilder = new StringBuilder(); |
164 | 116 | stringBuilder.Append($"CREATE USER \"{tempUserName}\" IDENTIFIED BY \"{tempUserName}\""); |
165 | | - stringBuilder.AppendLine($"DEFAULT TABLESPACE {tableSpaceName}"); |
| 117 | + stringBuilder.AppendLine($"DEFAULT TABLESPACE users"); |
166 | 118 | stringBuilder.AppendLine($"TEMPORARY TABLESPACE TEMP"); |
167 | | - stringBuilder.AppendLine($"QUOTA UNLIMITED ON {tableSpaceName}"); |
| 119 | + stringBuilder.AppendLine($"QUOTA UNLIMITED ON users"); |
168 | 120 |
|
169 | 121 | await context.ExecuteAsync(stringBuilder.ToString(), cancellationToken); |
170 | 122 |
|
@@ -253,40 +205,6 @@ public override async Task DropDatabaseAsync(DatabaseInfo databaseInfo, Cancella |
253 | 205 | } |
254 | 206 | } |
255 | 207 |
|
256 | | - var tablespaceName = $"{TableSpacePrefix}{databaseInfo.SchemaName}"; |
257 | | - |
258 | | - maxAttempts = 4; |
259 | | - delayBetweenAttempts = TimeSpan.FromSeconds(1); |
260 | | - |
261 | | - for (var i = 0; i < maxAttempts; i++) |
262 | | - { |
263 | | - try |
264 | | - { |
265 | | - await context.ExecuteAsync($"DROP TABLESPACE {tablespaceName} INCLUDING CONTENTS AND DATAFILES", cancellationToken); |
266 | | - } |
267 | | - catch |
268 | | - { |
269 | | - var exists = await context.GetTable<DBADataFiles>().AnyAsync(x => x.TablespaceName == tablespaceName, cancellationToken); |
270 | | - |
271 | | - if (!exists) |
272 | | - { |
273 | | - break; |
274 | | - } |
275 | | - |
276 | | - if (i + 1 == maxAttempts) |
277 | | - { |
278 | | - throw; |
279 | | - } |
280 | | - |
281 | | - await Task.Delay(delayBetweenAttempts, cancellationToken); |
282 | | - |
283 | | - delayBetweenAttempts = delayBetweenAttempts.Add(TimeSpan.FromSeconds(1)); |
284 | | - } |
285 | | - } |
286 | | - |
287 | 208 | await context.ExecuteAsync($"PURGE RECYCLEBIN", cancellationToken); |
288 | 209 | } |
289 | | - |
290 | | - [GeneratedRegex("^TS_TESTS_")] |
291 | | - private static partial Regex TableSpacePrefixRegex(); |
292 | 210 | } |
0 commit comments