From users-return-12226-apmail-jackrabbit-users-archive=jackrabbit.apache.org@jackrabbit.apache.org Mon Aug 10 17:21:37 2009 Return-Path: Delivered-To: apmail-jackrabbit-users-archive@minotaur.apache.org Received: (qmail 7375 invoked from network); 10 Aug 2009 17:21:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Aug 2009 17:21:36 -0000 Received: (qmail 88262 invoked by uid 500); 10 Aug 2009 17:21:42 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 87901 invoked by uid 500); 10 Aug 2009 17:21:40 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 87871 invoked by uid 99); 10 Aug 2009 17:21:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2009 17:21:39 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bgiles@coyotesong.com designates 74.125.92.27 as permitted sender) Received: from [74.125.92.27] (HELO qw-out-2122.google.com) (74.125.92.27) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2009 17:21:28 +0000 Received: by qw-out-2122.google.com with SMTP id 9so1120973qwb.13 for ; Mon, 10 Aug 2009 10:21:06 -0700 (PDT) Received: by 10.224.54.72 with SMTP id p8mr3380246qag.194.1249924866440; Mon, 10 Aug 2009 10:21:06 -0700 (PDT) Received: from ?10.10.6.23? (fw2.si-intl.com [208.97.217.4]) by mx.google.com with ESMTPS id 4sm790985qwe.25.2009.08.10.10.21.04 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 10 Aug 2009 10:21:05 -0700 (PDT) Message-ID: <4A805768.5030604@coyotesong.com> Date: Mon, 10 Aug 2009 11:22:48 -0600 From: Bear Giles User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: users@jackrabbit.apache.org Subject: Re: How to delete transient repository? References: <4A7C6D41.5010007@coyotesong.com> <91f3b2650908100141t4b150dd4hab2ecde563b1b0a0@mail.gmail.com> In-Reply-To: <91f3b2650908100141t4b150dd4hab2ecde563b1b0a0@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org 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 >