public void Snowflake_Generate_test_success() { for (int index = 0; index < 10; index++) { var g = new Snowflake.IdWorker(1, 10); var queue1 = new ConcurrentQueue <long>(); Enumerable.Range(0, 5097159).AsParallel().WithDegreeOfParallelism(100).ForAll(x => { var idg = g.NextId(); //var newId = idg.GenerateId(); queue1.Enqueue(idg); }); Assert.Equal(queue1.Count, queue1.ToDictionary(x => x, x => x).Count); } }
/// <summary> /// snowflake 초기화. 실패가 발생하면 예외를 던져준다. /// </summary> /// <param name="workerId">workerId 최고값은 31</param> /// <param name="dataCenterId">dataCenterId 최고값은 31</param> public static void Init(Int64 workerId, Int64 dataCenterId) { worker = new Snowflake.IdWorker(workerId, dataCenterId); }
private void button1_Click(object sender, EventArgs e) { var worker = new Snowflake.IdWorker(1, 1); var v = worker.NextId(); }
public SnowflakeIdWorker(long workerId, long datacenterId) { _idWorker = new Snowflake.IdWorker(workerId, datacenterId); }