public void DualCounterTest() { string filePath = "c:\\temp\\test"; DocCounter docCounter= new DocCounter(filePath); SequenceCounter sequenceCounter= new SequenceCounter(filePath); docCounter.Reset(); sequenceCounter.Reset(); long docCount = docCounter.Get(); Assert.AreEqual(0, docCount); docCount = docCounter.Next(); Assert.AreEqual(1, docCount); long sequenceCount = sequenceCounter.Get(); Assert.AreEqual(0, sequenceCount); sequenceCount = sequenceCounter.Next(); Assert.AreEqual(1, sequenceCount); docCounter.Close(); docCounter = new DocCounter(filePath); docCount = docCounter.Get(); Assert.AreEqual(1, docCount); }
/// <summary> /// Update or insert a new document into the database /// </summary> /// <param name="docId">ID of the document to store or update</param> /// <param name="data">string data for the associated document</param> /// <param name="previousRev">Optionally specify the revision to update. By default will assume a new revision /// if the revision document specifies and older revision then a sub version of the old document revision will be /// created </param> public void PutDoc(string docId, string data) { Node docInfo = null; try { Slice docInfoString = ""; // If possible try and retrieve any existing doc info for this id if (!docStore.TryGet(ReadOptions.Default, docId, out docInfoString)) { // Insert mode: create a new root document docInfo = new Node(docId, data, sequenceCount); docCount = docCounter.Next(); } else { // Update mode: create a new revision entry docInfo = Node.Parse(docInfoString.ToString()); // add a new document version docInfo.addVersion(data, sequenceCount); } // Store info about the document in the doc store //Debug.WriteLine(docInfo.Dump()); string docInfoData = docInfo.ToJson(); docInfoData = docInfoData.Replace("\"", ""); docStore.Put(WriteOptions.Default, docId, docInfoData); // store a unique uuid linked with the doc id data sequenceStore.Put(WriteOptions.Default, sequenceCount.ToString(), docInfo.getLatestSig() + "+" + data); sequenceCount = sequenceCounter.Next(); } catch (Exception ee) { throw ee; } finally { } }
public void SequenceCounterTest() { string filePath = "c:\\temp\\test"; SequenceCounter counter = new SequenceCounter(filePath); counter.Reset(); long count = counter.Get(); Assert.AreEqual(0, count); count = counter.Next(); Assert.AreEqual(1, count); count = counter.Next(); Assert.AreEqual(2, count); counter.Close(); counter = null; counter = new SequenceCounter(filePath); count = counter.Get(); Assert.AreEqual(2, count); }