{"action":"created","comment":{"url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/comments/91069384","pull_request_review_id":11574716,"id":91069384,"diff_hunk":"@@ -0,0 +1,98 @@\n+package de.braintags.io.vertx.util.asyncLock;\r\n+\r\n+import java.util.ArrayList;\r\n+import java.util.concurrent.ExecutorService;\r\n+import java.util.concurrent.Executors;\r\n+\r\n+import org.junit.Test;\r\n+import org.junit.runner.RunWith;\r\n+\r\n+import de.braintags.io.vertx.util.asyncLock.AsyncReadWriteLock;\r\n+import io.vertx.ext.unit.TestContext;\r\n+import io.vertx.ext.unit.junit.VertxUnitRunner;\r\n+\r\n+@RunWith(VertxUnitRunner.class)\r\n+public class AsyncReadWriteLockTest {\r\n+\r\n+  @Test\r\n+  public void simpleTest(TestContext context) {\r\n+    AsyncReadWriteLock lock = new AsyncReadWriteLock();\r\n+    ArrayList<Integer> result = new ArrayList<>();\r\n+\r\n+    int threadCount = 0;\r\n+\r\n+    ExecutorService es = Executors.newFixedThreadPool(3);\r\n+    threadCount += executeLockLevel(lock, 5, 0, true, result, es, false, false);\r\n+    threadCount += executeLockLevel(lock, 1, 1, false, result, es, false, false);\r\n+    threadCount += executeLockLevel(lock, 10, 2, true, result, es, false, false);\r\n+    threadCount += executeLockLevel(lock, 1, 3, false, result, es, true, true);\r\n+    threadCount += executeLockLevel(lock, 1, 4, false, result, es, false, true);\r\n+    threadCount += executeLockLevel(lock, 1, 5, false, result, es, false, true);\r\n+    threadCount += executeLockLevel(lock, 3, 6, true, result, es, true, false);\r\n+    threadCount += executeLockLevel(lock, 3, 7, true, result, es, false, true);\r\n+\r\n+    for (int tryCount = 0; tryCount < 100 && result.size() < threadCount; tryCount++) {\r\n+      try {\r\n+        Thread.sleep(100);\r\n+      } catch (InterruptedException e) {\r\n+        e.printStackTrace();\r\n+      }\r\n+    }\r\n+\r\n+    context.assertEquals(result.size(), threadCount);\r\n+\r\n+    int current = -1;\r\n+    for (int i = 0; i < result.size(); i++) {\r\n+      Integer v = result.get(i);\r\n+      context.assertTrue(current <= v);\r\n+      current = v;\r\n+    }\r\n+  }\r\n+\r\n+  /**\r\n+   * Executes count threads on lock in with read or write lock. Each thread adds the level to the result list.\r\n+   * Threads are executed on the executor service es and can simulate an exception or illegal behaviour calling\r\n+   * the finish handler twice.\r\n+   * @param lock\r\n+   * @param count\r\n+   * @param level\r\n+   * @param readLock\r\n+   * @param resultList\r\n+   * @param es\r\n+   * @param simulateException\r\n+   * @param simulateIllegalHandler\r\n+   * @return\r\n+   */\r\n+  protected int executeLockLevel(AsyncReadWriteLock lock, int count, int level, boolean readLock,\r\n+      ArrayList<Integer> resultList, ExecutorService es, boolean simulateException, boolean simulateIllegalHandler) {\r\n+    for (int i = 0; i < count; i++) {\r\n+      lock.execute(readLock, handler -> {\r\n+        Runnable runnable = () -> {\r\n+          try {\r\n+            Thread.sleep((int) (Math.random() * 30));\r\n+          } catch (InterruptedException e) {\r\n+            e.printStackTrace();\r\n+          }\r\n+          synchronized (resultList) {\r\n+            resultList.add(level);\r\n+          }\r\n+          handler.run();\r\n+          if (simulateIllegalHandler) {\r\n+            handler.run();\r\n+          }\r\n+        };\r\n+        if (simulateException) {\r\n+          throw new RuntimeException(\"test execption in worker\");\r\n+        }\r\n+\r\n+        es.submit(runnable);\r","path":"src/test/java/de/braintags/io/vertx/util/asyncLock/AsyncReadWriteLockTest.java","position":null,"original_position":88,"commit_id":"b5c2ec7010d3bcbde92f2ed150f5b9c24881a8ba","original_commit_id":"711289f652301670c58dfa5653a64d850b5d9435","user":{"login":"remi128","id":9085425,"avatar_url":"https://avatars.githubusercontent.com/u/9085425?v=3","gravatar_id":"","url":"https://api.github.com/users/remi128","html_url":"https://github.com/remi128","followers_url":"https://api.github.com/users/remi128/followers","following_url":"https://api.github.com/users/remi128/following{/other_user}","gists_url":"https://api.github.com/users/remi128/gists{/gist_id}","starred_url":"https://api.github.com/users/remi128/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remi128/subscriptions","organizations_url":"https://api.github.com/users/remi128/orgs","repos_url":"https://api.github.com/users/remi128/repos","events_url":"https://api.github.com/users/remi128/events{/privacy}","received_events_url":"https://api.github.com/users/remi128/received_events","type":"User","site_admin":false},"body":"The future is not used anymore? Does the use of this future clash with the vertx future?","created_at":"2016-12-06T12:39:46Z","updated_at":"2016-12-06T12:43:49Z","html_url":"https://github.com/BraintagsGmbH/vertx-util/pull/4#discussion_r91069384","pull_request_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/comments/91069384"},"html":{"href":"https://github.com/BraintagsGmbH/vertx-util/pull/4#discussion_r91069384"},"pull_request":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4","id":96568876,"html_url":"https://github.com/BraintagsGmbH/vertx-util/pull/4","diff_url":"https://github.com/BraintagsGmbH/vertx-util/pull/4.diff","patch_url":"https://github.com/BraintagsGmbH/vertx-util/pull/4.patch","issue_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/4","number":4,"state":"open","locked":false,"title":"Feature/async lock","user":{"login":"mpluecker","id":23695489,"avatar_url":"https://avatars.githubusercontent.com/u/23695489?v=3","gravatar_id":"","url":"https://api.github.com/users/mpluecker","html_url":"https://github.com/mpluecker","followers_url":"https://api.github.com/users/mpluecker/followers","following_url":"https://api.github.com/users/mpluecker/following{/other_user}","gists_url":"https://api.github.com/users/mpluecker/gists{/gist_id}","starred_url":"https://api.github.com/users/mpluecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpluecker/subscriptions","organizations_url":"https://api.github.com/users/mpluecker/orgs","repos_url":"https://api.github.com/users/mpluecker/repos","events_url":"https://api.github.com/users/mpluecker/events{/privacy}","received_events_url":"https://api.github.com/users/mpluecker/received_events","type":"User","site_admin":false},"body":"As this is dark magic, please review this carefully.","created_at":"2016-12-05T17:04:38Z","updated_at":"2016-12-06T12:43:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d876d027b19bf2c6170e2f5895dbf3b2f129c546","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4/commits","review_comments_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4/comments","review_comment_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/comments{/number}","comments_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/4/comments","statuses_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/statuses/b5c2ec7010d3bcbde92f2ed150f5b9c24881a8ba","head":{"label":"BraintagsGmbH:feature/asyncLock","ref":"feature/asyncLock","sha":"b5c2ec7010d3bcbde92f2ed150f5b9c24881a8ba","user":{"login":"BraintagsGmbH","id":14057560,"avatar_url":"https://avatars.githubusercontent.com/u/14057560?v=3","gravatar_id":"","url":"https://api.github.com/users/BraintagsGmbH","html_url":"https://github.com/BraintagsGmbH","followers_url":"https://api.github.com/users/BraintagsGmbH/followers","following_url":"https://api.github.com/users/BraintagsGmbH/following{/other_user}","gists_url":"https://api.github.com/users/BraintagsGmbH/gists{/gist_id}","starred_url":"https://api.github.com/users/BraintagsGmbH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BraintagsGmbH/subscriptions","organizations_url":"https://api.github.com/users/BraintagsGmbH/orgs","repos_url":"https://api.github.com/users/BraintagsGmbH/repos","events_url":"https://api.github.com/users/BraintagsGmbH/events{/privacy}","received_events_url":"https://api.github.com/users/BraintagsGmbH/received_events","type":"Organization","site_admin":false},"repo":{"id":50125822,"name":"vertx-util","full_name":"BraintagsGmbH/vertx-util","owner":{"login":"BraintagsGmbH","id":14057560,"avatar_url":"https://avatars.githubusercontent.com/u/14057560?v=3","gravatar_id":"","url":"https://api.github.com/users/BraintagsGmbH","html_url":"https://github.com/BraintagsGmbH","followers_url":"https://api.github.com/users/BraintagsGmbH/followers","following_url":"https://api.github.com/users/BraintagsGmbH/following{/other_user}","gists_url":"https://api.github.com/users/BraintagsGmbH/gists{/gist_id}","starred_url":"https://api.github.com/users/BraintagsGmbH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BraintagsGmbH/subscriptions","organizations_url":"https://api.github.com/users/BraintagsGmbH/orgs","repos_url":"https://api.github.com/users/BraintagsGmbH/repos","events_url":"https://api.github.com/users/BraintagsGmbH/events{/privacy}","received_events_url":"https://api.github.com/users/BraintagsGmbH/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BraintagsGmbH/vertx-util","description":null,"fork":false,"url":"https://api.github.com/repos/BraintagsGmbH/vertx-util","forks_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/forks","keys_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/teams","hooks_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/hooks","issue_events_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/events{/number}","events_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/events","assignees_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/assignees{/user}","branches_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/branches{/branch}","tags_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/tags","blobs_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/refs{/sha}","trees_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/statuses/{sha}","languages_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/languages","stargazers_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/stargazers","contributors_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/contributors","subscribers_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/subscribers","subscription_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/subscription","commits_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/commits{/sha}","git_commits_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/commits{/sha}","comments_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/comments{/number}","issue_comment_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/comments{/number}","contents_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/contents/{+path}","compare_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/merges","archive_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/downloads","issues_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues{/number}","pulls_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls{/number}","milestones_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/milestones{/number}","notifications_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/labels{/name}","releases_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/releases{/id}","deployments_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/deployments","created_at":"2016-01-21T17:55:12Z","updated_at":"2016-01-22T11:46:59Z","pushed_at":"2016-12-05T17:04:38Z","git_url":"git://github.com/BraintagsGmbH/vertx-util.git","ssh_url":"git@github.com:BraintagsGmbH/vertx-util.git","clone_url":"https://github.com/BraintagsGmbH/vertx-util.git","svn_url":"https://github.com/BraintagsGmbH/vertx-util","homepage":null,"size":116,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"BraintagsGmbH:master","ref":"master","sha":"b557c20e33d9cdbfa0aec28a4f667b0a8ca8f665","user":{"login":"BraintagsGmbH","id":14057560,"avatar_url":"https://avatars.githubusercontent.com/u/14057560?v=3","gravatar_id":"","url":"https://api.github.com/users/BraintagsGmbH","html_url":"https://github.com/BraintagsGmbH","followers_url":"https://api.github.com/users/BraintagsGmbH/followers","following_url":"https://api.github.com/users/BraintagsGmbH/following{/other_user}","gists_url":"https://api.github.com/users/BraintagsGmbH/gists{/gist_id}","starred_url":"https://api.github.com/users/BraintagsGmbH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BraintagsGmbH/subscriptions","organizations_url":"https://api.github.com/users/BraintagsGmbH/orgs","repos_url":"https://api.github.com/users/BraintagsGmbH/repos","events_url":"https://api.github.com/users/BraintagsGmbH/events{/privacy}","received_events_url":"https://api.github.com/users/BraintagsGmbH/received_events","type":"Organization","site_admin":false},"repo":{"id":50125822,"name":"vertx-util","full_name":"BraintagsGmbH/vertx-util","owner":{"login":"BraintagsGmbH","id":14057560,"avatar_url":"https://avatars.githubusercontent.com/u/14057560?v=3","gravatar_id":"","url":"https://api.github.com/users/BraintagsGmbH","html_url":"https://github.com/BraintagsGmbH","followers_url":"https://api.github.com/users/BraintagsGmbH/followers","following_url":"https://api.github.com/users/BraintagsGmbH/following{/other_user}","gists_url":"https://api.github.com/users/BraintagsGmbH/gists{/gist_id}","starred_url":"https://api.github.com/users/BraintagsGmbH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BraintagsGmbH/subscriptions","organizations_url":"https://api.github.com/users/BraintagsGmbH/orgs","repos_url":"https://api.github.com/users/BraintagsGmbH/repos","events_url":"https://api.github.com/users/BraintagsGmbH/events{/privacy}","received_events_url":"https://api.github.com/users/BraintagsGmbH/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BraintagsGmbH/vertx-util","description":null,"fork":false,"url":"https://api.github.com/repos/BraintagsGmbH/vertx-util","forks_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/forks","keys_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/teams","hooks_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/hooks","issue_events_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/events{/number}","events_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/events","assignees_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/assignees{/user}","branches_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/branches{/branch}","tags_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/tags","blobs_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/refs{/sha}","trees_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/statuses/{sha}","languages_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/languages","stargazers_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/stargazers","contributors_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/contributors","subscribers_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/subscribers","subscription_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/subscription","commits_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/commits{/sha}","git_commits_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/git/commits{/sha}","comments_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/comments{/number}","issue_comment_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/comments{/number}","contents_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/contents/{+path}","compare_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/merges","archive_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/downloads","issues_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues{/number}","pulls_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls{/number}","milestones_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/milestones{/number}","notifications_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/labels{/name}","releases_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/releases{/id}","deployments_url":"https://api.github.com/repos/BraintagsGmbH/vertx-util/deployments","created_at":"2016-01-21T17:55:12Z","updated_at":"2016-01-22T11:46:59Z","pushed_at":"2016-12-05T17:04:38Z","git_url":"git://github.com/BraintagsGmbH/vertx-util.git","ssh_url":"git@github.com:BraintagsGmbH/vertx-util.git","clone_url":"https://github.com/BraintagsGmbH/vertx-util.git","svn_url":"https://github.com/BraintagsGmbH/vertx-util","homepage":null,"size":116,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4"},"html":{"href":"https://github.com/BraintagsGmbH/vertx-util/pull/4"},"issue":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/4"},"comments":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/BraintagsGmbH/vertx-util/statuses/b5c2ec7010d3bcbde92f2ed150f5b9c24881a8ba"}}}}
{"actor":{"display_login":"remi128"}}