Browse Source

Update Demo

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
d821f9f9ec
  1. 1
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
  2. 1
      Src/Asp.Net/SqlServerTest/UnitTest/Main.cs
  3. 2
      Src/Asp.Net/SqlServerTest/UnitTest/ObjectsValidate.cs
  4. 1
      Src/Asp.Net/SqlServerTest/UnitTest/UJson.cs
  5. 228
      Src/Asp.Net/SqlServerTest/UnitTest/UThread.cs
  6. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

1
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -143,6 +143,7 @@
<Compile Include="UnitTest\ObjectsValidate.cs" />
<Compile Include="UnitTest\UJson.cs" />
<Compile Include="UnitTest\Main.cs" />
<Compile Include="UnitTest\UThread.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">

1
Src/Asp.Net/SqlServerTest/UnitTest/Main.cs

@ -26,6 +26,7 @@ namespace OrmTest
public static void Init()
{
Json();
Thread();
}
}
}

2
Src/Asp.Net/SqlServerTest/UnitTest/ObjectsValidate.cs

@ -12,7 +12,7 @@ namespace OrmTest
{
if (a?.ToString() != b?.ToString())
{
new Exception(name+" error");
throw new Exception(name + " error");
}
}
}

1
Src/Asp.Net/SqlServerTest/UnitTest/UJson.cs

@ -17,6 +17,7 @@ namespace OrmTest
var list = Db.Queryable<JsonTest>().ToList();
ObjectsValidate.Check("order1", list.First().Order.Name, "Json");
Db.Updateable(new JsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
list= Db.Queryable<JsonTest>().ToList();
ObjectsValidate.Check("order2", list.First().Order.Name, "Json");
var list2 = Db.Queryable<JsonTest>().ToList();
}

228
Src/Asp.Net/SqlServerTest/UnitTest/UThread.cs

@ -0,0 +1,228 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static SqlSugarClient tdb0 => new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (sql, p) =>
{
Console.WriteLine(sql);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
});
public static SqlSugarClient tdb1 => new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
IsShardSameThread = true,
AopEvents = new AopEvents
{
OnLogExecuting = (sql, p) =>
{
Console.WriteLine(sql);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
});
public static SqlSugarClient tdb2 = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (sql, p) =>
{
Console.WriteLine(sql);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
});
public static SqlSugarClient tdb3 = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
IsShardSameThread = true,
AopEvents = new AopEvents
{
OnLogExecuting = (sql, p) =>
{
Console.WriteLine(sql);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
});
public static void Thread()
{
Simple();
IsShardSameThread();
Single();
SingleAndIsShardSameThread();
}
private static void Simple()
{
var t1 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb0.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(1);
}
});
var t2 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb0.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(10);
}
});
var t3 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb0.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(6);
}
});
t1.Start();
t2.Start();
t3.Start();
Task.WaitAll(t1, t2, t3);
}
private static void SingleAndIsShardSameThread()
{
var t1 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb3.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(1);
}
});
var t2 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb3.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(10);
}
});
var t3 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb3.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(6);
}
});
t1.Start();
t2.Start();
t3.Start();
Task.WaitAll(t1, t2, t3);
}
private static void Single()
{
var t1 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb2.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(1);
}
});
var t2 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb2.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(10);
}
});
var t3 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
tdb2.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(6);
}
});
t1.Start();
t2.Start();
t3.Start();
Task.WaitAll(t1, t2, t3);
}
private static void IsShardSameThread()
{
var t1 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
Db.Insertable(new Order() { Name = "test", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(1);
}
});
var t2 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
Db.Insertable(new Order() { Name = "test2", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(10);
}
});
var t3 = new Task(() =>
{
for (int i = 0; i < 100; i++)
{
Db.Insertable(new Order() { Name = "test3", CreateTime = DateTime.Now }).ExecuteCommand();
System.Threading.Thread.Sleep(6);
}
});
t1.Start();
t2.Start();
t3.Start();
Task.WaitAll(t1, t2, t3);
}
}
}

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.
Loading…
Cancel
Save