public void IdGenerator_GetFromConfig_ReturnsSameInstanceForSameName() { var target1 = AppConfigFactory.GetFromConfig("foo"); var target2 = AppConfigFactory.GetFromConfig("foo"); Assert.IsTrue(ReferenceEquals(target1, target2)); }
public void IdGenerator_GetFromConfig_ParsesTickDurationCorrectly() { Assert.AreEqual(TimeSpan.FromMilliseconds(50), AppConfigFactory.GetFromConfig("foo").TimeSource.TickDuration); Assert.AreEqual(new TimeSpan(1, 2, 3), AppConfigFactory.GetFromConfig("bar").TimeSource.TickDuration); Assert.AreEqual(TimeSpan.FromTicks(7), AppConfigFactory.GetFromConfig("baz").TimeSource.TickDuration); // Make sure the default tickduration is 1 ms Assert.AreEqual(TimeSpan.FromMilliseconds(1), AppConfigFactory.GetFromConfig("nt").TimeSource.TickDuration); }
public void IdGenerator_GetFromConfig_CreatesCorrectGenerator() { var target = AppConfigFactory.GetFromConfig("foo"); Assert.AreEqual(123, target.Id); Assert.AreEqual(new DateTime(2016, 1, 2, 12, 34, 56, DateTimeKind.Utc), target.Epoch); Assert.AreEqual(39, target.MaskConfig.TimestampBits); Assert.AreEqual(11, target.MaskConfig.GeneratorIdBits); Assert.AreEqual(13, target.MaskConfig.SequenceBits); Assert.AreEqual(TimeSpan.FromMilliseconds(50), target.TimeSource.TickDuration); }
public void IdGenerator_GetFromConfig_CreatesCorrectGenerator2() { var target = AppConfigFactory.GetFromConfig("baz"); Assert.AreEqual(2047, target.Id); Assert.AreEqual(new DateTime(2016, 2, 29, 0, 0, 0, DateTimeKind.Utc), target.Options.TimeSource.Epoch); Assert.AreEqual(21, target.Options.IdStructure.TimestampBits); Assert.AreEqual(21, target.Options.IdStructure.GeneratorIdBits); Assert.AreEqual(21, target.Options.IdStructure.SequenceBits); Assert.AreEqual(TimeSpan.FromTicks(7), target.Options.TimeSource.TickDuration); Assert.AreEqual(SequenceOverflowStrategy.SpinWait, target.Options.SequenceOverflowStrategy); }
public void IdGenerator_GetFromConfig_CreatesCorrectGenerator1() { var target = AppConfigFactory.GetFromConfig("foo"); Assert.AreEqual(123, target.Id); Assert.AreEqual(new DateTime(2016, 1, 2, 12, 34, 56, DateTimeKind.Utc), target.Options.TimeSource.Epoch); Assert.AreEqual(39, target.Options.IdStructure.TimestampBits); Assert.AreEqual(11, target.Options.IdStructure.GeneratorIdBits); Assert.AreEqual(13, target.Options.IdStructure.SequenceBits); Assert.AreEqual(TimeSpan.FromMilliseconds(50), target.Options.TimeSource.TickDuration); Assert.AreEqual(SequenceOverflowStrategy.Throw, target.Options.SequenceOverflowStrategy); }
public void IdGeneratorElement_Property_Setters() { // We create an IdGeneratorElement from code and compare it to an IdGeneratorElement from config. var target = new IdGeneratorElement() { Name = "newfoo", Id = 123, Epoch = new DateTime(2016, 1, 2, 12, 34, 56, DateTimeKind.Utc), TimestampBits = 39, GeneratorIdBits = 11, SequenceBits = 13, TickDuration = TimeSpan.FromMilliseconds(50) }; var expected = AppConfigFactory.GetFromConfig("foo"); Assert.AreEqual(expected.Id, target.Id); Assert.AreEqual(expected.Epoch, target.Epoch); Assert.AreEqual(expected.MaskConfig.TimestampBits, target.TimestampBits); Assert.AreEqual(expected.MaskConfig.GeneratorIdBits, target.GeneratorIdBits); Assert.AreEqual(expected.MaskConfig.SequenceBits, target.SequenceBits); Assert.AreEqual(expected.TimeSource.TickDuration, target.TickDuration); }
public void IdGenerator_GetFromConfig_ParsesEpochCorrectly() { Assert.AreEqual(new DateTime(2016, 1, 2, 12, 34, 56, DateTimeKind.Utc), AppConfigFactory.GetFromConfig("foo").Epoch); Assert.AreEqual(new DateTime(2016, 2, 1, 1, 23, 45, DateTimeKind.Utc), AppConfigFactory.GetFromConfig("bar").Epoch); Assert.AreEqual(new DateTime(2016, 2, 29, 0, 0, 0, DateTimeKind.Utc), AppConfigFactory.GetFromConfig("baz").Epoch); }
public void IdGenerator_GetFromConfig_ThrowsOnInvalidEpoch() { var target = AppConfigFactory.GetFromConfig("e2"); }
public void IdGenerator_GetFromConfig_ThrowsOnNonExisting() { var target = AppConfigFactory.GetFromConfig("xxx"); }
public void IdGenerator_GetFromConfig_IsCaseSensitive() { var target = AppConfigFactory.GetFromConfig("Foo"); }
public void IdGenerator_GetFromConfig_ThrowsOnInvalidIdStructure() { AppConfigFactory.GetFromConfig("e1"); }