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.

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP.Infrastructure;
  4. using Xunit;
  5. namespace DotNetCore.CAP.Test
  6. {
  7. public class SnowflakeIdTest
  8. {
  9. [Fact]
  10. public void NextIdTest()
  11. {
  12. var result = SnowflakeId.Default().NextId();
  13. Assert.IsType<long>(result);
  14. Assert.True(result > 0);
  15. Assert.True(result.ToString().Length == long.MaxValue.ToString().Length);
  16. }
  17. [Fact]
  18. public void ConcurrentNextIdTest()
  19. {
  20. var array = new long[1000];
  21. Parallel.For(0, 1000, i =>
  22. {
  23. var id = SnowflakeId.Default().NextId();
  24. array[i] = id;
  25. });
  26. Assert.True(array.Distinct().Count() == 1000);
  27. }
  28. }
  29. }