{"action":"created","comment":{"url":"https://api.github.com/repos/amplab/tachyon/pulls/comments/36908880","id":36908880,"diff_hunk":"@@ -0,0 +1,303 @@\n+/*\n+ * Licensed to the University of California, Berkeley under one or more contributor license\n+ * agreements. See the NOTICE file distributed with this work for additional information regarding\n+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance with the License. You may obtain a\n+ * copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software distributed under the License\n+ * is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\n+ * or implied. See the License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+\n+package tachyon.worker.block;\n+\n+import java.io.File;\n+import java.lang.reflect.Field;\n+\n+import org.junit.Assert;\n+import org.junit.Before;\n+import org.junit.Rule;\n+import org.junit.Test;\n+import org.junit.rules.ExpectedException;\n+import org.junit.rules.TemporaryFolder;\n+\n+import com.google.common.collect.Sets;\n+\n+import tachyon.StorageLevelAlias;\n+import tachyon.conf.TachyonConf;\n+import tachyon.exception.NotFoundException;\n+import tachyon.exception.OutOfSpaceException;\n+import tachyon.util.io.FileUtils;\n+import tachyon.worker.WorkerContext;\n+import tachyon.worker.block.evictor.Evictor;\n+import tachyon.worker.block.meta.BlockMeta;\n+import tachyon.worker.block.meta.StorageDir;\n+import tachyon.worker.block.meta.TempBlockMeta;\n+\n+public class TieredBlockStoreTest {\n+  private static final long USER_ID1 = 2;\n+  private static final long USER_ID2 = 3;\n+  private static final long BLOCK_ID1 = 1000;\n+  private static final long BLOCK_ID2 = 1001;\n+  private static final long TEMP_BLOCK_ID = 1003;\n+  private static final long BLOCK_SIZE = 512;\n+  private static final StorageLevelAlias FIRST_TIER_ALIAS = TieredBlockStoreTestUtils.TIER_ALIAS[0];\n+  private TieredBlockStore mBlockStore;\n+  private BlockMetadataManager mMetaManager;\n+  private BlockLockManager mLockManager;\n+  private StorageDir mTestDir1;\n+  private StorageDir mTestDir2;\n+  private Evictor mEvictor;\n+\n+  @Rule\n+  public TemporaryFolder mTestFolder = new TemporaryFolder();\n+\n+  @Rule\n+  public ExpectedException mThrown = ExpectedException.none();\n+\n+  @Before\n+  public void before() throws Exception {\n+    File tempFolder = mTestFolder.newFolder();\n+    TachyonConf testConf =\n+        TieredBlockStoreTestUtils.defaultTachyonConf(tempFolder.getAbsolutePath());\n+    WorkerContext.getConf().merge(testConf);\n+    mBlockStore = new TieredBlockStore();\n+\n+    // TODO: avoid using reflection to get private members.\n+    Field field = mBlockStore.getClass().getDeclaredField(\"mMetaManager\");\n+    field.setAccessible(true);\n+    mMetaManager = (BlockMetadataManager) field.get(mBlockStore);\n+    field = mBlockStore.getClass().getDeclaredField(\"mLockManager\");\n+    field.setAccessible(true);\n+    mLockManager = (BlockLockManager) field.get(mBlockStore);\n+    field = mBlockStore.getClass().getDeclaredField(\"mEvictor\");\n+    field.setAccessible(true);\n+    mEvictor = (Evictor) field.get(mBlockStore);\n+\n+    mTestDir1 = mMetaManager.getTier(FIRST_TIER_ALIAS.getValue()).getDir(0);\n+    mTestDir2 = mMetaManager.getTier(FIRST_TIER_ALIAS.getValue()).getDir(1);\n+  }\n+\n+  // Different users can concurrently grab block locks on different blocks\n+  @Test\n+  public void differentUserLockDifferentBlocksTest() throws Exception {\n+    TieredBlockStoreTestUtils.cache(USER_ID1, BLOCK_ID1, BLOCK_SIZE, mTestDir1, mMetaManager,\n+        mEvictor);\n+    TieredBlockStoreTestUtils.cache(USER_ID2, BLOCK_ID2, BLOCK_SIZE, mTestDir2, mMetaManager,\n+        mEvictor);\n+\n+    long lockId1 = mBlockStore.lockBlock(USER_ID1, BLOCK_ID1);\n+    Assert.assertTrue(Sets.difference(mLockManager.getLockedBlocks(), Sets.newHashSet(BLOCK_ID1))\n+        .isEmpty());\n+\n+    long lockId2 = mBlockStore.lockBlock(USER_ID2, BLOCK_ID2);\n+    Assert.assertNotEquals(lockId1, lockId2);\n+    Assert.assertTrue(Sets.difference(mLockManager.getLockedBlocks(),\n+        Sets.newHashSet(BLOCK_ID1, BLOCK_ID2)).isEmpty());\n+\n+    mBlockStore.unlockBlock(lockId2);\n+    Assert.assertTrue(Sets.difference(mLockManager.getLockedBlocks(), Sets.newHashSet(BLOCK_ID1))\n+        .isEmpty());\n+\n+    mBlockStore.unlockBlock(lockId1);\n+    Assert.assertTrue(mLockManager.getLockedBlocks().isEmpty());\n+  }\n+\n+  // Same user can concurrently grab block locks on different block\n+  @Test\n+  public void sameUserLockDifferentBlocksTest() throws Exception {\n+    TieredBlockStoreTestUtils.cache(USER_ID1, BLOCK_ID1, BLOCK_SIZE, mTestDir1, mMetaManager,\n+        mEvictor);\n+    TieredBlockStoreTestUtils.cache(USER_ID1, BLOCK_ID2, BLOCK_SIZE, mTestDir2, mMetaManager,\n+        mEvictor);\n+\n+    long lockId1 = mBlockStore.lockBlock(USER_ID1, BLOCK_ID1);\n+    Assert.assertTrue(Sets.difference(mLockManager.getLockedBlocks(), Sets.newHashSet(BLOCK_ID1))\n+        .isEmpty());\n+\n+    long lockId2 = mBlockStore.lockBlock(USER_ID1, BLOCK_ID2);\n+    Assert.assertNotEquals(lockId1, lockId2);\n+  }\n+\n+  @Test\n+  public void lockNonExistingBlockTest() throws Exception {\n+    mThrown.expect(NotFoundException.class);\n+    mThrown.expectMessage(\"Failed to lockBlock: no blockId \" + BLOCK_ID1 + \" found\");\n+\n+    mBlockStore.lockBlock(USER_ID1, BLOCK_ID1);\n+    Assert.assertTrue(mLockManager.getLockedBlocks().isEmpty());\n+  }\n+\n+  @Test\n+  public void unlockNonExistingLockTest() throws Exception {\n+    long badLockId = 1003;\n+    mThrown.expect(NotFoundException.class);\n+    mThrown.expectMessage(\"Failed to unlockBlock: lockId \" + badLockId + \" has no lock record\");\n+\n+    mBlockStore.unlockBlock(badLockId);\n+  }\n+\n+  @Test\n+  public void commitBlockTest() throws Exception {\n+    TieredBlockStoreTestUtils.createTempBlock(USER_ID1, TEMP_BLOCK_ID, BLOCK_SIZE, mTestDir1\n+    );\n+    Assert.assertFalse(mBlockStore.hasBlockMeta(TEMP_BLOCK_ID));\n+    mBlockStore.commitBlock(USER_ID1, TEMP_BLOCK_ID);\n+    Assert.assertTrue(mBlockStore.hasBlockMeta(TEMP_BLOCK_ID));\n+    Assert\n+        .assertFalse(FileUtils.exists(TempBlockMeta.tempPath(mTestDir1, USER_ID1, TEMP_BLOCK_ID)));\n+    Assert.assertTrue(FileUtils.exists(TempBlockMeta.commitPath(mTestDir1, TEMP_BLOCK_ID)));\n+  }\n+\n+  @Test\n+  public void abortBlockTest() throws Exception {\n+    TieredBlockStoreTestUtils.createTempBlock(USER_ID1, TEMP_BLOCK_ID, BLOCK_SIZE, mTestDir1\n+    );","path":"servers/src/test/java/tachyon/worker/block/TieredBlockStoreTest.java","position":null,"original_position":159,"commit_id":"5f5df2e5cadd2dc634a4d5cb323471d5076ce388","original_commit_id":"9cc1477ca66b43f39ab0b495375678fcecedf4ee","user":{"login":"apc999","id":1413748,"avatar_url":"https://avatars.githubusercontent.com/u/1413748?v=3","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2015-08-12T20:22:52Z","updated_at":"2015-08-12T20:22:52Z","html_url":"https://github.com/amplab/tachyon/pull/1271#discussion_r36908880","pull_request_url":"https://api.github.com/repos/amplab/tachyon/pulls/1271","_links":{"self":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/comments/36908880"},"html":{"href":"https://github.com/amplab/tachyon/pull/1271#discussion_r36908880"},"pull_request":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1271"}}},"pull_request":{"url":"https://api.github.com/repos/amplab/tachyon/pulls/1271","id":42046365,"html_url":"https://github.com/amplab/tachyon/pull/1271","diff_url":"https://github.com/amplab/tachyon/pull/1271.diff","patch_url":"https://github.com/amplab/tachyon/pull/1271.patch","issue_url":"https://api.github.com/repos/amplab/tachyon/issues/1271","number":1271,"state":"open","locked":false,"title":"[TACHYON-695] Followup PR to add unit tests of TieredBlockStore","user":{"login":"apc999","id":1413748,"avatar_url":"https://avatars.githubusercontent.com/u/1413748?v=3","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false},"body":"JIRA: https://tachyon.atlassian.net/browse/TACHYON-695\r\n\r\nThis PR adds unit tests to TieredBlockStore","created_at":"2015-08-10T17:47:12Z","updated_at":"2015-08-12T20:22:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6269a128c2e9864c758e80b52b36aa6a57cefd45","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amplab/tachyon/pulls/1271/commits","review_comments_url":"https://api.github.com/repos/amplab/tachyon/pulls/1271/comments","review_comment_url":"https://api.github.com/repos/amplab/tachyon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amplab/tachyon/issues/1271/comments","statuses_url":"https://api.github.com/repos/amplab/tachyon/statuses/5f5df2e5cadd2dc634a4d5cb323471d5076ce388","head":{"label":"apc999:unittest","ref":"unittest","sha":"5f5df2e5cadd2dc634a4d5cb323471d5076ce388","user":{"login":"apc999","id":1413748,"avatar_url":"https://avatars.githubusercontent.com/u/1413748?v=3","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false},"repo":{"id":32042306,"name":"tachyon","full_name":"apc999/tachyon","owner":{"login":"apc999","id":1413748,"avatar_url":"https://avatars.githubusercontent.com/u/1413748?v=3","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/apc999/tachyon","description":" A Reliable Memory Centric Distributed Storage System","fork":true,"url":"https://api.github.com/repos/apc999/tachyon","forks_url":"https://api.github.com/repos/apc999/tachyon/forks","keys_url":"https://api.github.com/repos/apc999/tachyon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apc999/tachyon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apc999/tachyon/teams","hooks_url":"https://api.github.com/repos/apc999/tachyon/hooks","issue_events_url":"https://api.github.com/repos/apc999/tachyon/issues/events{/number}","events_url":"https://api.github.com/repos/apc999/tachyon/events","assignees_url":"https://api.github.com/repos/apc999/tachyon/assignees{/user}","branches_url":"https://api.github.com/repos/apc999/tachyon/branches{/branch}","tags_url":"https://api.github.com/repos/apc999/tachyon/tags","blobs_url":"https://api.github.com/repos/apc999/tachyon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apc999/tachyon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apc999/tachyon/git/refs{/sha}","trees_url":"https://api.github.com/repos/apc999/tachyon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apc999/tachyon/statuses/{sha}","languages_url":"https://api.github.com/repos/apc999/tachyon/languages","stargazers_url":"https://api.github.com/repos/apc999/tachyon/stargazers","contributors_url":"https://api.github.com/repos/apc999/tachyon/contributors","subscribers_url":"https://api.github.com/repos/apc999/tachyon/subscribers","subscription_url":"https://api.github.com/repos/apc999/tachyon/subscription","commits_url":"https://api.github.com/repos/apc999/tachyon/commits{/sha}","git_commits_url":"https://api.github.com/repos/apc999/tachyon/git/commits{/sha}","comments_url":"https://api.github.com/repos/apc999/tachyon/comments{/number}","issue_comment_url":"https://api.github.com/repos/apc999/tachyon/issues/comments{/number}","contents_url":"https://api.github.com/repos/apc999/tachyon/contents/{+path}","compare_url":"https://api.github.com/repos/apc999/tachyon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apc999/tachyon/merges","archive_url":"https://api.github.com/repos/apc999/tachyon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apc999/tachyon/downloads","issues_url":"https://api.github.com/repos/apc999/tachyon/issues{/number}","pulls_url":"https://api.github.com/repos/apc999/tachyon/pulls{/number}","milestones_url":"https://api.github.com/repos/apc999/tachyon/milestones{/number}","notifications_url":"https://api.github.com/repos/apc999/tachyon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apc999/tachyon/labels{/name}","releases_url":"https://api.github.com/repos/apc999/tachyon/releases{/id}","created_at":"2015-03-11T21:31:13Z","updated_at":"2015-05-12T21:15:01Z","pushed_at":"2015-08-12T20:22:39Z","git_url":"git://github.com/apc999/tachyon.git","ssh_url":"git@github.com:apc999/tachyon.git","clone_url":"https://github.com/apc999/tachyon.git","svn_url":"https://github.com/apc999/tachyon","homepage":"http://tachyon-project.org","size":16359,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"amplab:master","ref":"master","sha":"d48dc96ff3f8e64f517d4e81ad7d005de25dbd4a","user":{"login":"amplab","id":1438454,"avatar_url":"https://avatars.githubusercontent.com/u/1438454?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab","html_url":"https://github.com/amplab","followers_url":"https://api.github.com/users/amplab/followers","following_url":"https://api.github.com/users/amplab/following{/other_user}","gists_url":"https://api.github.com/users/amplab/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab/subscriptions","organizations_url":"https://api.github.com/users/amplab/orgs","repos_url":"https://api.github.com/users/amplab/repos","events_url":"https://api.github.com/users/amplab/events{/privacy}","received_events_url":"https://api.github.com/users/amplab/received_events","type":"Organization","site_admin":false},"repo":{"id":7276954,"name":"tachyon","full_name":"amplab/tachyon","owner":{"login":"amplab","id":1438454,"avatar_url":"https://avatars.githubusercontent.com/u/1438454?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab","html_url":"https://github.com/amplab","followers_url":"https://api.github.com/users/amplab/followers","following_url":"https://api.github.com/users/amplab/following{/other_user}","gists_url":"https://api.github.com/users/amplab/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab/subscriptions","organizations_url":"https://api.github.com/users/amplab/orgs","repos_url":"https://api.github.com/users/amplab/repos","events_url":"https://api.github.com/users/amplab/events{/privacy}","received_events_url":"https://api.github.com/users/amplab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplab/tachyon","description":" A Reliable Memory Centric Distributed Storage System","fork":false,"url":"https://api.github.com/repos/amplab/tachyon","forks_url":"https://api.github.com/repos/amplab/tachyon/forks","keys_url":"https://api.github.com/repos/amplab/tachyon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplab/tachyon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplab/tachyon/teams","hooks_url":"https://api.github.com/repos/amplab/tachyon/hooks","issue_events_url":"https://api.github.com/repos/amplab/tachyon/issues/events{/number}","events_url":"https://api.github.com/repos/amplab/tachyon/events","assignees_url":"https://api.github.com/repos/amplab/tachyon/assignees{/user}","branches_url":"https://api.github.com/repos/amplab/tachyon/branches{/branch}","tags_url":"https://api.github.com/repos/amplab/tachyon/tags","blobs_url":"https://api.github.com/repos/amplab/tachyon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplab/tachyon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplab/tachyon/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplab/tachyon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplab/tachyon/statuses/{sha}","languages_url":"https://api.github.com/repos/amplab/tachyon/languages","stargazers_url":"https://api.github.com/repos/amplab/tachyon/stargazers","contributors_url":"https://api.github.com/repos/amplab/tachyon/contributors","subscribers_url":"https://api.github.com/repos/amplab/tachyon/subscribers","subscription_url":"https://api.github.com/repos/amplab/tachyon/subscription","commits_url":"https://api.github.com/repos/amplab/tachyon/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplab/tachyon/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplab/tachyon/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplab/tachyon/issues/comments{/number}","contents_url":"https://api.github.com/repos/amplab/tachyon/contents/{+path}","compare_url":"https://api.github.com/repos/amplab/tachyon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplab/tachyon/merges","archive_url":"https://api.github.com/repos/amplab/tachyon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplab/tachyon/downloads","issues_url":"https://api.github.com/repos/amplab/tachyon/issues{/number}","pulls_url":"https://api.github.com/repos/amplab/tachyon/pulls{/number}","milestones_url":"https://api.github.com/repos/amplab/tachyon/milestones{/number}","notifications_url":"https://api.github.com/repos/amplab/tachyon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplab/tachyon/labels{/name}","releases_url":"https://api.github.com/repos/amplab/tachyon/releases{/id}","created_at":"2012-12-21T17:43:46Z","updated_at":"2015-08-12T08:19:49Z","pushed_at":"2015-08-12T20:22:39Z","git_url":"git://github.com/amplab/tachyon.git","ssh_url":"git@github.com:amplab/tachyon.git","clone_url":"https://github.com/amplab/tachyon.git","svn_url":"https://github.com/amplab/tachyon","homepage":"http://tachyon-project.org","size":38774,"stargazers_count":1499,"watchers_count":1499,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":576,"mirror_url":null,"open_issues_count":26,"forks":576,"open_issues":26,"watchers":1499,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1271"},"html":{"href":"https://github.com/amplab/tachyon/pull/1271"},"issue":{"href":"https://api.github.com/repos/amplab/tachyon/issues/1271"},"comments":{"href":"https://api.github.com/repos/amplab/tachyon/issues/1271/comments"},"review_comments":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1271/comments"},"review_comment":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amplab/tachyon/pulls/1271/commits"},"statuses":{"href":"https://api.github.com/repos/amplab/tachyon/statuses/5f5df2e5cadd2dc634a4d5cb323471d5076ce388"}}}}