jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guo Du <mrdu...@gmail.com>
Subject Re: How to delete transient repository?
Date Tue, 11 Aug 2009 10:57:22 GMT
I didn't see you closed the inputstream in createRepository() , might
be a problem?

--Guo

On Mon, Aug 10, 2009 at 6:22 PM, Bear Giles<bgiles@coyotesong.com> wrote:
> I forgot about the in-memory FS, time to check the Wiki....
>
> My junit TestCase code follows.  The teardown method shuts down the
> repository, but I get an IOException (unable to delete a .bin file) even if
> I wait 15 seconds for unseen threads to terminate.
>
>
> /**
> * Test case for JCR tests.  This class handles creation of transient
> repository.
> */
> public abstract class AbstractJcrTestCase extends
> AbstractDependencyInjectionSpringContextTests {
>   private static final Logger logger =
> Logger.getLogger(AbstractJcrTestCase.class);
>   private static final String WORKSPACE_NAME = null;
>   protected Repository repository;
>   protected Credentials credentials = new SimpleCredentials("userid",
> "".toCharArray());
>   private String configFile =
> "gov/usda/aphis/vsps/dao/jcr/fileRepository.xml";
>   private String cndFile = "gov/usda/aphis/vsps/dao/jcr/vsps.cnd";
>   private File repositoryDirectory;
>
>   /**
>    * TODO: Document method
>    *
>    * @throws IOException TODO: Document exception
>    * @throws RuntimeRepositoryException TODO: Document exception
>    */
>   public void createRepository() throws IOException {
>       // read configuration stream
>       InputStream is = Thread.currentThread().getContextClassLoader()
>                              .getResourceAsStream(configFile);
>
>       if (is == null) {
>           throw new IOException("unable to open configuration stream!");
>       }
>
>       // identify good repository directory.
>       String tmpdir = System.getProperty("java.io.tmpdir");
>       repositoryDirectory = new File(new File(tmpdir),
>               "transient-jcr-repository-" + new Date().getTime());
>
>       if (logger.isInfoEnabled()) {
>           logger.info("repository location: " +
> repositoryDirectory.getAbsolutePath());
>       }
>
>       if (!repositoryDirectory.exists()) {
>           repositoryDirectory.mkdir();
>       }
>
>       // create repository.
>       RepositoryConfig config = null;
>
>       try {
>           config = RepositoryConfig.create(is,
> repositoryDirectory.getAbsolutePath());
>       } catch (RepositoryException e) {
>           throw new RuntimeRepositoryException(e);
>       }
>
>       repository = new TransientRepository(config);
>
>       // set up VSPS node types.
>       Session session = null;
>
>       try {
>           session = repository.login(credentials, WORKSPACE_NAME);
>
>           JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
> session.getWorkspace()
>
>      .getNodeTypeManager();
>           is =
> Thread.currentThread().getContextClassLoader().getResourceAsStream(cndFile);
>           manager.registerNodeTypes(is,
> JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
>       } catch (RepositoryException e) {
>           throw new RuntimeRepositoryException(e);
>       } finally {
>           if (session != null) {
>               session.logout();
>           }
>       }
>   }
>
>   /**
>    * Create repository on setup.
>    */
>   @Override
>   public void onSetUp() throws Exception {
>       super.onSetUp();
>       createRepository();
>   }
>
>   /**
>    * Destroy repository on teardown.
>    */
>   @Override
>   public void onTearDown() throws Exception {
>       // this should not be necessary with transient repository, but it
>       // won't hurt.
>       if (repository instanceof JackrabbitRepository) {
>           ((JackrabbitRepository) repository).shutdown();
>       }
>
>       // delete transient repository
>       if ((repositoryDirectory != null) && repositoryDirectory.exists()) {
>           //FileUtils.deleteDirectory(repositoryDirectory);
>       }
>
>       super.onTearDown();
>   }
> }
>
>
> Thomas Müller wrote:
>>
>> Hi,
>>
>>
>>>
>>> How do I delete a transient repository?  My code is successfully creating
>>> and shutting down the repository, but when I try to delete the directory
>>> (using jakarta commons IO) I get an exception because of some of the data
>>> files.
>>>
>>
>> That sounds like a bug in Jackrabbit. Which files can not be deleted?
>>
>>
>>>
>>> Is there a standard way to do this that is guaranteed to work?
>>>
>>
>> Use Linux. Just joking.
>>
>> Did you consider using in-memory file system and persistence managers?
>>
>> Regards,
>> Thomas
>>
>
>

Mime
View raw message