public async Task Raises_alert_if_connection_string_was_not_found() { using (var store = GetDocumentStore()) { var database = await GetDatabase(store.Database); var notifications = new AsyncQueue <DynamicJsonValue>(); using (database.NotificationCenter.TrackActions(notifications, null)) { store.Admin.Server.Send(new AddEtlOperation <RavenConnectionString>(new RavenEtlConfiguration() { ConnectionStringName = "test", Name = "myEtl", Transforms = { new Transformation() { Collections ={ "Users" } } } }, store.Database)); var alert = await notifications.TryDequeueOfTypeAsync <DynamicJsonValue>(TimeSpan.FromSeconds(30)); Assert.True(alert.Item1); Assert.Equal("Invalid ETL configuration for 'myEtl'. Reason: Connection string named 'test' was not found for Raven ETL.", alert.Item2[nameof(AlertRaised.Message)]); } } }
public async Task Raises_alert_if_script_has_invalid_name() { using (var store = GetDocumentStore()) { var database = await GetDatabase(store.Database); var notifications = new AsyncQueue <DynamicJsonValue>(); using (database.NotificationCenter.TrackActions(notifications, null)) { AddEtl(store, new RavenEtlConfiguration() { ConnectionStringName = "test", Name = "myEtl", Transforms = { new Transformation() { Collections ={ "Users" } } } }, new RavenConnectionString() { Name = "test", TopologyDiscoveryUrls = new[] { "http://127.0.0.1:8080" }, Database = "Northwind", }); var alert = await notifications.TryDequeueOfTypeAsync <DynamicJsonValue>(TimeSpan.FromSeconds(30)); Assert.True(alert.Item1); Assert.Equal("Invalid ETL configuration for 'myEtl' (Northwind@http://127.0.0.1:8080). Reason: Script name cannot be empty.", alert.Item2[nameof(AlertRaised.Message)]); } } }
public async Task Raises_alert_if_ETLs_have_the_same_name() { using (var store = GetDocumentStore()) { var database = await GetDatabase(store.Database); var notifications = new AsyncQueue <DynamicJsonValue>(); using (database.NotificationCenter.TrackActions(notifications, null)) { AddEtl(store, new RavenEtlConfiguration() { ConnectionStringName = "test", Name = "myEtl", Transforms = { new Transformation() { Name = "TransformUsers", Collections ={ "Users" } } } }, new RavenConnectionString() { Name = "test", Url = "http://127.0.0.1:8080", Database = "Northwind", }); AddEtl(store, new RavenEtlConfiguration() { ConnectionStringName = "test", Name = "myEtl", Transforms = { new Transformation() { Name = "TransformOrders", Collections ={ "Orders" } } } }, new RavenConnectionString() { Name = "test", Url = "http://127.0.0.1:8080", Database = "Northwind", }); var alert = await notifications.TryDequeueOfTypeAsync <DynamicJsonValue>(TimeSpan.FromSeconds(30)); Assert.True(alert.Item1); Assert.Equal("Invalid ETL configuration for 'myEtl' (Northwind@http://127.0.0.1:8080). Reason: ETL with name 'myEtl' is already defined.", alert.Item2[nameof(AlertRaised.Message)]); } } }
public async Task Raises_alert_if_scipts_have_non_unique_names() { using (var store = GetDocumentStore()) { var database = await GetDatabase(store.Database); var notifications = new AsyncQueue <Notification>(); using (database.NotificationCenter.TrackActions(notifications, null)) { AddEtl(store, new RavenEtlConfiguration() { ConnectionStringName = "test", Name = "myEtl", Transforms = { new Transformation() { Name = "MyEtl", Collections ={ "Users" } }, new Transformation() { Name = "MyEtl", Collections ={ "People" } } } }, new RavenConnectionString() { Name = "test", Url = "http://127.0.0.1:8080", Database = "Northwind", }); var alert = await notifications.TryDequeueOfTypeAsync <AlertRaised>(TimeSpan.FromSeconds(30)); Assert.True(alert.Item1); Assert.Equal("Invalid ETL configuration for 'myEtl' (Northwind@http://127.0.0.1:8080). Reason: Script name 'MyEtl' name is already defined. The script names need to be unique.", alert.Item2.Message); } } }
public async Task Should_unload_db_and_send_notification_on_catastrophic_failure() { UseNewLocalServer(); using (var store = GetDocumentStore()) { var notifications = new AsyncQueue <Notification>(); using (Server.ServerStore.NotificationCenter.TrackActions(notifications, null)) { var database = await GetDatabase(store.Database); Assert.Equal(1, Server.ServerStore.DatabasesLandlord.DatabasesCache.Count()); try { throw new Exception("Catastrophy"); } catch (Exception e) { database.GetAllStoragesEnvironment().First().Environment.Options.SetCatastrophicFailure(ExceptionDispatchInfo.Capture(e)); } var ex = Assert.Throws <Exception>(() => { using (var context = DocumentsOperationContext.ShortTermSingleUse(database)) { using (var tx = context.OpenWriteTransaction()) { var dynamicJsonValue = new DynamicJsonValue(); using (var doc = context.ReadObject(dynamicJsonValue, "users/1", BlittableJsonDocumentBuilder.UsageMode.ToDisk)) { database.DocumentsStorage.Put(context, "users/1", null, doc); } tx.Commit(); } } }); Assert.Equal("Catastrophy", ex.Message); // db unloaded Assert.True(SpinWait.SpinUntil(() => Server.ServerStore.DatabasesLandlord.DatabasesCache.Any() == false, TimeSpan.FromMinutes(1))); var alert = await notifications.TryDequeueOfTypeAsync <AlertRaised>(TimeSpan.Zero); Assert.True(alert.Item1); Assert.Equal(AlertType.CatastrophicDatabaseFailure, alert.Item2.AlertType); Assert.Contains(database.Name, alert.Item2.Title); } using (var session = store.OpenSession()) { session.Store(new User()); session.SaveChanges(); } // db loaded again Assert.Equal(1, Server.ServerStore.DatabasesLandlord.DatabasesCache.Count()); } }