Oren Eini

CEO of RavenDB

a NoSQL Open Source Document Database

Get in touch with me:

oren@ravendb.net +972 52-548-6969

Posts: 7,546
|
Comments: 51,163
Privacy Policy · Terms
filter by tags archive
time to read 6 min | 1051 words

Just a quick note before continuing. In NHibernate, most tests inherits from the abstract NHibernate.Test.TestCase class. This class is responsible for the infrastructure of the test. By that I mean that it instansiate a Session Factory, create the appropriate tables, etc.

A test fixture specify how to find its mapping using these two properties:

/// <summary>

/// Mapping files used in the TestCase

/// </summary>

protected abstract IList Mappings { get; }

 

/// <summary>

/// Assembly to load mapping files from (default is NHibernate.DomainModel).

/// </summary>

protected virtual string MappingsAssembly

{

      get { return "NHibernate.DomainModel"; }

}

Creating a session is done by calling the protected method OpenSession().

This frees the tester from dealing with all those issues. (Just automatically creating the tables is a huge burden of my chest).

One important thing to note is that NHibernate expect the test to clean up after itself. It should close the session, delete any data that you put in the database and close any connections that you have opened.

If you are interested in modifying the configuration (as I did, to add support for second level caching), you can access the base.Cfg variable, and modify it, and then generate a new session factory from that.

That is enough details for now, I think.

time to read 2 min | 326 words

I mentioned before that I am now part of the NHibernate project, but so far I haven't done much with it. In what turns out to be a nice timing, I found a fairly obscure bug that I hope that I can fix, and I am going to bore you with all the nitty gritty details of how I am going to do it.

Before I can begin, let me describe what area I am going to work at.

NHibernate has two level of caches. The first level is the session, which holds all the entities that were loaded (or saved) with the session. This cache is not shared among threads/requests. This cache hold the objects as fully instansiated entities, which mean that sharing them among threads/requests will cause multi threading issues.

The second level cache is shared among all the session that were created from the same session factory (typically, you only have a single session factory per application, so in essense, this is an application level cache). There are several targets to this second level cache, but the most common are:

  • Hashtable cache (for debugging/testing purposes only)
  • SysCache - which utilize the ASP.Net Cache
  • Memcached - a distributed caching system

The second level cache does not hold entities, but collections of values. This means that you don't have to worry about mutli threading issues when you use this cache.

As far as I can see, the second level cache isn't very utilized in NHibernate projects, although I am not quite sure why this is the case, since it can give quite a performance boost to an application, without affecting the client code.

FUTURE POSTS

  1. Partial writes, IO_Uring and safety - 9 hours from now
  2. Configuration values & Escape hatches - 3 days from now
  3. What happens when a sparse file allocation fails? - 5 days from now
  4. NTFS has an emergency stash of disk space - 7 days from now
  5. Challenge: Giving file system developer ulcer - 10 days from now

And 4 more posts are pending...

There are posts all the way to Feb 17, 2025

RECENT SERIES

  1. Challenge (77):
    20 Jan 2025 - What does this code do?
  2. Answer (13):
    22 Jan 2025 - What does this code do?
  3. Production post-mortem (2):
    17 Jan 2025 - Inspecting ourselves to death
  4. Performance discovery (2):
    10 Jan 2025 - IOPS vs. IOPS
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats
}