public void Next_AlreadyExists_IsIncremented() { var graph = NeoHelper.CreateRestApi().Clear(); var service = new SequenceProvider(graph); graph.CreateUniqueNode("Sequence", "Name", "unit_test_sequence", new SequenceProvider.SequenceValue { Value = 500 }); var id = service.Next("UNIT_TEST_SEQUENCE"); Assert.AreEqual(501, id); id = service.Next("UNIT_TEST_SEQUENCE"); Assert.AreEqual(502, id); }
public void Next_NewlyCreated_IsCreated() { var graph = NeoHelper.CreateRestApi().Clear(); var service = new SequenceProvider(graph); var id = service.Next("UNIT_TEST_SEQUENCE"); Assert.AreEqual(1, id); }
public void Next_Concurrency_IsIncremented() { var graph = NeoHelper.CreateRestApi().Clear(); var service = new SequenceProvider(graph); var allThreads = new List<Thread>(); var allItems = new List<long>(); for (int i = 0; i < 2; i++) { var t = new Thread(() => { var localItems = new List<long>(10); for (int j = 0; j < 10; j++) { localItems.Add(service.Next("UNIT_TEST_SEQUENCE")); } lock (allItems) { allItems.AddRange(localItems); } }); allThreads.Add(t); t.Start(); } foreach (var t in allThreads) { t.Join(); } allItems.Sort(); var value = String.Join(",", allItems.Select(i => i.ToString(CultureInfo.InvariantCulture))); Assert.AreEqual("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20", value); }