public void CanSelectThenInsert() { String key = "test"; String value = TestUtil.NextString(); var dbConn = ConnectionFactory.Create(); var item = TestUtil.MakeWorkItem(dbConn); Assert.AreNotEqual(item, null); // there should be no data (aka key value pairs) now: var list = WorkItemData.SelectAll(dbConn, item.Id); Assert.AreNotEqual(list, null); // ensure SelectAll returns empty list, not null Assert.AreEqual(list.Count, 0); // now put one key/value pair in: var inserted = WorkItemData.Insert(dbConn, item, key, value); var selected = WorkItemData.SelectAll(dbConn, item.Id); Assert.AreNotEqual(selected, null); // ensure SelectAll returns empty list, not null Assert.AreEqual(selected.Count, 1); Assert.GreaterOrEqual(inserted.Id, 1); Assert.AreEqual(inserted.Id, selected[0].Id); Assert.AreEqual(inserted.WorkItemId, selected[0].WorkItemId); Assert.AreEqual(inserted.VariableName, selected[0].VariableName); Assert.AreEqual(inserted.VariableName, key); Assert.AreEqual(inserted.VariableValue, selected[0].VariableValue); }
public WorkItemInfo GetItem(String queueName) { IDbTransaction transaction = null; try { transaction = dbConn_.BeginTransaction(); // first get the queue object, so we can query things in // all steps hanging off that queue: var queue = Queue.Select(dbConn_, queueName); if (queue == null) { throw new Exception("unknown queue [" + queueName + "]"); } // TODO check queue perms here: //var allowed = AllowedQueue.Select(dbConn_, this.user_, queue); var items = WorkItem.SelectByPriority(dbConn_, queue); // if there are no Available items in the queue, return null // per design: if (items == null || items.Count == 0) { return(null); } // WorkItemInfos have information about the item's // step, and map; and the queue under which we queried // for it. Therefore we need all 3 objects to build // a WorkItemInfo: var item = items[0]; var step = Step.Select(dbConn_, item.StepId); var map = Map.Select(dbConn_, step.MapId); // Now update the work item, otherwise this one will always be // the WorkItemInfo one returned in an infinite loop: item.ItemState = WorkItemState.InProgress; item.Entered = DateTime.UtcNow; item.SessionId = session_.Id; item.Update(dbConn_); transaction.Commit(); transaction = null; return(new WorkItemInfo(item , map , step , queue , WorkItemData.SelectAll(dbConn_, item.Id) )); } finally { DbUtil.ReallyBackout(transaction); } }
public void RuleThatSkipsMiddle() { DateTime start = TestUtil.FlooredNow(); String itemName = "item" + TestUtil.NextString(); int priority = TestUtil.RANDOM.Next(-100, 100); var wfConn = TestUtil.CreateConnected(); var names = TestUtil.CreateMapWithRules(); var pairs = TestUtil.CreatePairs(); wfConn.CreateItem(names["map"] , itemName , names["startStep"] , pairs , priority ); var item0 = wfConn.GetItem(names["queue"]); TestUtil.AssertSame(item0, itemName, pairs, start, priority); TestUtil.AssertRightPlaces(item0, names["map"], names["startStep"]); Assert.IsNotNull(item0); // now finish the item. The rule skip=true should be applied; and // the item should go from the start step to the endStep; skipping // the middle step item0["skipMiddle"] = "true"; wfConn.FinishItem(item0); var item1 = wfConn.GetItem(names["queue"]); TestUtil.AssertSame(item1, itemName, item0, start, priority); TestUtil.AssertRightPlaces(item1, names["map"], names["endStep"]); // now, since we're in an end step, finishing the item should make // it go away: wfConn.FinishItem(item1); var item2 = wfConn.GetItem(names["queue"]); Assert.IsNull(item2); // make sure everything is gone from the DB, now that the item // is complete: var dbConn = ConnectionFactory.Create(); Assert.IsNull(WorkItem.Select(dbConn, item0.Id)); Assert.IsNull(WorkItem.Select(dbConn, item1.Id)); Assert.AreEqual(0, WorkItemData.SelectAll(dbConn, item0.Id).Count); Assert.AreEqual(0, WorkItemData.SelectAll(dbConn, item1.Id).Count); }
public void FinishThenFinishGoesAway() { DateTime start = TestUtil.FlooredNow(); String itemName = "item" + TestUtil.NextString(); int priority = TestUtil.RANDOM.Next(-100, 100); var wfConn = TestUtil.CreateConnected(); var names = TestUtil.CreateBasicMap(); var pairs = TestUtil.CreatePairs(); wfConn.CreateItem(names["map"] , itemName , names["startStep"] , pairs , priority ); var item0 = wfConn.GetItem(names["queue"]); TestUtil.AssertSame(item0, itemName, pairs, start, priority); TestUtil.AssertRightPlaces(item0, names["map"], names["startStep"]); Assert.IsNotNull(item0); // now finish the item. It should move to the // end step in our simple map setup: wfConn.FinishItem(item0); var item1 = wfConn.GetItem(names["queue"]); TestUtil.AssertSame(item1, itemName, pairs, start, priority); TestUtil.AssertRightPlaces(item1, names["map"], names["endStep"]); // now, since we're in an end step, finishing the item should make // it go away: wfConn.FinishItem(item1); var item2 = wfConn.GetItem(names["queue"]); Assert.IsNull(item2); // make sure everything is gone from the DB, now that the item // is complete: var dbConn = ConnectionFactory.Create(); Assert.IsNull(WorkItem.Select(dbConn, item0.Id)); Assert.IsNull(WorkItem.Select(dbConn, item1.Id)); Assert.AreEqual(0, WorkItemData.SelectAll(dbConn, item0.Id).Count); Assert.AreEqual(0, WorkItemData.SelectAll(dbConn, item1.Id).Count); }
public void CanCreateItem() { var dbConn = ConnectionFactory.Create(); String itemName = "Item" + TestUtil.NextString(); int priority = TestUtil.RANDOM.Next(-100, 100); int beforeItems = TestUtil.SelectCount(dbConn, WorkItem.TABLE); int beforeNvps = TestUtil.SelectCount(dbConn, WorkItemData.TABLE); var wfConn = TestUtil.CreateConnected(); var where = TestUtil.CreateBasicMap(); var inboundPairs = TestUtil.CreatePairs(); wfConn.CreateItem(where["map"] , itemName , where["startStep"] , inboundPairs , priority ); int afterItems = TestUtil.SelectCount(dbConn, WorkItem.TABLE); int afterNvps = TestUtil.SelectCount(dbConn, WorkItemData.TABLE); Assert.AreEqual(beforeItems + 1, afterItems); Assert.Greater(inboundPairs.Count, 0); Assert.AreEqual(beforeNvps + inboundPairs.Count, afterNvps); var item = WorkItem.Select(dbConn, itemName); Assert.IsNotNull(item); Assert.AreEqual(item.Priority, priority); Assert.AreEqual(item.Name, itemName); Assert.AreEqual(item.ItemState, WorkItemState.Available); Assert.Greater(item.Id, 0); var selectedPairs = WorkItemData.SelectAll(dbConn, item.Id); Assert.IsNotNull(selectedPairs); Assert.GreaterOrEqual(selectedPairs.Count, 1); Assert.AreEqual(selectedPairs.Count, inboundPairs.Count); foreach (var row in selectedPairs) { String key = row.VariableName; String value = row.VariableValue; Assert.AreEqual(inboundPairs[key], value); } }
public void CanCreateEmptyItem() { var dbConn = ConnectionFactory.Create(); String itemName = "Item" + TestUtil.NextString(); int priority = TestUtil.RANDOM.Next(-100, 100); int beforeItems = TestUtil.SelectCount(dbConn, WorkItem.TABLE); int beforeNvps = TestUtil.SelectCount(dbConn, WorkItemData.TABLE); var where = TestUtil.CreateBasicMap(); var inboundPairs = TestUtil.CreatePairs(); var wfConn = TestUtil.CreateConnected(); wfConn.CreateItem(where["map"] , itemName , where["startStep"] , new Dictionary <String, String>() , priority ); int afterItems = TestUtil.SelectCount(dbConn, WorkItem.TABLE); int afterNvps = TestUtil.SelectCount(dbConn, WorkItemData.TABLE); // since we created the item with a blank set of NVPs, //afterNvps should not increase: Assert.AreEqual(beforeItems + 1, afterItems); Assert.AreEqual(beforeNvps + 0, afterNvps); var item = WorkItem.Select(dbConn, itemName); Assert.IsNotNull(item); Assert.AreEqual(item.Priority, priority); Assert.Greater(item.Id, 0); Assert.AreEqual(item.ItemState, WorkItemState.Available); var selectedPairs = WorkItemData.SelectAll(dbConn, item.Id); Assert.IsNotNull(selectedPairs); Assert.AreEqual(selectedPairs.Count, 0); }