public ConfigureEndpointHelper(EndpointConfiguration configuration, string tablePrefix, Func <DbConnection> connectionBuilder, BuildSqlDialect sqlDialect, Func <Exception, bool> exceptionFilter = null) { this.tablePrefix = tablePrefix; this.connectionBuilder = connectionBuilder; this.sqlDialect = sqlDialect; this.exceptionFilter = exceptionFilter; sagaDefinitions = RuntimeSagaDefinitionReader.GetSagaDefinitions(configuration, sqlDialect).ToList(); using (var connection = connectionBuilder()) { connection.Open(); foreach (var definition in sagaDefinitions) { connection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(definition, sqlDialect), tablePrefix, exceptionFilter); try { connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(definition, sqlDialect), tablePrefix); } catch (Exception exception) when(exception.Message.Contains("Can't DROP")) { //ignore cleanup exceptions caused by async database operations } } connection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlDialect), tablePrefix, exceptionFilter); connection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), tablePrefix); connection.ExecuteCommand(SubscriptionScriptBuilder.BuildDropScript(sqlDialect), tablePrefix, exceptionFilter); connection.ExecuteCommand(SubscriptionScriptBuilder.BuildCreateScript(sqlDialect), tablePrefix); connection.ExecuteCommand(OutboxScriptBuilder.BuildDropScript(sqlDialect), tablePrefix, exceptionFilter); connection.ExecuteCommand(OutboxScriptBuilder.BuildCreateScript(sqlDialect), tablePrefix); } }
public void Setup() { dbConnection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(sagaDefinition, sqlDialect), nameof(TransportIntegrationTests)); dbConnection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaDefinition, sqlDialect), nameof(TransportIntegrationTests)); dbConnection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlDialect), nameof(TransportIntegrationTests)); dbConnection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), nameof(TransportIntegrationTests)); }
public void Write() { var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../"); foreach (var variant in Enum.GetValues(typeof(BuildSqlVariant)).Cast <BuildSqlVariant>()) { Write(directory, variant, "TimeoutCreate", TimeoutScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "TimeoutDrop", TimeoutScriptBuilder.BuildDropScript(variant)); Write(directory, variant, "OutboxCreate", OutboxScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "OutboxDrop", OutboxScriptBuilder.BuildDropScript(variant)); Write(directory, variant, "SubscriptionCreate", SubscriptionScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "SubscriptionDrop", SubscriptionScriptBuilder.BuildDropScript(variant)); var sagaDefinition = new SagaDefinition( tableSuffix: "OrderSaga", name: "OrderSaga", correlationProperty: new CorrelationProperty( name: "OrderNumber", type: CorrelationPropertyType.Int), transitionalCorrelationProperty: new CorrelationProperty( name: "OrderId", type: CorrelationPropertyType.Guid)); Write(directory, variant, "SagaCreate", SagaScriptBuilder.BuildCreateScript(sagaDefinition, variant)); Write(directory, variant, "SagaDrop", SagaScriptBuilder.BuildDropScript(sagaDefinition, variant)); } foreach (var variant in Enum.GetValues(typeof(SqlVariant)).Cast <SqlVariant>()) { var timeoutCommands = TimeoutCommandBuilder.Build(sqlVariant: variant, tablePrefix: "EndpointName"); Write(directory, variant, "TimeoutAdd", timeoutCommands.Add); Write(directory, variant, "TimeoutNext", timeoutCommands.Next); Write(directory, variant, "TimeoutRange", timeoutCommands.Range); Write(directory, variant, "TimeoutRemoveById", timeoutCommands.RemoveById); Write(directory, variant, "TimeoutRemoveBySagaId", timeoutCommands.RemoveBySagaId); Write(directory, variant, "TimeoutPeek", timeoutCommands.Peek); var outboxCommands = OutboxCommandBuilder.Build(variant, "EndpointName"); Write(directory, variant, "OutboxCleanup", outboxCommands.Cleanup); Write(directory, variant, "OutboxGet", outboxCommands.Get); Write(directory, variant, "OutboxSetAsDispatched", outboxCommands.SetAsDispatched); Write(directory, variant, "OutboxStore", outboxCommands.Store); var subscriptionCommands = SubscriptionCommandBuilder.Build(variant, "EndpointName"); Write(directory, variant, "SubscriptionSubscribe", subscriptionCommands.Subscribe); Write(directory, variant, "SubscriptionUnsubscribe", subscriptionCommands.Unsubscribe); Write(directory, variant, "SubscriptionGetSubscribers", subscriptionCommands.GetSubscribers(new List <MessageType> { new MessageType("MessageTypeName", new Version()) })); var sagaCommandBuilder = new SagaCommandBuilder(variant, "EndpointName"); Write(directory, variant, "SagaComplete", sagaCommandBuilder.BuildCompleteCommand("SagaName")); Write(directory, variant, "SagadGetByProperty", sagaCommandBuilder.BuildGetByPropertyCommand("SagaName", "PropertyName")); Write(directory, variant, "SagaGetBySagaId", sagaCommandBuilder.BuildGetBySagaIdCommand("SagaName")); Write(directory, variant, "SagaSave", sagaCommandBuilder.BuildSaveCommand("SagaName", "CorrelationPproperty", "TransitionalCorrelationPproperty")); Write(directory, variant, "SagaUpdate", sagaCommandBuilder.BuildUpdateCommand("SagaName", "TransitionalCorrelationPproperty")); } }
public void Setup() { MsmqQueueDeletion.DeleteQueuesForEndpoint(endpointName); dbConnection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(sagaDefinition, sqlVariant), nameof(MsmqTransportIntegrationTests)); dbConnection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaDefinition, sqlVariant), nameof(MsmqTransportIntegrationTests)); dbConnection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlVariant), nameof(MsmqTransportIntegrationTests)); dbConnection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlVariant), nameof(MsmqTransportIntegrationTests)); }
public void Setup() { manualResetEvent = new ManualResetEvent(false); dbConnection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(sagaDefinition, sqlDialect), nameof(MixedSagaAndNoOutbox)); dbConnection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaDefinition, sqlDialect), nameof(MixedSagaAndNoOutbox)); dbConnection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlDialect), nameof(MixedSagaAndNoOutbox)); dbConnection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), nameof(MixedSagaAndNoOutbox)); }
public void ExecuteCreateTwice() { var name = GetTablePrefix(); using (var connection = dbConnection(schema)) { connection.Open(); connection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), name, schema: schema); connection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), name, schema: schema); } }
public static void WriteTimeoutScript(string scriptPath, BuildSqlDialect sqlDialect) { var createPath = Path.Combine(scriptPath, "Timeout_Create.sql"); File.Delete(createPath); using (var writer = File.CreateText(createPath)) { TimeoutScriptBuilder.BuildCreateScript(writer, sqlDialect); } var dropPath = Path.Combine(scriptPath, "Timeout_Drop.sql"); File.Delete(dropPath); using (var writer = File.CreateText(dropPath)) { TimeoutScriptBuilder.BuildDropScript(writer, sqlDialect); } }
public void BuildCreateScript(BuildSqlDialect sqlDialect) { var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { TimeoutScriptBuilder.BuildCreateScript(writer, sqlDialect); } var script = builder.ToString(); if (sqlDialect == BuildSqlDialect.MsSqlServer) { SqlValidator.Validate(script); } Approver.Verify(script, scenario: "ForScenario." + sqlDialect); }
public void BuildCreateScript(BuildSqlVariant sqlVariant) { var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { TimeoutScriptBuilder.BuildCreateScript(writer, sqlVariant); } var script = builder.ToString(); if (sqlVariant == BuildSqlVariant.MsSqlServer) { SqlValidator.Validate(script); } using (ApprovalResults.ForScenario(sqlVariant)) { Approvals.Verify(script); } }
TimeoutPersister Setup(string theSchema, TimeSpan?cleanupInterval = null) { var name = GetTablePrefix(); using (var connection = dbConnection(theSchema)) { connection.Open(); connection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlDialect), name, schema: theSchema); connection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), name, schema: theSchema); } var preventCleanupInterval = goodUtcNowValue - new DateTime() + TimeSpan.FromDays(1); //Prevents entering cleanup mode right away (load timeouts from beginning of time) return(new TimeoutPersister( connectionBuilder: () => dbConnection(theSchema), tablePrefix: $"{name}_", sqlDialect: sqlDialect.Convert(theSchema), timeoutsCleanupExecutionInterval: cleanupInterval ?? preventCleanupInterval, utcNow: () => goodUtcNowValue)); }
TimeoutPersister Setup(TimeSpan?cleanupInterval = null) { var name = GetTablePrefix(); using (var connection = dbConnection()) { connection.Open(); connection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlVariant), name, schema: schema); connection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlVariant), name, schema: schema); } var preventCleanupInterval = DateTime.UtcNow - new DateTime() + TimeSpan.FromDays(1); //Prevents entering cleanup mode right away (load timeouts from beginning of time) return(new TimeoutPersister( connectionBuilder: dbConnection, tablePrefix: $"{name}_", sqlVariant: sqlVariant.Convert(), schema: schema, timeoutsCleanupExecutionInterval: cleanupInterval ?? preventCleanupInterval)); }
public void Write() { var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../"); foreach (var variant in Enum.GetValues(typeof(BuildSqlDialect)).Cast <BuildSqlDialect>()) { Write(directory, variant, "TimeoutCreate", TimeoutScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "TimeoutDrop", TimeoutScriptBuilder.BuildDropScript(variant)); Write(directory, variant, "OutboxCreate", OutboxScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "OutboxDrop", OutboxScriptBuilder.BuildDropScript(variant)); Write(directory, variant, "SubscriptionCreate", SubscriptionScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "SubscriptionDrop", SubscriptionScriptBuilder.BuildDropScript(variant)); var sagaDefinition = new SagaDefinition( tableSuffix: "OrderSaga", name: "OrderSaga", correlationProperty: new CorrelationProperty( name: "OrderNumber", type: CorrelationPropertyType.Int), transitionalCorrelationProperty: new CorrelationProperty( name: "OrderId", type: CorrelationPropertyType.Guid)); Write(directory, variant, "SagaCreate", SagaScriptBuilder.BuildCreateScript(sagaDefinition, variant)); Write(directory, variant, "SagaDrop", SagaScriptBuilder.BuildDropScript(sagaDefinition, variant)); } var dialects = new SqlDialect[] { new SqlDialect.MsSqlServer(), new SqlDialect.MySql(), new SqlDialect.Oracle(), new SqlDialect.PostgreSql() }; var assembly = typeof(SqlPersistence).Assembly; foreach (var dialect in dialects) { var timeoutCommands = GetCommand(dialect, "TimeoutCommandBuilder"); Write(directory, dialect, "TimeoutAdd", GetValue(timeoutCommands, "Add")); Write(directory, dialect, "TimeoutNext", GetValue(timeoutCommands, "Next")); Write(directory, dialect, "TimeoutRange", GetValue(timeoutCommands, "Range")); Write(directory, dialect, "TimeoutRemoveById", GetValue(timeoutCommands, "RemoveById")); Write(directory, dialect, "TimeoutRemoveBySagaId", GetValue(timeoutCommands, "RemoveBySagaId")); Write(directory, dialect, "TimeoutPeek", GetValue(timeoutCommands, "Peek")); var outboxCommands = GetCommand(dialect, "OutboxCommandBuilder"); Write(directory, dialect, "OutboxCleanup", GetValue(outboxCommands, "Cleanup")); Write(directory, dialect, "OutboxGet", GetValue(outboxCommands, "Get")); Write(directory, dialect, "OutboxSetAsDispatched", GetValue(outboxCommands, "SetAsDispatched")); Write(directory, dialect, "OutboxStore", GetValue(outboxCommands, "Store")); var subscriptionCommands = GetCommand(dialect, "SubscriptionCommandBuilder"); Write(directory, dialect, "SubscriptionSubscribe", GetValue(subscriptionCommands, "Subscribe")); Write(directory, dialect, "SubscriptionUnsubscribe", GetValue(subscriptionCommands, "Unsubscribe")); Write(directory, dialect, "SubscriptionGetSubscribers", GetSubscribersValue(subscriptionCommands, new List <MessageType> { new MessageType("MessageTypeName", new Version()) })); dynamic dialectAsDynamic = new ExposeInternalMethods(dialect); Write(directory, dialect, "SagaComplete", dialectAsDynamic.BuildCompleteCommand("EndpointName_SagaName")); Write(directory, dialect, "SagaGetByProperty", dialectAsDynamic.BuildGetByPropertyCommand("PropertyName", "EndpointName_SagaName")); Write(directory, dialect, "SagaGetBySagaId", dialectAsDynamic.BuildGetBySagaIdCommand("EndpointName_SagaName")); Write(directory, dialect, "SagaSave", dialectAsDynamic.BuildSaveCommand("CorrelationProperty", "TransitionalCorrelationProperty", "EndpointName_SagaName")); Write(directory, dialect, "SagaUpdate", dialectAsDynamic.BuildUpdateCommand("TransitionalCorrelationProperty", "EndpointName_SagaName")); // since we don't have docs on oracle saga finders if (!(dialect is SqlDialect.Oracle)) { var createSelectWithWhereClause = dialectAsDynamic.BuildSelectFromCommand("EndpointName_SagaName"); Write(directory, dialect, "SagaSelect", createSelectWithWhereClause("1 = 1")); } } }
public void Write() { var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../"); foreach (var variant in Enum.GetValues(typeof(BuildSqlDialect)).Cast <BuildSqlDialect>()) { Write(directory, variant, "TimeoutCreate", TimeoutScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "TimeoutDrop", TimeoutScriptBuilder.BuildDropScript(variant)); Write(directory, variant, "OutboxCreate", OutboxScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "OutboxDrop", OutboxScriptBuilder.BuildDropScript(variant)); Write(directory, variant, "SubscriptionCreate", SubscriptionScriptBuilder.BuildCreateScript(variant)); Write(directory, variant, "SubscriptionDrop", SubscriptionScriptBuilder.BuildDropScript(variant)); var sagaDefinition = new SagaDefinition( tableSuffix: "OrderSaga", name: "OrderSaga", correlationProperty: new CorrelationProperty( name: "OrderNumber", type: CorrelationPropertyType.Int), transitionalCorrelationProperty: new CorrelationProperty( name: "OrderId", type: CorrelationPropertyType.Guid)); Write(directory, variant, "SagaCreate", SagaScriptBuilder.BuildCreateScript(sagaDefinition, variant)); Write(directory, variant, "SagaDrop", SagaScriptBuilder.BuildDropScript(sagaDefinition, variant)); } var dialects = new SqlDialect[] { new SqlDialect.MsSqlServer(), new SqlDialect.MySql(), new SqlDialect.Oracle(), new SqlDialect.PostgreSql() }; foreach (var dialect in dialects) { var timeoutCommands = TimeoutCommandBuilder.Build( sqlDialect: dialect, tablePrefix: "EndpointName"); Write(directory, dialect, "TimeoutAdd", timeoutCommands.Add); Write(directory, dialect, "TimeoutNext", timeoutCommands.Next); Write(directory, dialect, "TimeoutRange", timeoutCommands.Range); Write(directory, dialect, "TimeoutRemoveById", timeoutCommands.RemoveById); Write(directory, dialect, "TimeoutRemoveBySagaId", timeoutCommands.RemoveBySagaId); Write(directory, dialect, "TimeoutPeek", timeoutCommands.Peek); var outboxCommands = OutboxCommandBuilder.Build( tablePrefix: "EndpointName", sqlDialect: dialect); Write(directory, dialect, "OutboxCleanup", outboxCommands.Cleanup); Write(directory, dialect, "OutboxGet", outboxCommands.Get); Write(directory, dialect, "OutboxSetAsDispatched", outboxCommands.SetAsDispatched); Write(directory, dialect, "OutboxStore", outboxCommands.Store); var subscriptionCommands = SubscriptionCommandBuilder.Build( sqlDialect: dialect, tablePrefix: "EndpointName"); Write(directory, dialect, "SubscriptionSubscribe", subscriptionCommands.Subscribe); Write(directory, dialect, "SubscriptionUnsubscribe", subscriptionCommands.Unsubscribe); Write(directory, dialect, "SubscriptionGetSubscribers", subscriptionCommands.GetSubscribers(new List <MessageType> { new MessageType("MessageTypeName", new Version()) })); Write(directory, dialect, "SagaComplete", dialect.BuildCompleteCommand("EndpointName_SagaName")); Write(directory, dialect, "SagaGetByProperty", dialect.BuildGetByPropertyCommand("PropertyName", "EndpointName_SagaName")); Write(directory, dialect, "SagaGetBySagaId", dialect.BuildGetBySagaIdCommand("EndpointName_SagaName")); Write(directory, dialect, "SagaSave", dialect.BuildSaveCommand("CorrelationProperty", "TransitionalCorrelationProperty", "EndpointName_SagaName")); Write(directory, dialect, "SagaUpdate", dialect.BuildUpdateCommand("TransitionalCorrelationProperty", "EndpointName_SagaName")); // since we don't have doco on oracle saga finders if (!(dialect is SqlDialect.Oracle)) { var createSelectWithWhereClause = dialect.BuildSelectFromCommand("EndpointName_SagaName"); Write(directory, dialect, "SagaSelect", createSelectWithWhereClause("1 = 1")); } } }
public override void WriteScripts(BuildSqlDialect dialect) { WriteScript("Timeout_Create.sql", writer => TimeoutScriptBuilder.BuildCreateScript(writer, dialect)); WriteScript("Timeout_Drop.sql", writer => TimeoutScriptBuilder.BuildDropScript(writer, dialect)); }