|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Closing the hsql corrrectlyHello,
How can I close my hsql at the end of unit test, because my database is not closed at the end of the test: the entry 'modified' is set to 'yes' in the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ? |
|
|
Re: Closing the hsql corrrectlyHi,
Here's my solution to do a clean shutdown of HSQL when using the file version, I've used the experimental singleton feature of EJB 3.1 to do that but since it is only for testing I don't mind: ------------------------------------------------------------------------------------------------------------------- @Singleton @Startup public class DatabaseBean implements Database { @Resource private DataSource testDataSource; @PreDestroy public void shutdown() { BasicManagedDataSource basicManagedDataSource = (BasicManagedDataSource) testDataSource; if (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) { try { // this is a hack to do a clean shutdown of hsqldb... testDataSource.getConnection().createStatement().execute("SHUTDOWN"); } catch (Exception e) { e.printStackTrace(); } } } } ------------------------------------------------------------------------------------------------------------------- Don't forget to change the the datasource name... Hope this helps! Christian On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: > > Hello, > > How can I close my hsql at the end of unit test, because my database is > not closed at the end of the test: the entry 'modified' is set to 'yes' in > the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ? > -- > View this message in context: > http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html > Sent from the OpenEJB User mailing list archive at Nabble.com. > > |
|
|
Re: Closing the hsql corrrectlyHey,
You want to do a shutdown after each test? Is that after every literal test (every test method) or after every unit test (test class)? If I understand your code correctly, this will only work if a new OpenEJB instance is started, meaning the VM is closed and reopened, or you do it manually. Or am I wrong with this? Could you perhaps explain a bit more about how your code works, because a Singleton's @PreDestroy will only be called when the Singleton gets destroyed, which only happens when the Container gets destroyed, which in turn closes with OpenEJB. Quintin Beukes On Fri, Oct 23, 2009 at 8:01 PM, Christian Bourque <christian.bourque@...> wrote: > Hi, > > Here's my solution to do a clean shutdown of HSQL when using the file > version, I've used the experimental singleton feature of EJB 3.1 to do that > but since it is only for testing I don't mind: > > ------------------------------------------------------------------------------------------------------------------- > @Singleton > @Startup > public class DatabaseBean implements Database > { > @Resource > private DataSource testDataSource; > > @PreDestroy > public void shutdown() > { > BasicManagedDataSource basicManagedDataSource = > (BasicManagedDataSource) testDataSource; > > if > (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) > { > try > { > // this is a hack to do a clean shutdown of hsqldb... > > testDataSource.getConnection().createStatement().execute("SHUTDOWN"); > } > catch (Exception e) > { > e.printStackTrace(); > } > } > } > } > ------------------------------------------------------------------------------------------------------------------- > > Don't forget to change the the datasource name... > > Hope this helps! > > Christian > > On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: > >> >> Hello, >> >> How can I close my hsql at the end of unit test, because my database is >> not closed at the end of the test: the entry 'modified' is set to 'yes' in >> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ? >> -- >> View this message in context: >> http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html >> Sent from the OpenEJB User mailing list archive at Nabble.com. >> >> > |
|
|
Re: Closing the hsql corrrectlyHey,
Well in my case the container is started before tests are run and stopped after all tests have been executed (using @BeforeClass and @AfterClass). Of course you don't want to shut it down after every test because the database would be overridden each time... If you have multiple test classes I guess you could apply the same technique using a test suite... Hope this helps... Christian On Fri, Oct 23, 2009 at 3:29 PM, Quintin Beukes <quintin@...>wrote: > Hey, > > You want to do a shutdown after each test? Is that after every literal > test (every test method) or after every unit test (test class)? > > If I understand your code correctly, this will only work if a new > OpenEJB instance is started, meaning the VM is closed and reopened, or > you do it manually. Or am I wrong with this? > > Could you perhaps explain a bit more about how your code works, > because a Singleton's @PreDestroy will only be called when the > Singleton gets destroyed, which only happens when the Container gets > destroyed, which in turn closes with OpenEJB. > > Quintin Beukes > > > > On Fri, Oct 23, 2009 at 8:01 PM, Christian Bourque > <christian.bourque@...> wrote: > > Hi, > > > > Here's my solution to do a clean shutdown of HSQL when using the file > > version, I've used the experimental singleton feature of EJB 3.1 to do > that > > but since it is only for testing I don't mind: > > > > > ------------------------------------------------------------------------------------------------------------------- > > @Singleton > > @Startup > > public class DatabaseBean implements Database > > { > > @Resource > > private DataSource testDataSource; > > > > @PreDestroy > > public void shutdown() > > { > > BasicManagedDataSource basicManagedDataSource = > > (BasicManagedDataSource) testDataSource; > > > > if > > (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) > > { > > try > > { > > // this is a hack to do a clean shutdown of hsqldb... > > > > testDataSource.getConnection().createStatement().execute("SHUTDOWN"); > > } > > catch (Exception e) > > { > > e.printStackTrace(); > > } > > } > > } > > } > > > ------------------------------------------------------------------------------------------------------------------- > > > > Don't forget to change the the datasource name... > > > > Hope this helps! > > > > Christian > > > > On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: > > > >> > >> Hello, > >> > >> How can I close my hsql at the end of unit test, because my database is > >> not closed at the end of the test: the entry 'modified' is set to 'yes' > in > >> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ? > >> -- > >> View this message in context: > >> > http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html > >> Sent from the OpenEJB User mailing list archive at Nabble.com. > >> > >> > > > |
|
|
Re: Closing the hsql corrrectlyYes, that clears it up. If you don't mind me asking another question,
how do you shut down the container in @AfterClass? Quintin Beukes On Fri, Oct 23, 2009 at 10:31 PM, Christian Bourque <christian.bourque@...> wrote: > Hey, > > Well in my case the container is started before tests are run and stopped > after all tests have been executed (using @BeforeClass and @AfterClass). > > Of course you don't want to shut it down after every test because the > database would be overridden each time... > > If you have multiple test classes I guess you could apply the same technique > using a test suite... > > Hope this helps... > > Christian > > On Fri, Oct 23, 2009 at 3:29 PM, Quintin Beukes <quintin@...>wrote: > >> Hey, >> >> You want to do a shutdown after each test? Is that after every literal >> test (every test method) or after every unit test (test class)? >> >> If I understand your code correctly, this will only work if a new >> OpenEJB instance is started, meaning the VM is closed and reopened, or >> you do it manually. Or am I wrong with this? >> >> Could you perhaps explain a bit more about how your code works, >> because a Singleton's @PreDestroy will only be called when the >> Singleton gets destroyed, which only happens when the Container gets >> destroyed, which in turn closes with OpenEJB. >> >> Quintin Beukes >> >> >> >> On Fri, Oct 23, 2009 at 8:01 PM, Christian Bourque >> <christian.bourque@...> wrote: >> > Hi, >> > >> > Here's my solution to do a clean shutdown of HSQL when using the file >> > version, I've used the experimental singleton feature of EJB 3.1 to do >> that >> > but since it is only for testing I don't mind: >> > >> > >> ------------------------------------------------------------------------------------------------------------------- >> > @Singleton >> > @Startup >> > public class DatabaseBean implements Database >> > { >> > @Resource >> > private DataSource testDataSource; >> > >> > @PreDestroy >> > public void shutdown() >> > { >> > BasicManagedDataSource basicManagedDataSource = >> > (BasicManagedDataSource) testDataSource; >> > >> > if >> > (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) >> > { >> > try >> > { >> > // this is a hack to do a clean shutdown of hsqldb... >> > >> > testDataSource.getConnection().createStatement().execute("SHUTDOWN"); >> > } >> > catch (Exception e) >> > { >> > e.printStackTrace(); >> > } >> > } >> > } >> > } >> > >> ------------------------------------------------------------------------------------------------------------------- >> > >> > Don't forget to change the the datasource name... >> > >> > Hope this helps! >> > >> > Christian >> > >> > On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: >> > >> >> >> >> Hello, >> >> >> >> How can I close my hsql at the end of unit test, because my database is >> >> not closed at the end of the test: the entry 'modified' is set to 'yes' >> in >> >> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ? >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html >> >> Sent from the OpenEJB User mailing list archive at Nabble.com. >> >> >> >> >> > >> > |
|
|
Re: Closing the hsql corrrectlyBy calling "close()" on the initial context that bootstrapped the container.
You have to set this property on the initial context though : properties.setProperty("openejb.embedded.initialcontext.close", "DESTROY"); Christian On Fri, Oct 23, 2009 at 5:01 PM, Quintin Beukes <quintin@...>wrote: > Yes, that clears it up. If you don't mind me asking another question, > how do you shut down the container in @AfterClass? > > Quintin Beukes > > > > On Fri, Oct 23, 2009 at 10:31 PM, Christian Bourque > <christian.bourque@...> wrote: > > Hey, > > > > Well in my case the container is started before tests are run and stopped > > after all tests have been executed (using @BeforeClass and @AfterClass). > > > > Of course you don't want to shut it down after every test because the > > database would be overridden each time... > > > > If you have multiple test classes I guess you could apply the same > technique > > using a test suite... > > > > Hope this helps... > > > > Christian > > > > On Fri, Oct 23, 2009 at 3:29 PM, Quintin Beukes <quintin@... > >wrote: > > > >> Hey, > >> > >> You want to do a shutdown after each test? Is that after every literal > >> test (every test method) or after every unit test (test class)? > >> > >> If I understand your code correctly, this will only work if a new > >> OpenEJB instance is started, meaning the VM is closed and reopened, or > >> you do it manually. Or am I wrong with this? > >> > >> Could you perhaps explain a bit more about how your code works, > >> because a Singleton's @PreDestroy will only be called when the > >> Singleton gets destroyed, which only happens when the Container gets > >> destroyed, which in turn closes with OpenEJB. > >> > >> Quintin Beukes > >> > >> > >> > >> On Fri, Oct 23, 2009 at 8:01 PM, Christian Bourque > >> <christian.bourque@...> wrote: > >> > Hi, > >> > > >> > Here's my solution to do a clean shutdown of HSQL when using the file > >> > version, I've used the experimental singleton feature of EJB 3.1 to do > >> that > >> > but since it is only for testing I don't mind: > >> > > >> > > >> > ------------------------------------------------------------------------------------------------------------------- > >> > @Singleton > >> > @Startup > >> > public class DatabaseBean implements Database > >> > { > >> > @Resource > >> > private DataSource testDataSource; > >> > > >> > @PreDestroy > >> > public void shutdown() > >> > { > >> > BasicManagedDataSource basicManagedDataSource = > >> > (BasicManagedDataSource) testDataSource; > >> > > >> > if > >> > > (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) > >> > { > >> > try > >> > { > >> > // this is a hack to do a clean shutdown of hsqldb... > >> > > >> > testDataSource.getConnection().createStatement().execute("SHUTDOWN"); > >> > } > >> > catch (Exception e) > >> > { > >> > e.printStackTrace(); > >> > } > >> > } > >> > } > >> > } > >> > > >> > ------------------------------------------------------------------------------------------------------------------- > >> > > >> > Don't forget to change the the datasource name... > >> > > >> > Hope this helps! > >> > > >> > Christian > >> > > >> > On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: > >> > > >> >> > >> >> Hello, > >> >> > >> >> How can I close my hsql at the end of unit test, because my database > is > >> >> not closed at the end of the test: the entry 'modified' is set to > 'yes' > >> in > >> >> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) > ? > >> >> -- > >> >> View this message in context: > >> >> > >> > http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html > >> >> Sent from the OpenEJB User mailing list archive at Nabble.com. > >> >> > >> >> > >> > > >> > > > |
|
|
Re: Closing the hsql corrrectlyThanks. I was wondering about that for the openejb-junit project.
Quintin Beukes On Fri, Oct 23, 2009 at 11:23 PM, Christian Bourque <christian.bourque@...> wrote: > By calling "close()" on the initial context that bootstrapped the container. > You have to set this property on the initial context though : > > properties.setProperty("openejb.embedded.initialcontext.close", "DESTROY"); > > Christian > > On Fri, Oct 23, 2009 at 5:01 PM, Quintin Beukes <quintin@...>wrote: > >> Yes, that clears it up. If you don't mind me asking another question, >> how do you shut down the container in @AfterClass? >> >> Quintin Beukes >> >> >> >> On Fri, Oct 23, 2009 at 10:31 PM, Christian Bourque >> <christian.bourque@...> wrote: >> > Hey, >> > >> > Well in my case the container is started before tests are run and stopped >> > after all tests have been executed (using @BeforeClass and @AfterClass). >> > >> > Of course you don't want to shut it down after every test because the >> > database would be overridden each time... >> > >> > If you have multiple test classes I guess you could apply the same >> technique >> > using a test suite... >> > >> > Hope this helps... >> > >> > Christian >> > >> > On Fri, Oct 23, 2009 at 3:29 PM, Quintin Beukes <quintin@... >> >wrote: >> > >> >> Hey, >> >> >> >> You want to do a shutdown after each test? Is that after every literal >> >> test (every test method) or after every unit test (test class)? >> >> >> >> If I understand your code correctly, this will only work if a new >> >> OpenEJB instance is started, meaning the VM is closed and reopened, or >> >> you do it manually. Or am I wrong with this? >> >> >> >> Could you perhaps explain a bit more about how your code works, >> >> because a Singleton's @PreDestroy will only be called when the >> >> Singleton gets destroyed, which only happens when the Container gets >> >> destroyed, which in turn closes with OpenEJB. >> >> >> >> Quintin Beukes >> >> >> >> >> >> >> >> On Fri, Oct 23, 2009 at 8:01 PM, Christian Bourque >> >> <christian.bourque@...> wrote: >> >> > Hi, >> >> > >> >> > Here's my solution to do a clean shutdown of HSQL when using the file >> >> > version, I've used the experimental singleton feature of EJB 3.1 to do >> >> that >> >> > but since it is only for testing I don't mind: >> >> > >> >> > >> >> >> ------------------------------------------------------------------------------------------------------------------- >> >> > @Singleton >> >> > @Startup >> >> > public class DatabaseBean implements Database >> >> > { >> >> > @Resource >> >> > private DataSource testDataSource; >> >> > >> >> > @PreDestroy >> >> > public void shutdown() >> >> > { >> >> > BasicManagedDataSource basicManagedDataSource = >> >> > (BasicManagedDataSource) testDataSource; >> >> > >> >> > if >> >> > >> (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) >> >> > { >> >> > try >> >> > { >> >> > // this is a hack to do a clean shutdown of hsqldb... >> >> > >> >> > testDataSource.getConnection().createStatement().execute("SHUTDOWN"); >> >> > } >> >> > catch (Exception e) >> >> > { >> >> > e.printStackTrace(); >> >> > } >> >> > } >> >> > } >> >> > } >> >> > >> >> >> ------------------------------------------------------------------------------------------------------------------- >> >> > >> >> > Don't forget to change the the datasource name... >> >> > >> >> > Hope this helps! >> >> > >> >> > Christian >> >> > >> >> > On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: >> >> > >> >> >> >> >> >> Hello, >> >> >> >> >> >> How can I close my hsql at the end of unit test, because my database >> is >> >> >> not closed at the end of the test: the entry 'modified' is set to >> 'yes' >> >> in >> >> >> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) >> ? >> >> >> -- >> >> >> View this message in context: >> >> >> >> >> >> http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html >> >> >> Sent from the OpenEJB User mailing list archive at Nabble.com. >> >> >> >> >> >> >> >> > >> >> >> > >> > |
|
|
Re: Closing the hsql corrrectlyIs it necessary to have a Singleton ?
|
|
|
Re: Closing the hsql corrrectlyTechnically not, but it's the cleaner solution IMO. You want the
shutdown to occur only once. Since stateless beans are in pools @PreDestroy will be called more than once. So for a stateless bean you would need some static variable and synchronization to control this. With a Singleton, all these things are unnecessary. Quintin Beukes On Sat, Oct 24, 2009 at 8:12 AM, hypnosat7 <ablarbi@...> wrote: > > Is it necessary to have a Singleton ? > > Christian Bourque wrote: >> >> Hi, >> >> Here's my solution to do a clean shutdown of HSQL when using the file >> version, I've used the experimental singleton feature of EJB 3.1 to do >> that >> but since it is only for testing I don't mind: >> >> ------------------------------------------------------------------------------------------------------------------- >> @Singleton >> @Startup >> public class DatabaseBean implements Database >> { >> @Resource >> private DataSource testDataSource; >> >> @PreDestroy >> public void shutdown() >> { >> BasicManagedDataSource basicManagedDataSource = >> (BasicManagedDataSource) testDataSource; >> >> if >> (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver")) >> { >> try >> { >> // this is a hack to do a clean shutdown of hsqldb... >> >> testDataSource.getConnection().createStatement().execute("SHUTDOWN"); >> } >> catch (Exception e) >> { >> e.printStackTrace(); >> } >> } >> } >> } >> ------------------------------------------------------------------------------------------------------------------- >> >> Don't forget to change the the datasource name... >> >> Hope this helps! >> >> Christian >> >> On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@...> wrote: >> >>> >>> Hello, >>> >>> How can I close my hsql at the end of unit test, because my database is >>> not closed at the end of the test: the entry 'modified' is set to 'yes' >>> in >>> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ? >>> -- >>> View this message in context: >>> http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html >>> Sent from the OpenEJB User mailing list archive at Nabble.com. >>> >>> >> >> > > -- > View this message in context: http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26036443.html > Sent from the OpenEJB User mailing list archive at Nabble.com. > > |
| Free embeddable forum powered by Nabble | Forum Help |