public async Task Stream_CreateCollectionWithOptions()
        {
            var tailer = new Tailer(m_client);
            IOutlet outlet = Substitute.For<IOutlet>();
            var stream = new Stream(tailer, outlet);
            Oplog lastOplog = await tailer.GetMostRecentOplog();

            var collectionOptions = new CreateCollectionOptions { Capped = true, MaxSize = 10 };
            var collectionOptionsDocument = new BsonDocument(new List<BsonElement> { new BsonElement("capped", true), new BsonElement("size", 10) });

            var databaseName = "_Test_MongoRiver";
            var collectionName = "_Test_MongoRiver";

            IMongoDatabase database = m_client.GetDatabase(databaseName);

            await database.CreateCollectionAsync(collectionName, collectionOptions);
            await m_client.DropDatabaseAsync(databaseName);

            await RunStream(stream, lastOplog);

            outlet.Received(2).UpdateOptime(Arg.Any<BsonTimestamp>());

            Received.InOrder(() =>
            {
                outlet.CreateCollection(databaseName, collectionName, collectionOptionsDocument);
                outlet.DeleteDatabase(databaseName);
            });
        }
        public async Task Stream_ExecuteCorrectOperationsInCorrectOrder()
        {
            var tailer = new Tailer(m_client);
            IOutlet outlet = Substitute.For<IOutlet>();
            var stream = new Stream(tailer, outlet);
            Oplog lastOplog = await tailer.GetMostRecentOplog();

            var databaseName = "_Test_MongoRiver";
            var collectionName = "_Test_MongoRiver";
            var newCollectionName = string.Concat(collectionName, "_foo");
            var insertedDocument = new FooBarDocument { Id = "foo", Bar = "baz" };
            var filterDocument = new BsonDocument("_id", "foo");
            var updatedDocument = new FooBarDocument { Id = "foo", Bar = "qux" };
            var indexName = "FooBar_Index";
            var indexKeyDocument = new BsonDocument("Bar", 1);
            var indexOptionsDocument = new BsonDocument("name", indexName);

            IMongoDatabase database = m_client.GetDatabase(databaseName);
            IMongoCollection<FooBarDocument> collection = database.GetCollection<FooBarDocument>(collectionName);

            await collection.InsertOneAsync(insertedDocument);
            await collection.ReplaceOneAsync(filterDocument, updatedDocument);
            await collection.DeleteOneAsync(filterDocument);

            IndexKeysDefinition<FooBarDocument> indexDef = new IndexKeysDefinitionBuilder<FooBarDocument>().Ascending(d => d.Bar);
            await collection.Indexes.CreateOneAsync(indexDef, new CreateIndexOptions { Name = indexName });
            await collection.Indexes.DropOneAsync(indexName);

            await database.RenameCollectionAsync(collectionName, newCollectionName);
            await database.DropCollectionAsync(newCollectionName);
            await m_client.DropDatabaseAsync(databaseName);

            await RunStream(stream, lastOplog);

            outlet.Received(9).UpdateOptime(Arg.Any<BsonTimestamp>());

            Received.InOrder(() =>
            {
                outlet.CreateCollection(databaseName, collectionName, new BsonDocument());

                outlet.Insert(databaseName, collectionName, insertedDocument.ToBsonDocument());
                outlet.Update(databaseName, collectionName, filterDocument, updatedDocument.ToBsonDocument());
                outlet.Delete(databaseName, collectionName, filterDocument);

                outlet.CreateIndex(databaseName, collectionName, indexKeyDocument, indexOptionsDocument);
                outlet.DeleteIndex(databaseName, collectionName, indexName);

                outlet.RenameCollection(databaseName, collectionName, newCollectionName);
                outlet.DeleteCollection(databaseName, newCollectionName);
                outlet.DeleteDatabase(databaseName);
            });
        }
Ejemplo n.º 3
0
        public Stream(Tailer tailer, IOutlet outlet)
        {
            if (tailer == null)
            {
                throw new ArgumentNullException("tailer");
            }

            if (outlet == null)
            {
                throw new ArgumentNullException("outlet");
            }

            m_tailer = tailer;
            m_outlet = outlet;
        }
 private IObservable<OpLogEvent> CreateInternal(Func<Stream, Tailer, Task> runFunc)
 {
     var observable = Observable.Create<OpLogEvent>(observer =>
     {
         IOutlet output = new ObserverOutlet(observer);
         var tailer = new Tailer(_client);
         var stream = new Stream(tailer, output);
         runFunc(stream, tailer);
         return () =>
         {
             stream.Stop();
         };
     });
     return observable;
 }
Ejemplo n.º 5
0
        public Stream(Tailer tailer, IOutlet outlet)
        {
            if(tailer == null)
            {
                throw new ArgumentNullException("tailer");
            }

            if(outlet == null)
            {
                throw new ArgumentNullException("outlet");
            }

            m_tailer = tailer;
            m_outlet = outlet;
        }
        public async Task Stream_IgnoresEverythingBeforeTimestampPassedIn()
        {
            var tailer = new Tailer(m_client);
            IOutlet outlet = Substitute.For<IOutlet>();
            var stream = new Stream(tailer, outlet);

            var databaseName = "_Test_MongoRiver";
            var collectionName = "_Test_MongoRiver";

            var insertedDocument = new FooBarDocument { Id = "foo", Bar = "baz" };
            var filterDocument = new BsonDocument("_id", "foo");
            var updatedDocument = new FooBarDocument { Id = "foo", Bar = "qux" };

            IMongoDatabase database = m_client.GetDatabase(databaseName);
            IMongoCollection<FooBarDocument> collection = database.GetCollection<FooBarDocument>(collectionName);

            await collection.InsertOneAsync(insertedDocument);
            await collection.ReplaceOneAsync(filterDocument, updatedDocument);

            Oplog lastOplog = await tailer.GetMostRecentOplog(DateTime.UtcNow.AddSeconds(-3));
            await m_client.DropDatabaseAsync(databaseName);
            await RunStream(stream, lastOplog);

            outlet.Received(4).UpdateOptime(Arg.Any<BsonTimestamp>());
            outlet.Received().Insert(databaseName, collectionName, insertedDocument.ToBsonDocument());
            outlet.Received().Update(databaseName, collectionName, filterDocument.ToBsonDocument(), updatedDocument.ToBsonDocument());
            outlet.Received().DeleteDatabase(databaseName);
        }
        public async Task Stream_IgnoresEverythingBeforeOperationPassedIn()
        {
            var tailer = new Tailer(m_client);
            IOutlet outlet = Substitute.For<IOutlet>();
            var stream = new Stream(tailer, outlet);

            var databaseName = "_Test_MongoRiver";
            var collectionName = "_Test_MongoRiver";

            var insertedDocument = new FooBarDocument { Id = "foo", Bar = "baz" };

            IMongoDatabase database = m_client.GetDatabase(databaseName);
            IMongoCollection<FooBarDocument> collection = database.GetCollection<FooBarDocument>(collectionName);

            await collection.InsertOneAsync(insertedDocument);

            // Need a little delay to make sure previous insert is available in the oplog
            await Task.Delay(100);

            Oplog lastOplog = await tailer.GetMostRecentOplog();
            await m_client.DropDatabaseAsync(databaseName);
            await RunStream(stream, lastOplog);

            outlet.Received(1).UpdateOptime(Arg.Any<BsonTimestamp>());
            outlet.DidNotReceive().Insert(databaseName, collectionName, insertedDocument.ToBsonDocument());
            outlet.Received().DeleteDatabase(databaseName);
        }