protected override void TeardownVariant(int option)
        {
            _dbObserver?.Dispose();
            _dbObserver = null;
            _docObserver?.Dispose();
            _docObserver = null;

            base.TeardownVariant(option);
        }
        public void TestDocObserver()
        {
            RunTestVariants(() => {
                CreateRev("A", C4Slice.Constant("1-aa"), Body);
                _docObserver = Native.c4docobs_create(Db, "A", DocObserverCallback, this);

                CreateRev("A", C4Slice.Constant("2-bb"), Body);
                CreateRev("B", C4Slice.Constant("1-bb"), Body);
                _docCallbackCalls.Should().Be(1, "because there was only one update to the doc in question");
            });
        }
Exemplo n.º 3
0
        public ListenerToken AddDocumentChangeListener(string id, [CanBeNull] TaskScheduler scheduler,
                                                       EventHandler <DocumentChangedEventArgs> handler)
        {
            CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(id), id);
            CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(handler), handler);

            return(ThreadSafety.DoLocked(() =>
            {
                CheckOpen();

                var cbHandler =
                    new CouchbaseEventHandler <string, DocumentChangedEventArgs>(handler, id, scheduler);
                var count = _documentChanged.Add(cbHandler);
                if (count == 0)
                {
                    var docObs = new DocumentObserver(_c4db, id, _DocObserverCallback, this);
                    _docObs[id] = docObs;
                }

                return new ListenerToken(cbHandler, "doc");
            }));
        }