Methods Summary |
---|
protected void | checkDeserializedState(org.hibernate.Session session)Check the state of a fixture session after deserialization, as well
as validate the environmental state after session deserialization.
|
protected void | checkSerializedState(org.hibernate.Session session)Check the state of a fixture session after serialization, as well
as validate the environmental state after session serialization.
|
protected void | done()Used to cleanup the environment after testing (e.g., ending a JTA
transaction or closing a user-supplied connection).
|
public final java.lang.String[] | getMappings()
return new String[] { "connections/Silly.hbm.xml" };
|
protected abstract org.hibernate.Session | getSessionUnderTest()Used to get a session configured based on the config scenario being
tested.
|
protected void | prepare()Used to prepare the environment for testing (e.g., starting a
JTA transaction or obtaining a user-supplied connection).
|
protected abstract void | reconnect(org.hibernate.Session session)Perform any steps needed to reconnect a fixture session.
|
protected void | release(org.hibernate.Session session)Used to release a {@link #getSessionUnderTest fixture session}.
Overridden to perform session releasing/testing specific to the given
config scenario being tested.
if ( session != null && session.isOpen() ) {
try {
session.close();
}
catch( Throwable ignore ) {
}
}
|
public void | testBasicSessionUsage()Test that the basic session usage template works in all environment
scenarios.
prepare();
Session s = null;
Transaction txn = null;
try {
s = getSessionUnderTest();
txn = s.beginTransaction();
s.createQuery( "from Silly" ).list();
txn.commit();
}
catch( Throwable t ) {
if ( txn != null ) {
try {
txn.rollback();
}
catch( Throwable ignore ) {
}
}
}
finally {
if ( s != null && s.isOpen() ) {
try {
s.close();
}
catch( Throwable ignore ) {
}
}
}
done();
|
public final void | testConnectedSerialization()Tests to validate that a session holding JDBC resources will not
be allowed to serialize.
prepare();
Session sessionUnderTest = getSessionUnderTest();
// force the connection to be retained
sessionUnderTest.createQuery( "from Silly" ).scroll();
try {
SerializationHelper.serialize( sessionUnderTest );
fail( "Serialization of connected session allowed!" );
}
catch( IllegalStateException e ) {
// expected behaviour
}
finally {
release( sessionUnderTest );
done();
}
|
public final void | testManualDisconnectChain()Test that the legacy manual disconnect()/reconnect() chain works as
expected in the given environment.
prepare();
Session sessionUnderTest = getSessionUnderTest();
sessionUnderTest.disconnect();
byte[] bytes = SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest );
Session s2 = ( Session ) SerializationHelper.deserialize( bytes );
checkDeserializedState( s2 );
reconnect( s2 );
s2.disconnect();
reconnect( s2 );
release( sessionUnderTest );
release( s2 );
done();
|
public final void | testManualDisconnectWithOpenResources()Test that the legacy manual disconnect()/reconnect() chain works as
expected in the given environment. Similiar to {@link #testManualDisconnectChain}
expect that here we force the session to acquire and hold JDBC resources
prior to disconnecting.
prepare();
Session sessionUnderTest = getSessionUnderTest();
Silly silly = new Silly( "tester" );
sessionUnderTest.save( silly );
sessionUnderTest.flush();
sessionUnderTest.createQuery( "from Silly" ).iterate();
sessionUnderTest.disconnect();
SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest );
reconnect( sessionUnderTest );
sessionUnderTest.createQuery( "from Silly" ).scroll();
sessionUnderTest.disconnect();
SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest );
reconnect( sessionUnderTest );
sessionUnderTest.delete( silly );
sessionUnderTest.flush();
release( sessionUnderTest );
done();
|
public final void | testManualDisconnectedSerialization()Test that a session which has been manually disconnected will be allowed
to serialize.
prepare();
Session sessionUnderTest = getSessionUnderTest();
sessionUnderTest.disconnect();
SerializationHelper.serialize( sessionUnderTest );
checkSerializedState( sessionUnderTest );
release( sessionUnderTest );
done();
|
public void | testSessionClosedProtections()Test that session-closed protections work properly in all environments.
prepare();
Session s = getSessionUnderTest();
release( s );
done();
assertFalse( s.isOpen() );
assertFalse( s.isConnected() );
assertNotNull( s.getStatistics() );
assertNotNull( s.toString() );
try {
s.createQuery( "from Silly" ).list();
fail( "allowed to create query on closed session" );
}
catch( Throwable ignore ) {
}
try {
s.getTransaction();
fail( "allowed to access transaction on closed session" );
}
catch( Throwable ignore ) {
}
try {
s.connection();
fail( "allowed to access connection on closed session" );
}
catch( Throwable ignore ) {
}
try {
s.close();
fail( "allowed to close already closed session" );
}
catch( Throwable ignore ) {
}
try {
s.isDirty();
fail( "allowed to check dirtiness of closed session" );
}
catch( Throwable ignore ) {
}
|