public void TestChangeListenerNotificationBatching() { const int numDocs = 50; var atomicInteger = new AtomicInteger(0); var doneSignal = new CountDownLatch(1); database.Changed += (sender, e) => atomicInteger.IncrementAndGet(); database.RunInTransaction(() => { CreateDocuments(database, numDocs); doneSignal.CountDown(); return true; }); var success = doneSignal.Await(TimeSpan.FromSeconds(30)); Assert.IsTrue(success); Assert.AreEqual(1, atomicInteger.Get()); }
public void TestChangeListenerNotification() { const int numDocs = 50; var atomicInteger = new AtomicInteger(0); database.Changed += (sender, e) => atomicInteger.IncrementAndGet(); CreateDocuments(database, numDocs); Assert.AreEqual(numDocs, atomicInteger.Get()); }
/// <summary>https://github.com/couchbase/couchbase-lite-android/issues/220</summary> /// <exception cref="System.Exception"></exception> public virtual void TestMultiDocumentUpdate() { int numberOfDocuments = 10; int numberOfUpdates = 10; Document[] docs = new Document[numberOfDocuments]; for (int j = 0; j < numberOfDocuments; j++) { IDictionary<string, object> prop = new Dictionary<string, object>(); prop.Put("foo", "bar"); prop.Put("toogle", true); Document document = CreateDocumentWithProperties(database, prop); docs[j] = document; } AtomicInteger numDocsUpdated = new AtomicInteger(0); AtomicInteger numExceptions = new AtomicInteger(0); for (int j_1 = 0; j_1 < numberOfDocuments; j_1++) { Document doc = docs[j_1]; for (int k = 0; k < numberOfUpdates; k++) { IDictionary<string, object> contents = new Hashtable(doc.GetProperties()); bool wasChecked = (bool)contents.Get("toogle"); //toggle value of check property contents.Put("toogle", !wasChecked); try { doc.PutProperties(contents); numDocsUpdated.IncrementAndGet(); } catch (CouchbaseLiteException cblex) { Log.E(Tag, "Document update failed", cblex); numExceptions.IncrementAndGet(); } } } NUnit.Framework.Assert.AreEqual(numberOfDocuments * numberOfUpdates, numDocsUpdated .Get()); NUnit.Framework.Assert.AreEqual(0, numExceptions.Get()); }