当前位置: 首页>>代码示例>>C#>>正文


C# IdGenerator.CreateId方法代码示例

本文整理汇总了C#中IdGenerator.CreateId方法的典型用法代码示例。如果您正苦于以下问题:C# IdGenerator.CreateId方法的具体用法?C# IdGenerator.CreateId怎么用?C# IdGenerator.CreateId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IdGenerator的用法示例。


在下文中一共展示了IdGenerator.CreateId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Constructor_Throws_OnTimestampWraparound

        public void Constructor_Throws_OnTimestampWraparound()
        {
            var mc = MaskConfig.Default;
            var ts = new MockTimeSource(mc.WraparoundDate(TESTEPOCH).AddMilliseconds(-1));  //Set clock to 1 ms before epoch
            var g = new IdGenerator(0, TESTEPOCH, MaskConfig.Default, ts);

            Assert.IsTrue(g.CreateId() > 0);   //Should succeed;
            ts.NextTick();
            g.CreateId();   //Should fail
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:10,代码来源:IdGenTests.cs

示例2: Sequence_ShouldReset_EveryNewTick

        public void Sequence_ShouldReset_EveryNewTick()
        {
            // We setup our generator so that the time (current - epoch) results in 0, generator id 0 and we're only
            // left with the sequence increasing each invocation of CreateId();
            var ts = new MockTimeSource(TESTEPOCH);
            var m = MaskConfig.Default;
            var g = new IdGenerator(0, TESTEPOCH, m, ts);

            Assert.AreEqual(0, g.CreateId());
            Assert.AreEqual(1, g.CreateId());
            ts.NextTick();
            // Since the timestamp has increased, we should now have a much higher value (since the timestamp is shifted
            // left a number of bits (specifically GeneratorIdBits + SequenceBits)
            Assert.AreEqual((1 << (m.GeneratorIdBits + m.SequenceBits)) + 0, g.CreateId());
            Assert.AreEqual((1 << (m.GeneratorIdBits + m.SequenceBits)) + 1, g.CreateId());
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:16,代码来源:IdGenTests.cs

示例3: Sequence_ShouldIncrease_EveryInvocation

        public void Sequence_ShouldIncrease_EveryInvocation()
        {
            // We setup our generator so that the time (current - epoch) results in 0, generator id 0 and we're only
            // left with the sequence increasing each invocation of CreateId();
            var ts = new MockTimeSource(TESTEPOCH);
            var m = MaskConfig.Default;
            var g = new IdGenerator(0, TESTEPOCH, MaskConfig.Default, ts);

            Assert.AreEqual(0, g.CreateId());
            Assert.AreEqual(1, g.CreateId());
            Assert.AreEqual(2, g.CreateId());
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:12,代码来源:IdGenTests.cs

示例4: GeneratorId_ShouldBePresent_InID2

        public void GeneratorId_ShouldBePresent_InID2()
        {
            // We setup our generator so that the time (current - epoch) results in 0, generator id 4095 so that all 12 bits
            // are set for the generator.
            var ts = new MockTimeSource(TESTEPOCH);
            var m = new MaskConfig(40, 12, 11);     // We use a custom mask-config with 12 bits for the generator this time
            var g = new IdGenerator(4095, TESTEPOCH, m, ts);

            // Make sure all expected bits are set
            Assert.AreEqual(-1 & ((1 << 12) - 1), g.Id);
            Assert.AreEqual((1 << 12) - 1 << 11, g.CreateId());
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:12,代码来源:IdGenTests.cs

示例5: GeneratorId_ShouldBePresent_InID1

        public void GeneratorId_ShouldBePresent_InID1()
        {
            // We setup our generator so that the time (current - epoch) results in 0, generator id 1023 so that all 10 bits
            // are set for the generator.
            var ts = new MockTimeSource(TESTEPOCH);
            var m = MaskConfig.Default;             // We use a default mask-config with 11 bits for the generator this time
            var g = new IdGenerator(1023, TESTEPOCH, m, ts);

            // Make sure all expected bits are set
            Assert.AreEqual((1 << m.GeneratorIdBits) - 1 << m.SequenceBits, g.CreateId());
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:11,代码来源:IdGenTests.cs

示例6: CreateId_Throws_OnSequenceOverflow

        public void CreateId_Throws_OnSequenceOverflow()
        {
            var ts = new MockTimeSource(TESTEPOCH);
            var g = new IdGenerator(0, TESTEPOCH, new MaskConfig(41, 20, 2), ts);

            // We have a 2-bit sequence; generating 4 id's shouldn't be a problem
            for (int i = 0; i < 4; i++)
                Assert.AreEqual(i, g.CreateId());

            // However, if we invoke once more we should get an SequenceOverflowException
            g.CreateId();
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:12,代码来源:IdGenTests.cs

示例7: CreateId_Throws_OnClockBackwards

        public void CreateId_Throws_OnClockBackwards()
        {
            var ts = new MockTimeSource(DateTime.UtcNow);
            var m = MaskConfig.Default;
            var g = new IdGenerator(0, TESTEPOCH, m, ts);

            g.CreateId();
            ts.PreviousTick(); //Set clock back 1 'tick' (ms)
            g.CreateId();
        }
开发者ID:BuddyTV,项目名称:IdGen,代码行数:10,代码来源:IdGenTests.cs


注:本文中的IdGenerator.CreateId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。