Esempio n. 1
0
        public void GeneratedUUID_ShouldHaveProperVersion(GuidGenerationMode mode)
        {
            var generator       = new TimeBasedGenerator();
            var expectedVersion = 0x10;

            var guid  = generator.GenerateGuid(mode);
            var array = guid.ToByteArray();

            Assert.Equal(expectedVersion, array[7] & 0xf0);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testMultithreaded() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testMultithreaded()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<Thread> threads = new java.util.ArrayList<Thread>();
            IList <Thread> threads = new List <Thread>();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.fasterxml.uuid.impl.TimeBasedGenerator timeBasedGenerator = com.fasterxml.uuid.Generators.timeBasedGenerator(com.fasterxml.uuid.EthernetAddress.fromInterface());
            TimeBasedGenerator timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.ConcurrentSkipListSet<String> generatedIds = new java.util.concurrent.ConcurrentSkipListSet<String>();
            ConcurrentSkipListSet <string> generatedIds = new ConcurrentSkipListSet <string>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.ConcurrentSkipListSet<String> duplicatedIds = new java.util.concurrent.ConcurrentSkipListSet<String>();
            ConcurrentSkipListSet <string> duplicatedIds = new ConcurrentSkipListSet <string>();

            for (int i = 0; i < THREAD_COUNT; i++)
            {
                Thread thread = new Thread(() =>
                {
                    for (int j = 0; j < LOOP_COUNT; j++)
                    {
                        string id     = timeBasedGenerator.generate().ToString();
                        bool wasAdded = generatedIds.add(id);
                        if (!wasAdded)
                        {
                            duplicatedIds.add(id);
                        }
                    }
                });
                threads.Add(thread);
                thread.Start();
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            Assert.assertEquals(THREAD_COUNT * LOOP_COUNT, generatedIds.size());
            Assert.assertTrue(duplicatedIds.Empty);
        }
Esempio n. 3
0
 public TimeBasedIdentityGenerator()
 {
     generator = new TimeBasedGenerator();
 }