friism
friism

Reputation: 19279

NEventStore and Sqlite in-memory

I'm trying to unit test EventStore persistence using JSON serialization and Sqlite running in inmemory-mode. I'm getting a "No such table: Commits" exception during EventStore initialization. I'm assuming this is because EventStore somehow closes the connection and opens a new one, causing it to see a new in-memory Sqlite instance (sans Commits table). Is there any way to make this work?

Upvotes: 3

Views: 1132

Answers (1)

Jonathan Oliver
Jonathan Oliver

Reputation: 5267

The SQLite implementation is interesting, especially when you're using the ":memory:" connection string. The acceptance tests surrounding the implementation depend upon the the database not "disappearing" between operations.

The fundamental design of the EventStore separates each discrete action into a separate operation which:

  1. Depending upon the configuration, enlists in the ambient TransactionScope (if any)
  2. Opens the connection
  3. Builds the IDbCommand
  4. Executes the IDbCommand
  5. Evaluates the results
  6. Disposes the connection (releasing it back to the pool)
  7. Completes the TransactionScope (when no exceptions are thrown)
  8. Disposes the TransactionScope

The issue that you're running into is that each invocation against the EventStore opens and closes the connection.

Now, there is a way around this because I wanted to support explicitly utilizing the same IDbConnection without releasing it back to the pool. EventStore v3.0 (which is in release candidate stage) has a method call that utilizes the same connection and which avoids connection tear down after each operation:

ConfigurationConnectionFactory.OpenScope("SQLite"); // SQLite = app.config connection key

Simply add this to the "using_the_persistence_engine" acceptance tests class and you're all set:

private static IDisposable scope;

Add this as the first line to "Establish context":

scope = ConfigurationConnectionFactory.OpenScope("SQLite");

Finally, the lastline in "Cleanup everything" should be:

scope.Dispose();

Upvotes: 3

Related Questions