Thank you for your input.
 
I am actually working on a presentation for our local JUG where I
describe processes for testing with data access code.  My final
recommendation is to use an in-memory database which solves the problem
I posted to the list.
 
However in the context of the presentation, I am presenting alternatives
(sub-optimal alternatives in my mind) to using an in-memory database,
and one of those alternatives is to use an existing database.  In
attempting to write up the sample code I noticed this asymetry in the
SpringLiquibaseObject.  (i.e can auto load, but not auto-unoad)  The
asymetry sounds like it was designed into the object on purpose, but I
figured it didn't hurt to ask.
 

JB 

"The best way to predict the future is to invent it." 
- Alan Kay 

 

________________________________

From: Bram Whillock [mailto:[email protected]] 
Sent: Wednesday, July 14, 2010 7:00 PM
To: [email protected]
Subject: Re: [Liquibase-user] Rollbacks from Spring


Hey Jonathan, 

So, we did this at our company.  However, we used an in-memory database
for all of our tests, in our case it was HyperSonic.

http://hsqldb.org/

<http://hsqldb.org/> If you're using Java, it's perfect for a db you
want for unit tests only.  Your mileage may vary with your schemas
running correctly against both types of dbs.

Cheers,
-Bram


On Wed, Jul 14, 2010 at 2:40 PM, Nathan Voxland <[email protected]>
wrote:


        My concern would be that the normal use isn't to rollback your
        database changes and it could be accidentally triggered.  The
way you
        are implementing it works well for your use, but I don't think
it's
        something we want in the core library.  It would work well as an
        extension, though (http://liquibase.org/extensions)
        
        Nathan
        

        On Wed, Jul 14, 2010 at 7:46 AM, Baker,Jonathan
<[email protected]> wrote:
        > I have begun evaluating liquibase.  So far I think it will be
extemely
        > useful for our team.
        >
        > I am trying to use it in the context of unit testing.  I'd
like to ensure
        > that my testing database matches our released database schema.
I am using
        > the spring framework and junit 4 for my testing harness.  I
utilize the
        > SpringLiquibase object to load our tables for the tests.  This
works great
        > for creating the tables, but once the tests are done, there is
no clean way
        > to unload all of the changes I just made to ensure that the
database is in
        > the same state as when I started.
        >
        > I know I can utilize the Liquibase object in @Before and
@After methods to
        > load and unload the tables.  And for now, I have implemented
that.
        >
        > <bean name="liquibase"  class="liquibase.Liquibase">
        >     <constructor-arg index="0"
value="phonebook-create-changelog.xml"/>
        >     <constructor-arg index="1">
        >         <bean class="liquibase.ClassLoaderFileOpener"/>
        >     </constructor-arg>
        >     <constructor-arg index="2">
        >         <bean id="dataSource.connection"
        >
        >
class="org.springframework.beans.factory.config.PropertyPathFactoryBean"
/>
        >     </constructor-arg>
        > </bean>
        >
        >     @Resource
        >   private Liquibase liquibase;
        >
        >   private void create_tables() throws Throwable {
        >       liquibase.update("");
        >   }
        >
        >   @After
        >   public void drop_tables() throws Throwable {
        >       liquibase.rollback(Integer.MAX_VALUE, "");
        >   }
        >
        >   @Before
        >   public void setup_database() throws Throwable {
        >       create_tables();
        >       load_test_data();
        >   }
        >
        > I would prefer if the SpringLiquibase object had something
like a
        > rollbackOnDestroy() that would allow spring to trigger a
rollback when it
        > unloaded the application context.  You could configure it like
this:
        >
        > <bean name="spring.liquibase"
class="liquibase.spring.SpringLiquibase"
        > destroy-method="rollbackOnDestroy">
        >     <property name="dataSource" ref="dataSource"/>
        >     <property name="changeLog"
        > value="classpath:phonebook-create-changelog.xml"/>
        >     <property name="contexts" value="test, production"/>
        > </bean>
        >
        > The rollbackOnDestroy method would only be called if it was
configured.  I
        > am rolling back to Integer.MAX_VALUE because I want everything
rolled back
        > so that my database is empty before and after any test, but
that could be
        > added as a configured property on the SpringLiquibase object
such as
        > maxChangeRollbackCount.
        >
        > I threw together a quick attempt at implementing this:
        >
        >     /**
        >      * Optionally executed when bean is destroyed
        >      */
        >     public void rollbackOnDestroy() throws LiquibaseException
{
        >
        >         Connection c = null;
        >         try {
        >             c = getDataSource().getConnection();
        >             Liquibase liquibase = createLiquibase(c);
        >
        >             liquibase.rollback(Integer.MAX_VALUE,
getContexts());
        >         } catch (SQLException e) {
        >             throw new JDBCException(e);
        >         } finally {
        >             if (c != null) {
        >                 try {
        >                     c.rollback();
        >                     c.close();
        >                 } catch (SQLException e) {
        >                     //nothing to do
        >                 }
        >             }
        >         }
        >     }
        >
        > Something along these lines would be a good enhancement to the
        > SpringLiquibase object, and would greatly assist with testing.
        > Unfortunately the maven plugin doesn't help here as there is
no maven
        > lifecycle event such as after-test to ensure that things
happen after the
        > unit tests when a user types mvn test.
        >
        > JB
        >
        > "The best way to predict the future is to invent it."
        > - Alan Kay
        >
        
        >
------------------------------------------------------------------------
------
        > This SF.net email is sponsored by Sprint
        > What will you do first with EVO, the first 4G phone?
        > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
        > _______________________________________________
        > Liquibase-user mailing list
        > [email protected]
        > https://lists.sourceforge.net/lists/listinfo/liquibase-user
        >
        >
        
        
------------------------------------------------------------------------
------
        This SF.net email is sponsored by Sprint
        What will you do first with EVO, the first 4G phone?
        Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
        _______________________________________________
        Liquibase-user mailing list
        [email protected]
        https://lists.sourceforge.net/lists/listinfo/liquibase-user
        


------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Liquibase-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/liquibase-user

Reply via email to