Skip to content

Commit 0bcd235

Browse files
author
d4ilys
committed
TDengine增加单元测试
1 parent cd092e9 commit 0bcd235

13 files changed

Lines changed: 233 additions & 91 deletions

File tree

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
</PropertyGroup>
77

8-
<IsPackable>false</IsPackable>
9-
<IsTestProject>true</IsTestProject>
10-
</PropertyGroup>
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9+
<WarningLevel>3</WarningLevel>
10+
<NoWarn>1701;1702;1591</NoWarn>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
15+
<PackageReference Include="xunit" Version="2.4.1" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
</ItemGroup>
1121

12-
<ItemGroup>
13-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15-
<PackageReference Include="NUnit" Version="3.14.0" />
16-
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
18-
</ItemGroup>
1922

2023
<ItemGroup>
21-
<Using Include="NUnit.Framework" />
24+
<ProjectReference Include="..\..\Providers\FreeSql.Provider.TDengine\FreeSql.Provider.TDengine.csproj" />
2225
</ItemGroup>
2326

2427
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Xunit;
3+
4+
namespace FreeSql.Tests.Provider.TDengine.TDengine.TDengineAdo
5+
{
6+
public class TDengineAdoTest
7+
{
8+
IFreeSql fsql => g.tdengine;
9+
10+
[Fact]
11+
public void ExecuteConnectTest()
12+
{
13+
var executeConnectTest = fsql.Ado.ExecuteConnectTest();
14+
Assert.True(executeConnectTest);
15+
}
16+
}
17+
}

FreeSql.Tests/FreeSql.Tests.Provider.TDengine/UnitTest1.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace FreeSql.Tests.Provider.TDengine
10+
{
11+
internal class g
12+
{
13+
static readonly Lazy<IFreeSql> tdengineLazy = new Lazy<IFreeSql>(() =>
14+
{
15+
return new FreeSql.FreeSqlBuilder()
16+
.UseConnectionString(FreeSql.DataType.TDengine,
17+
"Host=127.0.0.1;Port=6030;Username=root;Password=taosdata;Protocol=Native;db=test;Min Pool Size=1;Max Poll Size=10")
18+
.UseAutoSyncStructure(true)
19+
.UseNameConvert(Internal.NameConvertType.ToLower)
20+
.UseMonitorCommand(
21+
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " +
22+
cmd.CommandText) //监听SQL命令对象,在执行前
23+
//, (cmd, traceLog) => Console.WriteLine(traceLog)
24+
)
25+
.Build();
26+
});
27+
28+
public static IFreeSql tdengine => tdengineLazy.Value;
29+
}
30+
}

FreeSql/FreeSql.xml

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/FreeSqlBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ public IFreeSql<TMark> Build<TMark>()
385385
if (type == null) throwNotFind("FreeSql.Provider.Duckdb.dll", "FreeSql.Duckdb.DuckdbProvider<>");
386386
break;
387387

388+
case DataType.TDengine:
389+
type = Type.GetType("FreeSql.TDengine.TDengineProvider`1,FreeSql.Provider.TDengine")?.MakeGenericType(typeof(TMark));
390+
if (type == null) throwNotFind("FreeSql.Provider.TDengine.dll", "FreeSql.TDengine.TDengineProvider<>");
391+
break;
392+
388393
default: throw new Exception(CoreStrings.NotSpecified_UseConnectionString_UseConnectionFactory);
389394
}
390395
}

Providers/FreeSql.Provider.TDengine/TDengineAdo/TDengineAdo.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
using System;
1+
using FreeSql.Internal;
2+
using FreeSql.Internal.CommonProvider;
3+
using FreeSql.Internal.Model;
4+
using FreeSql.Internal.ObjectPool;
5+
using System;
26
using System.Collections;
3-
using System.Collections.Generic;
47
using System.Data.Common;
58
using System.Linq;
6-
using System.Text;
79
using System.Threading;
8-
using System.Threading.Tasks;
9-
using FreeSql.Internal;
10-
using FreeSql.Internal.CommonProvider;
11-
using FreeSql.Internal.Model;
12-
using FreeSql.Internal.ObjectPool;
1310
using TDengine.Data.Client;
1411

15-
namespace FreeSql.Provider.TDengine.TDengineAdo
12+
namespace FreeSql.TDengine
1613
{
1714
internal class TDengineAdo : AdoProvider
1815
{
@@ -32,15 +29,19 @@ public TDengineAdo(CommonUtils util, string masterConnectionString, string[] sla
3229
var isAdoPool = masterConnectionString?.StartsWith("AdoConnectionPool,") ?? false;
3330
if (isAdoPool) masterConnectionString = masterConnectionString.Substring("AdoConnectionPool,".Length);
3431
if (!string.IsNullOrEmpty(masterConnectionString))
35-
MasterPool = isAdoPool ?
36-
new DbConnectionStringPool(base.DataType, CoreStrings.S_MasterDatabase, () => new TDengineConnection(masterConnectionString)) as IObjectPool<DbConnection> :
37-
new TDengineConnectionPool(CoreStrings.S_MasterDatabase, masterConnectionString, null, null);
32+
MasterPool = isAdoPool
33+
? new DbConnectionStringPool(base.DataType, CoreStrings.S_MasterDatabase,
34+
() => new TDengineConnection(masterConnectionString)) as IObjectPool<DbConnection>
35+
: new TDengineConnectionPool(CoreStrings.S_MasterDatabase, masterConnectionString, null, null);
3836

3937
slaveConnectionStrings?.ToList().ForEach(slaveConnectionString =>
4038
{
41-
var slavePool = isAdoPool ?
42-
new DbConnectionStringPool(base.DataType, $"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", () => new TDengineConnection(slaveConnectionString)) as IObjectPool<DbConnection> :
43-
new TDengineConnectionPool($"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables));
39+
var slavePool = isAdoPool
40+
? new DbConnectionStringPool(base.DataType, $"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}",
41+
() => new TDengineConnection(slaveConnectionString)) as IObjectPool<DbConnection>
42+
: new TDengineConnectionPool($"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}",
43+
slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables),
44+
() => Interlocked.Increment(ref slaveUnavailables));
4445
SlavePools.Add(slavePool);
4546
});
4647
}
@@ -96,7 +97,8 @@ public override DbCommand CreateCommand()
9697
return new TDengineCommand();
9798
}
9899

99-
public override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj);
100+
public override DbParameter[] GetDbParamtersByObject(string sql, object obj) =>
101+
_util.GetDbParamtersByObject(sql, obj);
100102

101103
public override void ReturnConnection(IObjectPool<DbConnection> pool, Object<DbConnection> conn, Exception ex)
102104
{

Providers/FreeSql.Provider.TDengine/TDengineAdo/TDengineConnectionPool.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
using System;
1+
using FreeSql.Internal.ObjectPool;
2+
using System;
23
using System.Collections.Concurrent;
3-
using System.Collections.Generic;
44
using System.Data;
55
using System.Data.Common;
6-
using System.Linq;
7-
using System.Text;
86
using System.Text.RegularExpressions;
97
using System.Threading.Tasks;
10-
using FreeSql.Internal.ObjectPool;
118
using TDengine.Data.Client;
129

13-
namespace FreeSql.Provider.TDengine.TDengineAdo
10+
namespace FreeSql.TDengine
1411
{
1512
internal class TDengineConnectionPool : ObjectPool<DbConnection>
1613
{
1714
internal Action AvailableHandler;
1815

1916
internal Action UnavailableHandler;
2017

21-
2218
public TDengineConnectionPool(string name, string connectionString, Action availableHandler,
2319
Action unavailableHandler) : base(null)
2420
{
@@ -111,7 +107,6 @@ public void OnDestroy(DbConnection obj)
111107

112108
public void OnGetTimeout()
113109
{
114-
115110
}
116111

117112
public void OnGet(Object<DbConnection> obj)
@@ -120,13 +115,14 @@ public void OnGet(Object<DbConnection> obj)
120115
{
121116
if (obj.Value == null)
122117
{
123-
InternalPool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy);
118+
InternalPool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError),
119+
obj.LastGetTimeCopy);
124120
throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name));
125121
}
126122

127-
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
123+
if (obj.Value.State != ConnectionState.Open ||
124+
DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
128125
{
129-
130126
try
131127
{
132128
obj.Value.Open();
@@ -149,13 +145,15 @@ public async Task OnGetAsync(Object<DbConnection> obj)
149145
{
150146
if (obj.Value == null)
151147
{
152-
InternalPool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy);
148+
InternalPool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError),
149+
obj.LastGetTimeCopy);
153150
throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name));
154151
}
155152

156-
if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
153+
if (obj.Value.State != ConnectionState.Open ||
154+
DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 &&
155+
(await obj.Value.PingAsync()) == false)
157156
{
158-
159157
try
160158
{
161159
await obj.Value.OpenAsync();

0 commit comments

Comments
 (0)