{"action":"created","comment":{"url":"https://api.github.com/repos/sonatype/nexus-oss/pulls/comments/27405725","id":27405725,"diff_hunk":"@@ -0,0 +1,168 @@\n+/*\n+ * Sonatype Nexus (TM) Open Source Version\n+ * Copyright (c) 2008-2015 Sonatype, Inc.\n+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.\n+ *\n+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,\n+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.\n+ *\n+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. \"Sonatype\" and \"Sonatype Nexus\" are trademarks\n+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the\n+ * Eclipse Foundation. All other trademarks are the property of their respective owners.\n+ */\n+package org.sonatype.nexus.orient;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.List;\n+\n+import org.sonatype.nexus.common.io.DirSupport;\n+\n+import com.google.common.base.Throwables;\n+import com.google.common.collect.Lists;\n+import org.junit.rules.ExternalResource;\n+import org.junit.runners.model.MultipleFailureException;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+import org.slf4j.bridge.SLF4JBridgeHandler;\n+\n+import static com.google.common.base.Preconditions.checkNotNull;\n+import static com.google.common.base.Preconditions.checkState;\n+\n+/**\n+ * JUnit rule to provide a persistent {@link DatabaseInstance} and related components.\n+ *\n+ * @since 3.0\n+ */\n+public class PersistentDatabaseInstanceRule\n+  extends ExternalResource\n+{\n+  static {\n+    try {\n+      SLF4JBridgeHandler.removeHandlersForRootLogger();\n+      SLF4JBridgeHandler.install();\n+    } catch (LinkageError e) {\n+      // no-op, jul-to-slf4j not installed\n+    }\n+  }\n+\n+  private static final Logger log = LoggerFactory.getLogger(PersistentDatabaseInstanceRule.class);\n+\n+  private final String name;\n+\n+  private MinimalDatabaseServer server;\n+\n+  private PersistentDatabaseManager manager;\n+\n+  private DatabaseInstance instance;\n+\n+  public PersistentDatabaseInstanceRule(final String name) {\n+    this.name = checkNotNull(name);\n+  }\n+\n+  public MinimalDatabaseServer getServer() {\n+    checkState(server != null);\n+    return server;\n+  }\n+\n+  public DatabaseManager getManager() {\n+    checkState(manager != null);\n+    return manager;\n+  }\n+\n+  public DatabaseInstance getInstance() {\n+    checkState(instance != null);\n+    return instance;\n+  }\n+\n+  @Override\n+  protected void before() throws Throwable {\n+    log.info(\"Preparing database instance: {}\", name);\n+\n+    server = new MinimalDatabaseServer();\n+    server.start();\n+\n+    manager = new PersistentDatabaseManager();\n+    manager.start();\n+\n+    instance = manager.instance(name);\n+\n+    log.info(\"Database instance prepared\");\n+  }\n+\n+  @Override\n+  protected void after() {\n+    log.info(\"Cleaning up database instance: {}\", name);\n+\n+    instance = null;\n+\n+    // capture any errors so we can propagate to test harness\n+    List<Throwable> errors = Lists.newArrayListWithCapacity(2);\n+\n+    if (manager != null) {\n+      try {\n+        manager.stop();\n+      }\n+      catch (Exception e) {\n+        log.error(\"Failed to stop database manager\", e);\n+        errors.add(e);\n+      }\n+      manager = null;\n+    }\n+\n+    if (server != null) {\n+      try {\n+        server.stop();\n+      }\n+      catch (Exception e) {\n+        log.error(\"Failed to stop database server\", e);\n+        errors.add(e);\n+      }\n+      server = null;\n+    }\n+\n+    if (!errors.isEmpty()) {\n+      log.error(\"Failed to clean up database instance\");\n+      throw Throwables.propagate(new MultipleFailureException(errors));\n+    }\n+\n+    log.info(\"Database instance cleaned up\");\n+  }\n+\n+  class PersistentDatabaseManager\n+      extends DatabaseManagerSupport {\n+\n+    private final File databasesDirectory;\n+\n+    PersistentDatabaseManager() {\n+      File targetDir = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile()).getParentFile();","path":"components/nexus-orient/src/main/java/org/sonatype/nexus/orient/PersistentDatabaseInstanceRule.java","position":138,"original_position":138,"commit_id":"ad17babfdff7caaae68621d5b061eef7376621ab","original_commit_id":"ad17babfdff7caaae68621d5b061eef7376621ab","user":{"login":"kellyrob99","id":76356,"avatar_url":"https://avatars.githubusercontent.com/u/76356?v=3","gravatar_id":"","url":"https://api.github.com/users/kellyrob99","html_url":"https://github.com/kellyrob99","followers_url":"https://api.github.com/users/kellyrob99/followers","following_url":"https://api.github.com/users/kellyrob99/following{/other_user}","gists_url":"https://api.github.com/users/kellyrob99/gists{/gist_id}","starred_url":"https://api.github.com/users/kellyrob99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kellyrob99/subscriptions","organizations_url":"https://api.github.com/users/kellyrob99/orgs","repos_url":"https://api.github.com/users/kellyrob99/repos","events_url":"https://api.github.com/users/kellyrob99/events{/privacy}","received_events_url":"https://api.github.com/users/kellyrob99/received_events","type":"User","site_admin":false},"body":"probably can avoid all this and use TemporaryFolder, unless there's a compelling reason to keep the file system around after the test exits","created_at":"2015-03-30T16:23:57Z","updated_at":"2015-03-30T16:23:57Z","html_url":"https://github.com/sonatype/nexus-oss/pull/1142#discussion_r27405725","pull_request_url":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142","_links":{"self":{"href":"https://api.github.com/repos/sonatype/nexus-oss/pulls/comments/27405725"},"html":{"href":"https://github.com/sonatype/nexus-oss/pull/1142#discussion_r27405725"},"pull_request":{"href":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142"}}},"pull_request":{"url":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142","id":31988007,"html_url":"https://github.com/sonatype/nexus-oss/pull/1142","diff_url":"https://github.com/sonatype/nexus-oss/pull/1142.diff","patch_url":"https://github.com/sonatype/nexus-oss/pull/1142.patch","issue_url":"https://api.github.com/repos/sonatype/nexus-oss/issues/1142","number":1142,"state":"open","locked":false,"title":"Add tests to understand orient's concurrent modification behavior","user":{"login":"cwilper","id":118935,"avatar_url":"https://avatars.githubusercontent.com/u/118935?v=3","gravatar_id":"","url":"https://api.github.com/users/cwilper","html_url":"https://github.com/cwilper","followers_url":"https://api.github.com/users/cwilper/followers","following_url":"https://api.github.com/users/cwilper/following{/other_user}","gists_url":"https://api.github.com/users/cwilper/gists{/gist_id}","starred_url":"https://api.github.com/users/cwilper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cwilper/subscriptions","organizations_url":"https://api.github.com/users/cwilper/orgs","repos_url":"https://api.github.com/users/cwilper/repos","events_url":"https://api.github.com/users/cwilper/events{/privacy}","received_events_url":"https://api.github.com/users/cwilper/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-26T04:07:38Z","updated_at":"2015-03-30T16:23:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9f4784fa1fa22a9a3487297514cb424a512dc59","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142/commits","review_comments_url":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142/comments","review_comment_url":"https://api.github.com/repos/sonatype/nexus-oss/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sonatype/nexus-oss/issues/1142/comments","statuses_url":"https://api.github.com/repos/sonatype/nexus-oss/statuses/ad17babfdff7caaae68621d5b061eef7376621ab","head":{"label":"sonatype:orient-longtx","ref":"orient-longtx","sha":"ad17babfdff7caaae68621d5b061eef7376621ab","user":{"login":"sonatype","id":44938,"avatar_url":"https://avatars.githubusercontent.com/u/44938?v=3","gravatar_id":"","url":"https://api.github.com/users/sonatype","html_url":"https://github.com/sonatype","followers_url":"https://api.github.com/users/sonatype/followers","following_url":"https://api.github.com/users/sonatype/following{/other_user}","gists_url":"https://api.github.com/users/sonatype/gists{/gist_id}","starred_url":"https://api.github.com/users/sonatype/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonatype/subscriptions","organizations_url":"https://api.github.com/users/sonatype/orgs","repos_url":"https://api.github.com/users/sonatype/repos","events_url":"https://api.github.com/users/sonatype/events{/privacy}","received_events_url":"https://api.github.com/users/sonatype/received_events","type":"Organization","site_admin":false},"repo":{"id":10146961,"name":"nexus-oss","full_name":"sonatype/nexus-oss","owner":{"login":"sonatype","id":44938,"avatar_url":"https://avatars.githubusercontent.com/u/44938?v=3","gravatar_id":"","url":"https://api.github.com/users/sonatype","html_url":"https://github.com/sonatype","followers_url":"https://api.github.com/users/sonatype/followers","following_url":"https://api.github.com/users/sonatype/following{/other_user}","gists_url":"https://api.github.com/users/sonatype/gists{/gist_id}","starred_url":"https://api.github.com/users/sonatype/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonatype/subscriptions","organizations_url":"https://api.github.com/users/sonatype/orgs","repos_url":"https://api.github.com/users/sonatype/repos","events_url":"https://api.github.com/users/sonatype/events{/privacy}","received_events_url":"https://api.github.com/users/sonatype/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sonatype/nexus-oss","description":"Sonatype Nexus OSS","fork":false,"url":"https://api.github.com/repos/sonatype/nexus-oss","forks_url":"https://api.github.com/repos/sonatype/nexus-oss/forks","keys_url":"https://api.github.com/repos/sonatype/nexus-oss/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sonatype/nexus-oss/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sonatype/nexus-oss/teams","hooks_url":"https://api.github.com/repos/sonatype/nexus-oss/hooks","issue_events_url":"https://api.github.com/repos/sonatype/nexus-oss/issues/events{/number}","events_url":"https://api.github.com/repos/sonatype/nexus-oss/events","assignees_url":"https://api.github.com/repos/sonatype/nexus-oss/assignees{/user}","branches_url":"https://api.github.com/repos/sonatype/nexus-oss/branches{/branch}","tags_url":"https://api.github.com/repos/sonatype/nexus-oss/tags","blobs_url":"https://api.github.com/repos/sonatype/nexus-oss/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sonatype/nexus-oss/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sonatype/nexus-oss/git/refs{/sha}","trees_url":"https://api.github.com/repos/sonatype/nexus-oss/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sonatype/nexus-oss/statuses/{sha}","languages_url":"https://api.github.com/repos/sonatype/nexus-oss/languages","stargazers_url":"https://api.github.com/repos/sonatype/nexus-oss/stargazers","contributors_url":"https://api.github.com/repos/sonatype/nexus-oss/contributors","subscribers_url":"https://api.github.com/repos/sonatype/nexus-oss/subscribers","subscription_url":"https://api.github.com/repos/sonatype/nexus-oss/subscription","commits_url":"https://api.github.com/repos/sonatype/nexus-oss/commits{/sha}","git_commits_url":"https://api.github.com/repos/sonatype/nexus-oss/git/commits{/sha}","comments_url":"https://api.github.com/repos/sonatype/nexus-oss/comments{/number}","issue_comment_url":"https://api.github.com/repos/sonatype/nexus-oss/issues/comments{/number}","contents_url":"https://api.github.com/repos/sonatype/nexus-oss/contents/{+path}","compare_url":"https://api.github.com/repos/sonatype/nexus-oss/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sonatype/nexus-oss/merges","archive_url":"https://api.github.com/repos/sonatype/nexus-oss/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sonatype/nexus-oss/downloads","issues_url":"https://api.github.com/repos/sonatype/nexus-oss/issues{/number}","pulls_url":"https://api.github.com/repos/sonatype/nexus-oss/pulls{/number}","milestones_url":"https://api.github.com/repos/sonatype/nexus-oss/milestones{/number}","notifications_url":"https://api.github.com/repos/sonatype/nexus-oss/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sonatype/nexus-oss/labels{/name}","releases_url":"https://api.github.com/repos/sonatype/nexus-oss/releases{/id}","created_at":"2013-05-18T20:48:57Z","updated_at":"2015-03-29T23:12:36Z","pushed_at":"2015-03-30T13:39:39Z","git_url":"git://github.com/sonatype/nexus-oss.git","ssh_url":"git@github.com:sonatype/nexus-oss.git","clone_url":"https://github.com/sonatype/nexus-oss.git","svn_url":"https://github.com/sonatype/nexus-oss","homepage":"http://links.sonatype.com/products/nexus/oss/home","size":881004,"stargazers_count":140,"watchers_count":140,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":88,"mirror_url":null,"open_issues_count":10,"forks":88,"open_issues":10,"watchers":140,"default_branch":"master"}},"base":{"label":"sonatype:master","ref":"master","sha":"9a0c108d52cba521c92bba7983d5afce3ae18da9","user":{"login":"sonatype","id":44938,"avatar_url":"https://avatars.githubusercontent.com/u/44938?v=3","gravatar_id":"","url":"https://api.github.com/users/sonatype","html_url":"https://github.com/sonatype","followers_url":"https://api.github.com/users/sonatype/followers","following_url":"https://api.github.com/users/sonatype/following{/other_user}","gists_url":"https://api.github.com/users/sonatype/gists{/gist_id}","starred_url":"https://api.github.com/users/sonatype/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonatype/subscriptions","organizations_url":"https://api.github.com/users/sonatype/orgs","repos_url":"https://api.github.com/users/sonatype/repos","events_url":"https://api.github.com/users/sonatype/events{/privacy}","received_events_url":"https://api.github.com/users/sonatype/received_events","type":"Organization","site_admin":false},"repo":{"id":10146961,"name":"nexus-oss","full_name":"sonatype/nexus-oss","owner":{"login":"sonatype","id":44938,"avatar_url":"https://avatars.githubusercontent.com/u/44938?v=3","gravatar_id":"","url":"https://api.github.com/users/sonatype","html_url":"https://github.com/sonatype","followers_url":"https://api.github.com/users/sonatype/followers","following_url":"https://api.github.com/users/sonatype/following{/other_user}","gists_url":"https://api.github.com/users/sonatype/gists{/gist_id}","starred_url":"https://api.github.com/users/sonatype/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonatype/subscriptions","organizations_url":"https://api.github.com/users/sonatype/orgs","repos_url":"https://api.github.com/users/sonatype/repos","events_url":"https://api.github.com/users/sonatype/events{/privacy}","received_events_url":"https://api.github.com/users/sonatype/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sonatype/nexus-oss","description":"Sonatype Nexus OSS","fork":false,"url":"https://api.github.com/repos/sonatype/nexus-oss","forks_url":"https://api.github.com/repos/sonatype/nexus-oss/forks","keys_url":"https://api.github.com/repos/sonatype/nexus-oss/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sonatype/nexus-oss/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sonatype/nexus-oss/teams","hooks_url":"https://api.github.com/repos/sonatype/nexus-oss/hooks","issue_events_url":"https://api.github.com/repos/sonatype/nexus-oss/issues/events{/number}","events_url":"https://api.github.com/repos/sonatype/nexus-oss/events","assignees_url":"https://api.github.com/repos/sonatype/nexus-oss/assignees{/user}","branches_url":"https://api.github.com/repos/sonatype/nexus-oss/branches{/branch}","tags_url":"https://api.github.com/repos/sonatype/nexus-oss/tags","blobs_url":"https://api.github.com/repos/sonatype/nexus-oss/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sonatype/nexus-oss/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sonatype/nexus-oss/git/refs{/sha}","trees_url":"https://api.github.com/repos/sonatype/nexus-oss/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sonatype/nexus-oss/statuses/{sha}","languages_url":"https://api.github.com/repos/sonatype/nexus-oss/languages","stargazers_url":"https://api.github.com/repos/sonatype/nexus-oss/stargazers","contributors_url":"https://api.github.com/repos/sonatype/nexus-oss/contributors","subscribers_url":"https://api.github.com/repos/sonatype/nexus-oss/subscribers","subscription_url":"https://api.github.com/repos/sonatype/nexus-oss/subscription","commits_url":"https://api.github.com/repos/sonatype/nexus-oss/commits{/sha}","git_commits_url":"https://api.github.com/repos/sonatype/nexus-oss/git/commits{/sha}","comments_url":"https://api.github.com/repos/sonatype/nexus-oss/comments{/number}","issue_comment_url":"https://api.github.com/repos/sonatype/nexus-oss/issues/comments{/number}","contents_url":"https://api.github.com/repos/sonatype/nexus-oss/contents/{+path}","compare_url":"https://api.github.com/repos/sonatype/nexus-oss/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sonatype/nexus-oss/merges","archive_url":"https://api.github.com/repos/sonatype/nexus-oss/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sonatype/nexus-oss/downloads","issues_url":"https://api.github.com/repos/sonatype/nexus-oss/issues{/number}","pulls_url":"https://api.github.com/repos/sonatype/nexus-oss/pulls{/number}","milestones_url":"https://api.github.com/repos/sonatype/nexus-oss/milestones{/number}","notifications_url":"https://api.github.com/repos/sonatype/nexus-oss/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sonatype/nexus-oss/labels{/name}","releases_url":"https://api.github.com/repos/sonatype/nexus-oss/releases{/id}","created_at":"2013-05-18T20:48:57Z","updated_at":"2015-03-29T23:12:36Z","pushed_at":"2015-03-30T13:39:39Z","git_url":"git://github.com/sonatype/nexus-oss.git","ssh_url":"git@github.com:sonatype/nexus-oss.git","clone_url":"https://github.com/sonatype/nexus-oss.git","svn_url":"https://github.com/sonatype/nexus-oss","homepage":"http://links.sonatype.com/products/nexus/oss/home","size":881004,"stargazers_count":140,"watchers_count":140,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":88,"mirror_url":null,"open_issues_count":10,"forks":88,"open_issues":10,"watchers":140,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142"},"html":{"href":"https://github.com/sonatype/nexus-oss/pull/1142"},"issue":{"href":"https://api.github.com/repos/sonatype/nexus-oss/issues/1142"},"comments":{"href":"https://api.github.com/repos/sonatype/nexus-oss/issues/1142/comments"},"review_comments":{"href":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142/comments"},"review_comment":{"href":"https://api.github.com/repos/sonatype/nexus-oss/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sonatype/nexus-oss/pulls/1142/commits"},"statuses":{"href":"https://api.github.com/repos/sonatype/nexus-oss/statuses/ad17babfdff7caaae68621d5b061eef7376621ab"}}}}