public void Verify_GenerateIds_Increase_In_Sequence_When_TimeStamp_Same() { var timestamp = DateTime.UtcNow.Ticks; var idGenerationStrategy = new FlakeIDGenerationStrategy(100, () => timestamp); var idGenerator = new IDGenerator <long>(100, idGenerationStrategy); var id1 = idGenerator.GenerateId(); var id2 = idGenerator.GenerateId(); Assert.IsTrue(id2 > id1); }
public void Verify_GenerateId_Throws_Exception_When_Clock_Moves_Back() { var timestamp = DateTime.UtcNow.Ticks; var idGenerationStrategy = new FlakeIDGenerationStrategy(100, () => timestamp); var idGenerator = new IDGenerator <long>(100, idGenerationStrategy); idGenerator.GenerateId(); timestamp = new DateTime(timestamp).AddMilliseconds(-1).Ticks; idGenerator.GenerateId(); Assert.IsTrue(true); }
public void Verify_GenerateIds_Increase_In_Sequence() { var timestamp = DateTime.UtcNow.Ticks; var idGenerationStrategy = new FlakeIDGenerationStrategy(100, () => timestamp); var idGenerator = new IDGenerator <long>(100, idGenerationStrategy); var id1 = idGenerator.GenerateId(); timestamp = new DateTime(timestamp).AddMilliseconds(1).Ticks; var id2 = idGenerator.GenerateId(); Assert.IsTrue(id2 > id1); }
public void Verify_Sequence_From_Generated_Matches() { var timestamp = DateTime.UtcNow.Ticks; var idGenerationStrategy = new FlakeIDGenerationStrategy(100, () => timestamp); var idGenerator = new IDGenerator <long>(100, idGenerationStrategy); var id = idGenerator.GenerateId(); Assert.IsTrue(idGenerationStrategy.GetSequenceFromId(id).Equals(1)); for (int i = 0; i < 9; i++) { id = idGenerator.GenerateId(); } Assert.IsTrue(idGenerationStrategy.GetSequenceFromId(id).Equals(10)); }
public PrgState Execute(PrgState state) { if (IsOpen(state)) { throw new Exception("File " + fileName + " is open"); } else { System.IO.StreamReader file = new System.IO.StreamReader(fileName); FileData fd = new FileData(fileName, file); int id = IDGenerator.GenerateId(); // add the id and the descriptor state.FileTable.Add(id, fd); // get the dictionary IModDictionary <string, int> dict = state.SymbTable; if (dict.Contains(varFileId)) { dict.Update(varFileId, id); } else { dict.Put(varFileId, id); } return(state); } }
public void Verify_NodeId_From_Generated_Matches() { var timestamp = DateTime.UtcNow.Ticks; var idGenerationStrategy = new FlakeIDGenerationStrategy(100, () => timestamp); var idGenerator = new IDGenerator <long>(100, idGenerationStrategy); var id = idGenerator.GenerateId(); Assert.IsTrue(idGenerationStrategy.GetNodeFromId(id).Equals(100)); }
public void GenerateId() { Id = IDGenerator.GenerateId(); }