From 4a956a730434cd0e67141197b6c592c71c2cc70a Mon Sep 17 00:00:00 2001 From: yitter Date: Sat, 25 Jun 2022 11:32:49 +0800 Subject: [PATCH] auto commit --- C#.NET/source/Yitter.IdGen.sln | 4 +- C#.NET/source/Yitter.IdGenTest/Program.cs | 80 +++++++++++++++++++--- .../Yitter.IdGenTest/Yitter.IdGenTest.csproj | 2 +- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/C#.NET/source/Yitter.IdGen.sln b/C#.NET/source/Yitter.IdGen.sln index 2cbc6ea..b0e6203 100644 --- a/C#.NET/source/Yitter.IdGen.sln +++ b/C#.NET/source/Yitter.IdGen.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31005.135 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32602.215 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yitter.IdGenerator", "Yitter.IdGenerator\Yitter.IdGenerator.csproj", "{FF8DAF11-34E7-4842-ADF2-3722A1A5FBB2}" EndProject diff --git a/C#.NET/source/Yitter.IdGenTest/Program.cs b/C#.NET/source/Yitter.IdGenTest/Program.cs index 099615f..3968244 100644 --- a/C#.NET/source/Yitter.IdGenTest/Program.cs +++ b/C#.NET/source/Yitter.IdGenTest/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading; @@ -30,7 +31,7 @@ namespace Yitter.OrgSystem.TestA var options = new IdGeneratorOptions() { - Method = method, + Method = 1, WorkerId = 1, WorkerIdBitLength = 6, @@ -39,10 +40,8 @@ namespace Yitter.OrgSystem.TestA TopOverCostCount = 2000, //TimestampType = 1, - // MinSeqNumber = 1, // MaxSeqNumber = 200, - // BaseTime = DateTime.Now.AddYears(-10), }; @@ -55,13 +54,78 @@ namespace Yitter.OrgSystem.TestA Console.WriteLine("====================================="); Console.WriteLine("这是用方法 " + method + " 生成的 Id:" + newId); - while (true) + var seed1 = 50; + var seed2 = 1000; + var finish = 0; + var next = IdGen.NewLong(); + + var hashSet = new HashSet(seed1 * seed2); + ConcurrentBag bags = new ConcurrentBag(); + + for (int i = 0; i < seed1; i++) { - RunSingle(); - //CallDll(); - //Go(options); - Thread.Sleep(1000); // 每隔1秒执行一次Go + (new Thread(_ => + { + for (int j = 0; j < seed2; j++) + { + var me = IdGen.NewLong(); + hashSet.Add(me); + bags.Add(me); + } + + Interlocked.Increment(ref finish); + }) + { IsBackground = true }).Start(); } + + while (finish < seed1) + { + Console.WriteLine("等待执行结束"); + Thread.Sleep(2000); + } + + Console.WriteLine($"hashSet 共计:{hashSet.Count} 实际应该:{seed1 * seed2}"); + Console.WriteLine($"bags 共计:{bags.Count} 实际应该:{seed1 * seed2}"); + + var IdArray = bags.ToArray(); + int totalCount = 0; + + for (int i = 0; i < seed1 * seed2; i++) + { + var me = IdArray[i]; + int j = 0; + int count = 0; + + while (j < seed1 * seed2) + { + if (IdArray[j] == me) + { + count++; + } + j++; + } + + if (count > 1) + { + totalCount++; + Console.WriteLine($"{IdArray[i]},重复:{count}"); + } + } + + if (totalCount == 0) + { + Console.WriteLine($"重复数为 0 "); + } + + Console.Read(); + + //while (true) + //{ + // //RunSingle(); + // //CallDll(); + // //Go(options); + // Thread.Sleep(1000); // 每隔1秒执行一次Go + //} } private static void RunSingle() diff --git a/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj b/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj index 409f0d3..03d97b9 100644 --- a/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj +++ b/C#.NET/source/Yitter.IdGenTest/Yitter.IdGenTest.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0