diff --git a/samples/DtmSample/AppSettings.cs b/samples/DtmSample/AppSettings.cs index 688e7e1..43bccbf 100644 --- a/samples/DtmSample/AppSettings.cs +++ b/samples/DtmSample/AppSettings.cs @@ -2,10 +2,15 @@ { public class AppSettings { + public string DtmUrl { get; set; } + public string BusiUrl { get; set; } public string SqlBarrierConn { get; set; } + + public string SqlBarrierErrorConn { get; set; } + public string MongoBarrierConn { get; set; } } } diff --git a/samples/DtmSample/Controllers/MsgTestController.cs b/samples/DtmSample/Controllers/MsgTestController.cs index a6efcd0..36decaa 100644 --- a/samples/DtmSample/Controllers/MsgTestController.cs +++ b/samples/DtmSample/Controllers/MsgTestController.cs @@ -1,4 +1,5 @@ -using System.Net; +using System; +using System.Net; using Dtmcli; using DtmMongoBarrier; using DtmSample.Dtos; @@ -37,6 +38,9 @@ public MsgTestController(ILogger logger, IOptions new(_settings.SqlBarrierConn); private SqlConnection GetMssqlConn() => new(_settings.SqlBarrierConn); + + private SqlConnection GetBadMssqlConn() => new(_settings.SqlBarrierErrorConn); + private MySqlConnection GetErrConn() => new(""); @@ -116,6 +120,40 @@ await msg.DoAndSubmitDB(_settings.BusiUrl + "/msg-mssqlqueryprepared", conn, asy return Ok(TransResponse.BuildSucceedResponse()); } + + /// + /// MSG DoAndSubmitDB (mssql). db connection error, DTM server Status should be prepared. + /// + /// + /// + [HttpPost("msg-db-mssql-db-connection-error")] + public async Task MsgDbMsSql_DbConnectionError(CancellationToken cancellationToken) + { + var gid = await _dtmClient.GenGid(cancellationToken); + + var msg = _transFactory.NewMsg(gid) + .Add(_settings.BusiUrl + "/TransOut", new TransRequest("1", -30)) + .Add(_settings.BusiUrl + "/TransIn", new TransRequest("2", 30)); + + try + { + using (SqlConnection conn = GetBadMssqlConn()) + { + await msg.DoAndSubmitDB(_settings.BusiUrl + "/msg-mssqlqueryprepared", conn, async tx => { await Task.CompletedTask; }); + } + } + catch (SqlException e) + { + Thread.Sleep(5 * 1000); + _logger.LogInformation("{}/admin/global-transactions/detail/{}, status should be prepared", _settings.DtmUrl, gid); + throw; + } + + _logger.LogInformation("result gid is {0}", gid); + return Ok(TransResponse.BuildSucceedResponse()); + } + + /// /// MSG DoAndSubmit (mongo) /// diff --git a/samples/DtmSample/appsettings.json b/samples/DtmSample/appsettings.json index 5916f0c..50bd3dd 100644 --- a/samples/DtmSample/appsettings.json +++ b/samples/DtmSample/appsettings.json @@ -24,6 +24,7 @@ "SqlDbType": "sqlserver", "BarrierSqlTableName": "dbo.barrier", "SqlBarrierConn": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=dtm_barrier;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "SqlBarrierErrorConn": "Data Source=.;Initial Catalog=dtm_barrier;User ID=sa;Password=my_error_password;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", "MongoBarrierConn": "mongodb://localhost:27017" } } \ No newline at end of file