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_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); }
public void OnlyReadsNewEventsTest() { const string lastMessage = "last message"; bool called = false; List <string> msgs = new List <string>(); EventLogSubscription.OnEntryWritten callback = (e) => { msgs.Add(e.Message); if (e.Message == lastMessage) { called = true; } }; using (EventLogSubscription tailer = new EventLogSubscription(logName, callback, null, null)) { string oldLogMessage = Guid.NewGuid().ToString(); for (int i = 0; i < 5; i++) { testLog.WriteEntry(oldLogMessage); } Tailer tailer = new Tailer(logName, callback, null, null); tailer.Start(); testLog.WriteEntry(lastMessage); int count = 0; while (!called && count++ < 40) { Thread.Sleep(250); } Assert.True(count < 10); Assert.Equal(1, msgs.Count); } }
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); }); }
/// <summary> /// 読み込み /// </summary> /// <param name="tailerElement"></param> public void Load( XmlElement tailerElement ) { // 属性 foreach( XmlAttribute attribute in tailerElement.Attributes ) { var attributeName = attribute.Name.ToLower(); switch( attributeName ) { case "fontfamily": FontFamily = new FontFamily( attribute.Value ); break; case "fontsize": FontSize = double.Parse( attribute.Value ); break; default: Debug.Assert( false, "未知の属性 attributeName={0}", attributeName ); break; } } // 要素 foreach( XmlNode childNode in tailerElement.ChildNodes ) { var elementName = childNode.Name.ToLower(); switch( elementName ) { case "tailer": var tailer = new Tailer(); tailer.Load( childNode as XmlElement ); Tailers.Add( tailer ); break; default: Debug.Assert( false, "未知の要素 elementName={0}", elementName ); break; } } }