开发者

db4o - DatabaseClosedException

I am trying to store an entity with db4o through an arquillian test case and am getting a DatabaseClosedException:


Test set: com.walterjwhite.address.api.datastore.TestAddressDatastore

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.149 sec <<< FAILURE! test_save(com.walterjwhite.address.api.datastore.TestAddressDatastore) Time elapsed: 0.68 sec <<< ERROR! com.db4o.ext.DatabaseClosedException at com.db4o.internal.ObjectContainerBase.checkClosed(ObjectContainerBase.java:303) at com.db4o.internal.ObjectContainerBase.checkTransaction(ObjectContainerBase.java:331) at com.db4o.internal.ObjectContainerBase.asTopLevelStore(ObjectContainerBase.java:412) at com.db4o.internal.ObjectContainerBase.storeInternal(ObjectContainerBase.java:1602) at com.db4o.internal.ObjectContainerBase.store(ObjectContainerBase.java:1584) at com.db4o.internal.ObjectContainerBase.store(ObjectContainerBase.java:1576) at com.db4o.internal.ObjectContainerSession.store(ObjectContainerSession.java:360) at com.walterjwhite.datastore.api.AbstractDatastore.save(AbstractDatastore.java:79) at com.walterjwhite.address.api.datastore.org$jboss$weld$bean-0b7a0e6e-330e-4c1b-8c9e-1e90ab004c80$jar-ManagedBean-class_com$walterjwhite$address$api$datastore$AddressDatastore_$$_WeldClientProxy.save(org$jboss$weld$bean-0b7a0e6e-330e-4c1b-8c9e-1e90ab004c80$jar-ManagedBean-class_com$walterjwhite$address$api$datastore$AddressDatastore_$$_WeldClientProxy.java) at com.walterjwhite.address.api.datastore.TestAddressDatastore.test_save(TestAddressDatastore.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:259) at org.jboss.arquillian.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80) at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126) at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:106) at org.jboss.arquillian.impl.core.EventImpl.fire(EventImpl.java:67) at org.jboss.arquillian.impl.client.protocol.local.LocalContainerMethodExecutor.invoke(LocalContainerMethodExecutor.java:50) at org.jboss.arquillian.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:97) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80) at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126) at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:106) at org.jboss.arquillian.impl.core.EventImpl.fire(EventImpl.java:67) at org.jboss.arquillian.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80) at org.jboss.arquillian.impl.client.ContainerDeploymentContextHandler.createContext(ContainerDeploymentContextHandler.java:133) at org.jboss.arquillian.impl.client.ContainerDeploymentContextHandler.createTestContext(ContainerDeploymentContextHandler.java:120) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87) at org.jboss.arquillian.impl.TestContextHandler.createTestContext(TestContextHandler.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87) at org.jboss.arquillian.impl.TestContextHandler.createClassContext(TestContextHandler.java:68) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 开发者_如何学JAVA at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87) at org.jboss.arquillian.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90) at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87) at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126) at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:101) at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:251) at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:214) at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303) at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45) at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:228) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:173) at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303) at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45) at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:187) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103) at $Proxy0.invoke(Unknown Source) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

@Produces
protected ObjectServer openServer(ApplicationContext applicationContext)
{
    return (Db4oClientServer.openServer("/tmp/test.db4o", 0));
}

@Produces
public ObjectContainer getObjectContainer(ObjectServer objectServer)
{
    return (objectServer.openClient());
}

For my test case, I am creating an object server with the file in /tmp. The file is created, the object container is automatically injected through a setter, otherwise the objectContainer would be null and this would be a different exception.

I put some debug statements into the code to make sure the dispose method wasn't being called until after the store invocation so I can rule out that potential issue.

What else do I need to do to prepare the container?

Thanks,

Walter


Do you see the file test.db4o being created in tmp? Make sure the directory where you write the db exists and is accessible to the proces that tries to create it.


When this has happened to me in the past, an earlier error has closed the database before this exception gets thrown. My suggestions is to look for other errors before this is thrown.


I figured it out ... I didn't have the right scope specified on my bean ... I wrote a simple test application without Weld / CDI and it worked fine. The ObjectServer was getting closed almost immediately after it was opened.

After I changed it to the proper scope which was a singleton for the server, it worked.

Walter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜