You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.2 KiB
118 lines
3.2 KiB
6 years ago
|
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 void Thread3()
|
||
|
{
|
||
|
Console.WriteLine("Thread3");
|
||
|
SimpleAsync3();
|
||
|
IsShardSameThreadAsync3();
|
||
|
SingleAsync3();
|
||
|
SingleAndIsShardSameThreadAsync3();
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
private static async Task SimpleAsync3()
|
||
|
{
|
||
|
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await simpleDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await simpleDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||
|
}
|
||
|
|
||
|
List<Order> orders = new List<Order>();
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
orders = await simpleDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
if (orders.Count > 0)
|
||
|
{
|
||
|
Console.WriteLine("async is ok");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static async Task SingleAndIsShardSameThreadAsync3()
|
||
|
{
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await singleAndSsDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await singleAndSsDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||
|
}
|
||
|
List<Order> orders = new List<Order>();
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
orders = await singleAndSsDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
if (orders.Count > 0)
|
||
|
{
|
||
|
Console.WriteLine("async is ok");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static async Task SingleAsync3()
|
||
|
{
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await singleDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await singleDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||
|
}
|
||
|
|
||
|
List<Order> orders = new List<Order>();
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
orders = await singleDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
if (orders.Count > 0)
|
||
|
{
|
||
|
Console.WriteLine("async is ok");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static async Task IsShardSameThreadAsync3()
|
||
|
{
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await ssDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
await ssDb.Insertable(new Order() { Name = "a", CustomId = 1 }).ExecuteCommandAsync();
|
||
|
}
|
||
|
|
||
|
List<Order> orders = new List<Order>();
|
||
|
for (int i = 0; i < 100; i++)
|
||
|
{
|
||
|
orders = await ssDb.Queryable<Order>().Take(10).ToListAsync();
|
||
|
}
|
||
|
if (orders.Count > 0)
|
||
|
{
|
||
|
Console.WriteLine("async is ok");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|