{"action":"created","comment":{"url":"https://api.github.com/repos/zalando/nakadi/pulls/comments/95367570","pull_request_review_id":15919239,"id":95367570,"diff_hunk":"@@ -0,0 +1,148 @@\n+package org.zalando.nakadi.repository.db;\n+\n+import java.util.Date;\n+import java.util.List;\n+import java.util.Optional;\n+import java.util.UUID;\n+import java.util.stream.Collectors;\n+import java.util.stream.LongStream;\n+import org.junit.Assert;\n+import org.junit.Before;\n+import org.junit.Test;\n+import org.springframework.dao.DuplicateKeyException;\n+import org.zalando.nakadi.domain.EventType;\n+import org.zalando.nakadi.domain.Storage;\n+import org.zalando.nakadi.domain.Timeline;\n+import org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException;\n+import org.zalando.nakadi.exceptions.InternalNakadiException;\n+import org.zalando.nakadi.utils.TestUtils;\n+\n+public class TimelineDbRepositoryTest extends AbstractDbRepositoryTest {\n+\n+    private TimelineDbRepository tRepository;\n+    private StorageDbRepository sRepository;\n+    private EventTypeDbRepository eRepository;\n+\n+    public TimelineDbRepositoryTest() {\n+        super(\"zn_data.timeline\", \"zn_data.storage\", \"zn_data.event_type_schema\", \"zn_data.event_type\");\n+    }\n+\n+    @Before\n+    public void setUp() {\n+        super.setUp();\n+        this.tRepository = new TimelineDbRepository(template, mapper);\n+        this.sRepository = new StorageDbRepository(template, mapper);\n+        this.eRepository = new EventTypeDbRepository(template, mapper);\n+    }\n+\n+    @Test\n+    public void testTimelineCreated() throws InternalNakadiException, DuplicatedEventTypeNameException {\n+        final Storage storage = sRepository.createStorage(\n+                StorageDbRepositoryTest.createStorage(\"default\", \"test\", \"path\"));\n+        final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType());\n+\n+        final Timeline timeline = createTimeline(\n+                storage, UUID.randomUUID(), 0, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null);\n+\n+        tRepository.createTimeline(timeline);\n+\n+        final Optional<Timeline> fromDb = tRepository.getTimeline(timeline.getId());\n+        Assert.assertTrue(fromDb.isPresent());\n+        Assert.assertFalse(fromDb.get() == timeline);\n+        Assert.assertEquals(timeline, fromDb.get());\n+    }\n+\n+    @Test\n+    public void testTimelineUpdate() throws InternalNakadiException, DuplicatedEventTypeNameException {\n+        final Storage storage = sRepository.createStorage(\n+                StorageDbRepositoryTest.createStorage(\"default\", \"test\", \"path\"));\n+        final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType());\n+\n+        final Timeline initial = tRepository.createTimeline(createTimeline(\n+                storage, UUID.randomUUID(), 0, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null));\n+\n+        final Timeline modified = tRepository.getTimeline(initial.getId()).get();\n+        modified.setCreatedAt(new Date());\n+        modified.setCleanupAt(new Date());\n+        modified.setSwitchedAt(new Date());\n+        final Timeline.KafkaStoragePosition pos = new Timeline.KafkaStoragePosition();\n+        pos.setOffsets(LongStream.range(0L, 10L).mapToObj(Long::new).collect(Collectors.toList()));\n+        modified.setLatestPosition(pos);\n+\n+        tRepository.updateTimelime(modified);\n+        final Timeline result = tRepository.getTimeline(modified.getId()).get();\n+\n+        Assert.assertEquals(modified, result);\n+        Assert.assertNotEquals(initial, result);\n+    }\n+\n+    @Test(expected = DuplicateKeyException.class)\n+    public void testDuplicateOrderNotAllowed() throws InternalNakadiException, DuplicatedEventTypeNameException {\n+        final Storage storage = sRepository.createStorage(\n+                StorageDbRepositoryTest.createStorage(\"default\", \"test\", \"path\"));\n+        final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType());\n+\n+        tRepository.createTimeline(createTimeline(\n+                storage, UUID.randomUUID(), 0, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null));\n+        tRepository.createTimeline(createTimeline(\n+                storage, UUID.randomUUID(), 0, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null));\n+    }\n+\n+    @Test\n+    public void testListTimelinesOrdered() throws InternalNakadiException, DuplicatedEventTypeNameException {\n+        final Storage storage = sRepository.createStorage(\n+                StorageDbRepositoryTest.createStorage(\"default\", \"test\", \"path\"));\n+        final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType());\n+        final Timeline t1 = tRepository.createTimeline(createTimeline(\n+                storage, UUID.randomUUID(), 1, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null));\n+        final Timeline t0 = tRepository.createTimeline(createTimeline(\n+                storage, UUID.randomUUID(), 0, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null));\n+\n+        final List<Timeline> testTimelines = tRepository.listTimelines(testEt.getName());\n+        Assert.assertEquals(2, testTimelines.size());\n+        Assert.assertEquals(t0, testTimelines.get(0));\n+        Assert.assertEquals(t1, testTimelines.get(1));\n+    }\n+\n+    @Test\n+    public void testTimelineDeleted() throws InternalNakadiException, DuplicatedEventTypeNameException {\n+        final Storage storage = sRepository.createStorage(\n+                StorageDbRepositoryTest.createStorage(\"default\", \"test\", \"path\"));\n+        final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType());\n+        final Timeline t1 = tRepository.createTimeline(createTimeline(\n+                storage, UUID.randomUUID(), 1, \"test_topic\", testEt.getName(),\n+                new Date(), null, null, null));\n+        Assert.assertEquals(1, tRepository.listTimelines(testEt.getName()).size());\n+        tRepository.deleteTimeline(t1.getId());\n+        Assert.assertEquals(0, tRepository.listTimelines(testEt.getName()).size());\n+    }\n+\n+    private static Timeline createTimeline(","path":"src/acceptance-test/java/org/zalando/nakadi/repository/db/TimelineDbRepositoryTest.java","position":126,"original_position":126,"commit_id":"8f5984aa5a2d79d7f3c5e999bef0ddc7f5c704b8","original_commit_id":"8f5984aa5a2d79d7f3c5e999bef0ddc7f5c704b8","user":{"login":"antban","id":2656223,"avatar_url":"https://avatars.githubusercontent.com/u/2656223?v=3","gravatar_id":"","url":"https://api.github.com/users/antban","html_url":"https://github.com/antban","followers_url":"https://api.github.com/users/antban/followers","following_url":"https://api.github.com/users/antban/following{/other_user}","gists_url":"https://api.github.com/users/antban/gists{/gist_id}","starred_url":"https://api.github.com/users/antban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antban/subscriptions","organizations_url":"https://api.github.com/users/antban/orgs","repos_url":"https://api.github.com/users/antban/repos","events_url":"https://api.github.com/users/antban/events{/privacy}","received_events_url":"https://api.github.com/users/antban/received_events","type":"User","site_admin":false},"body":"I don't think that using builder in this case is necessary. I will create static method for timeline creation as a part of `@Nullable` policy.","created_at":"2017-01-10T13:57:12Z","updated_at":"2017-01-10T13:57:12Z","html_url":"https://github.com/zalando/nakadi/pull/531#discussion_r95367570","pull_request_url":"https://api.github.com/repos/zalando/nakadi/pulls/531","_links":{"self":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/comments/95367570"},"html":{"href":"https://github.com/zalando/nakadi/pull/531#discussion_r95367570"},"pull_request":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/531"}}},"pull_request":{"url":"https://api.github.com/repos/zalando/nakadi/pulls/531","id":100422570,"html_url":"https://github.com/zalando/nakadi/pull/531","diff_url":"https://github.com/zalando/nakadi/pull/531.diff","patch_url":"https://github.com/zalando/nakadi/pull/531.patch","issue_url":"https://api.github.com/repos/zalando/nakadi/issues/531","number":531,"state":"open","locked":false,"title":"ARUHA-522 Prepare database for timelines","user":{"login":"antban","id":2656223,"avatar_url":"https://avatars.githubusercontent.com/u/2656223?v=3","gravatar_id":"","url":"https://api.github.com/users/antban","html_url":"https://github.com/antban","followers_url":"https://api.github.com/users/antban/followers","following_url":"https://api.github.com/users/antban/following{/other_user}","gists_url":"https://api.github.com/users/antban/gists{/gist_id}","starred_url":"https://api.github.com/users/antban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antban/subscriptions","organizations_url":"https://api.github.com/users/antban/orgs","repos_url":"https://api.github.com/users/antban/repos","events_url":"https://api.github.com/users/antban/events{/privacy}","received_events_url":"https://api.github.com/users/antban/received_events","type":"User","site_admin":false},"body":"Covered things: \r\n - Migration scripts\r\n - CRD Storage\r\n - CRUD Timeline","created_at":"2017-01-06T07:49:15Z","updated_at":"2017-01-10T13:57:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a80bdae3ff1f44bc8c9967e8bfdefd07efd040b5","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/zalando/nakadi/pulls/531/commits","review_comments_url":"https://api.github.com/repos/zalando/nakadi/pulls/531/comments","review_comment_url":"https://api.github.com/repos/zalando/nakadi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando/nakadi/issues/531/comments","statuses_url":"https://api.github.com/repos/zalando/nakadi/statuses/8f5984aa5a2d79d7f3c5e999bef0ddc7f5c704b8","head":{"label":"zalando:ARUHA-522","ref":"ARUHA-522","sha":"8f5984aa5a2d79d7f3c5e999bef0ddc7f5c704b8","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":44234368,"name":"nakadi","full_name":"zalando/nakadi","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/nakadi","description":"A distributed event bus that implements a RESTful API abstraction instead of Kafka-like queues","fork":false,"url":"https://api.github.com/repos/zalando/nakadi","forks_url":"https://api.github.com/repos/zalando/nakadi/forks","keys_url":"https://api.github.com/repos/zalando/nakadi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/nakadi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/nakadi/teams","hooks_url":"https://api.github.com/repos/zalando/nakadi/hooks","issue_events_url":"https://api.github.com/repos/zalando/nakadi/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/nakadi/events","assignees_url":"https://api.github.com/repos/zalando/nakadi/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/nakadi/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/nakadi/tags","blobs_url":"https://api.github.com/repos/zalando/nakadi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/nakadi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/nakadi/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/nakadi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/nakadi/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/nakadi/languages","stargazers_url":"https://api.github.com/repos/zalando/nakadi/stargazers","contributors_url":"https://api.github.com/repos/zalando/nakadi/contributors","subscribers_url":"https://api.github.com/repos/zalando/nakadi/subscribers","subscription_url":"https://api.github.com/repos/zalando/nakadi/subscription","commits_url":"https://api.github.com/repos/zalando/nakadi/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/nakadi/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/nakadi/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/nakadi/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/nakadi/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/nakadi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/nakadi/merges","archive_url":"https://api.github.com/repos/zalando/nakadi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/nakadi/downloads","issues_url":"https://api.github.com/repos/zalando/nakadi/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/nakadi/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/nakadi/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/nakadi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/nakadi/labels{/name}","releases_url":"https://api.github.com/repos/zalando/nakadi/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/nakadi/deployments","created_at":"2015-10-14T08:30:17Z","updated_at":"2017-01-10T13:07:29Z","pushed_at":"2017-01-10T13:08:16Z","git_url":"git://github.com/zalando/nakadi.git","ssh_url":"git@github.com:zalando/nakadi.git","clone_url":"https://github.com/zalando/nakadi.git","svn_url":"https://github.com/zalando/nakadi","homepage":"","size":4614,"stargazers_count":87,"watchers_count":87,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":40,"mirror_url":null,"open_issues_count":29,"forks":40,"open_issues":29,"watchers":87,"default_branch":"master"}},"base":{"label":"zalando:master","ref":"master","sha":"18705aee546b81d3a8324a1320d30fa2e321f020","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":44234368,"name":"nakadi","full_name":"zalando/nakadi","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/nakadi","description":"A distributed event bus that implements a RESTful API abstraction instead of Kafka-like queues","fork":false,"url":"https://api.github.com/repos/zalando/nakadi","forks_url":"https://api.github.com/repos/zalando/nakadi/forks","keys_url":"https://api.github.com/repos/zalando/nakadi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/nakadi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/nakadi/teams","hooks_url":"https://api.github.com/repos/zalando/nakadi/hooks","issue_events_url":"https://api.github.com/repos/zalando/nakadi/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/nakadi/events","assignees_url":"https://api.github.com/repos/zalando/nakadi/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/nakadi/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/nakadi/tags","blobs_url":"https://api.github.com/repos/zalando/nakadi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/nakadi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/nakadi/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/nakadi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/nakadi/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/nakadi/languages","stargazers_url":"https://api.github.com/repos/zalando/nakadi/stargazers","contributors_url":"https://api.github.com/repos/zalando/nakadi/contributors","subscribers_url":"https://api.github.com/repos/zalando/nakadi/subscribers","subscription_url":"https://api.github.com/repos/zalando/nakadi/subscription","commits_url":"https://api.github.com/repos/zalando/nakadi/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/nakadi/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/nakadi/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/nakadi/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/nakadi/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/nakadi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/nakadi/merges","archive_url":"https://api.github.com/repos/zalando/nakadi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/nakadi/downloads","issues_url":"https://api.github.com/repos/zalando/nakadi/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/nakadi/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/nakadi/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/nakadi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/nakadi/labels{/name}","releases_url":"https://api.github.com/repos/zalando/nakadi/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/nakadi/deployments","created_at":"2015-10-14T08:30:17Z","updated_at":"2017-01-10T13:07:29Z","pushed_at":"2017-01-10T13:08:16Z","git_url":"git://github.com/zalando/nakadi.git","ssh_url":"git@github.com:zalando/nakadi.git","clone_url":"https://github.com/zalando/nakadi.git","svn_url":"https://github.com/zalando/nakadi","homepage":"","size":4614,"stargazers_count":87,"watchers_count":87,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":40,"mirror_url":null,"open_issues_count":29,"forks":40,"open_issues":29,"watchers":87,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/531"},"html":{"href":"https://github.com/zalando/nakadi/pull/531"},"issue":{"href":"https://api.github.com/repos/zalando/nakadi/issues/531"},"comments":{"href":"https://api.github.com/repos/zalando/nakadi/issues/531/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/531/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/531/commits"},"statuses":{"href":"https://api.github.com/repos/zalando/nakadi/statuses/8f5984aa5a2d79d7f3c5e999bef0ddc7f5c704b8"}}}}
{"actor":{"display_login":"antban"}}