{"action":"created","comment":{"url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments/28584551","id":28584551,"diff_hunk":"@@ -275,3 +277,192 @@ TEST(Sherlock, SubscribeToStreamViaHTTP) {\n   // TODO(dkorolev): Unregister the exposed endpoint and free its handler. It's hanging out there now...\n   // TODO(dkorolev): Add tests that the endpoint is not unregistered until its last client is done. (?)\n }\n+\n+struct IntKey {\n+  int x;\n+  IntKey(int x = 0) : x(x) {}\n+  int operator()() const { return x; }\n+\n+  template <typename A>\n+  void serialize(A& ar) {\n+    ar(CEREAL_NVP(x));\n+  }\n+\n+  bool operator==(const IntKey& rhs) const { return x == rhs.x; }\n+  struct HashFunction {\n+    size_t operator()(const IntKey& k) const { return static_cast<size_t>(k.x); }\n+  };\n+};\n+\n+struct KeyValueEntry {\n+  IntKey key_;\n+  double value_;\n+  // Uncomment the line below to ensure that it doesn't compile.\n+  // constexpr static bool allow_nonthrowing_get = true;\n+\n+  KeyValueEntry() = default;\n+  KeyValueEntry(const int key, const double value) : key_(key), value_(value) {}\n+\n+  const IntKey& key() const { return key_; }\n+  void set_key(const IntKey& key) { key_ = key; }\n+\n+  template <typename A>\n+  void serialize(A& ar) {\n+    ar(CEREAL_NVP(key_), CEREAL_NVP(value_));\n+  }\n+};\n+\n+struct KeyValueSubscriptionData {\n+  atomic_size_t seen_;\n+  string results_;\n+  KeyValueSubscriptionData() : seen_(0u) {}\n+};\n+\n+struct KeyValueAggregateListener {\n+  KeyValueSubscriptionData& data_;\n+  size_t max_to_process_ = static_cast<size_t>(-1);\n+\n+  KeyValueAggregateListener() = delete;\n+  explicit KeyValueAggregateListener(KeyValueSubscriptionData& data) : data_(data) {}\n+\n+  KeyValueAggregateListener& SetMax(size_t cap) {\n+    max_to_process_ = cap;\n+    return *this;\n+  }\n+\n+  bool Entry(const KeyValueEntry& entry, size_t index, size_t total) {\n+    static_cast<void>(index);\n+    static_cast<void>(total);\n+    if (data_.seen_) {\n+      data_.results_ += \",\";\n+    }\n+    data_.results_ += Printf(\"%d=%.2lf\", entry.key(), entry.value_);\n+    ++data_.seen_;\n+    return data_.seen_ < max_to_process_;\n+  }\n+\n+  void Terminate() {\n+    if (data_.seen_) {\n+      data_.results_ += \",\";\n+    }\n+    data_.results_ += \"DONE\";\n+  }\n+};\n+\n+TEST(Sherlock, NonPolymorphicKeyValueStorage) {\n+  typedef sherlock::kv_storage::API<KeyValueEntry> KVS;\n+  KVS api(\"non_polymorphic_kv_storage\");\n+\n+  // Add the first key-value pair.\n+  // Use `UnsafeStream()`, since generally the only way to access the underlying stream is to make API calls.\n+  api.UnsafeStream().Emplace(2, 0.5);\n+\n+  while (!api.CaughtUp()) {\n+    // Spin lock, for the purposes of this test.\n+    // Ensure that the data has reached the the processor that maintains the in-memory state of the API.\n+  }\n+\n+  // Future expanded syntax.\n+  std::future<KeyValueEntry> f1 = api.AsyncGet(KVS::T_KEY(2));\n+  KeyValueEntry r1 = f1.get();\n+  EXPECT_EQ(0.5, r1.value_);\n+\n+  // Future short syntax.\n+  EXPECT_EQ(0.5, api.AsyncGet(KVS::T_KEY(2)).get().value_);\n+\n+  // Callback version.\n+  struct CallBackTest {\n+    explicit CallBackTest(int key, double value, bool expect_fail = false) :\n+        key(key), value(value), expect_fail(expect_fail) {}\n+\n+    void found(const KeyValueEntry& entry) {\n+      called = true;\n+      EXPECT_FALSE(expect_fail);\n+      EXPECT_EQ(key, entry.key()());\n+      EXPECT_EQ(value, entry.value_);\n+    }\n+    void not_found(const IntKey& key) {\n+      called = true;\n+      EXPECT_TRUE(expect_fail);\n+      EXPECT_EQ(this->key, key());\n+    }\n+    void added() {\n+      called = true;\n+      EXPECT_FALSE(expect_fail);\n+    }\n+    void already_exists() {\n+      called = true;\n+      EXPECT_TRUE(expect_fail);\n+    }\n+\n+    const int key;\n+    const double value;\n+    const bool expect_fail;\n+    bool called = false;\n+  };\n+\n+  CallBackTest cbt1(2, 0.5);\n+  auto cbf1 = [&](const KeyValueEntry& entry) { cbt1.found(entry); };\n+  auto cbnf1 = [&](const IntKey& key) { cbt1.not_found(key); };\n+  api.AsyncGet(KVS::T_KEY(2), cbf1, cbnf1);\n+  while (!cbt1.called)\n+    ;\n+\n+  // Add two more key-value pairs.\n+  api.UnsafeStream().Emplace(3, 0.33);\n+  api.UnsafeStream().Emplace(4, 0.25);\n+\n+  while (api.EntriesSeen() < 3u) {\n+    // For the purposes of this test: Spin lock to ensure that the listener/MMQ consumer got the data published.\n+  }\n+\n+  EXPECT_EQ(0.33, api.AsyncGet(KVS::T_KEY(3)).get().value_);\n+  EXPECT_EQ(0.25, api.Get(KVS::T_KEY(4)).value_);\n+\n+  ASSERT_THROW(api.AsyncGet(KVS::T_KEY(5)).get(), KVS::T_KEY_NOT_FOUND_EXCEPTION);\n+  ASSERT_THROW(api.Get(KVS::T_KEY(6)), KVS::T_KEY_NOT_FOUND_EXCEPTION);\n+  CallBackTest cbt2(7, 0.0, true);\n+  auto cbf2 = [&](const KeyValueEntry& entry) { cbt2.found(entry); };\n+  auto cbnf2 = [&](const IntKey& key) { cbt2.not_found(key); };\n+  api.AsyncGet(KVS::T_KEY(7), cbf2, cbnf2);\n+  while (!cbt2.called)\n+    ;\n+\n+  // Add three more key-value pairs, this time via the API.\n+  api.AsyncAdd(KeyValueEntry(5, 0.2)).wait();\n+  api.Add(KeyValueEntry(6, 0.17));\n+  CallBackTest cbt3(7, 0.76);\n+  auto cba3 = [&]() { cbt3.added(); };","path":"test.cc","position":193,"original_position":193,"commit_id":"157ee5a7c64803a6877c8ba4e94927a4ab46ccdd","original_commit_id":"157ee5a7c64803a6877c8ba4e94927a4ab46ccdd","user":{"login":"dkorolev","id":2159447,"avatar_url":"https://avatars.githubusercontent.com/u/2159447?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorolev","html_url":"https://github.com/dkorolev","followers_url":"https://api.github.com/users/dkorolev/followers","following_url":"https://api.github.com/users/dkorolev/following{/other_user}","gists_url":"https://api.github.com/users/dkorolev/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorolev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorolev/subscriptions","organizations_url":"https://api.github.com/users/dkorolev/orgs","repos_url":"https://api.github.com/users/dkorolev/repos","events_url":"https://api.github.com/users/dkorolev/events{/privacy}","received_events_url":"https://api.github.com/users/dkorolev/received_events","type":"User","site_admin":false},"body":"Same comment on `std::bind`.","created_at":"2015-04-17T10:41:53Z","updated_at":"2015-04-17T10:41:53Z","html_url":"https://github.com/KnowSheet/Sherlock/pull/15#discussion_r28584551","pull_request_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments/28584551"},"html":{"href":"https://github.com/KnowSheet/Sherlock/pull/15#discussion_r28584551"},"pull_request":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15","id":33502747,"html_url":"https://github.com/KnowSheet/Sherlock/pull/15","diff_url":"https://github.com/KnowSheet/Sherlock/pull/15.diff","patch_url":"https://github.com/KnowSheet/Sherlock/pull/15.patch","issue_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/15","number":15,"state":"open","locked":false,"title":"Fresh version of KV Storage. Get() and Add() with policies.","user":{"login":"mzhurovich","id":11226961,"avatar_url":"https://avatars.githubusercontent.com/u/11226961?v=3","gravatar_id":"","url":"https://api.github.com/users/mzhurovich","html_url":"https://github.com/mzhurovich","followers_url":"https://api.github.com/users/mzhurovich/followers","following_url":"https://api.github.com/users/mzhurovich/following{/other_user}","gists_url":"https://api.github.com/users/mzhurovich/gists{/gist_id}","starred_url":"https://api.github.com/users/mzhurovich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mzhurovich/subscriptions","organizations_url":"https://api.github.com/users/mzhurovich/orgs","repos_url":"https://api.github.com/users/mzhurovich/repos","events_url":"https://api.github.com/users/mzhurovich/events{/privacy}","received_events_url":"https://api.github.com/users/mzhurovich/received_events","type":"User","site_admin":false},"body":"@dkorolev PTAL.","created_at":"2015-04-16T23:30:36Z","updated_at":"2015-04-17T10:41:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aa3379db04a67397394040cca333db512e5d8b50","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15/commits","review_comments_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15/comments","review_comment_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/15/comments","statuses_url":"https://api.github.com/repos/KnowSheet/Sherlock/statuses/157ee5a7c64803a6877c8ba4e94927a4ab46ccdd","head":{"label":"mzhurovich:kv-storage","ref":"kv-storage","sha":"157ee5a7c64803a6877c8ba4e94927a4ab46ccdd","user":{"login":"mzhurovich","id":11226961,"avatar_url":"https://avatars.githubusercontent.com/u/11226961?v=3","gravatar_id":"","url":"https://api.github.com/users/mzhurovich","html_url":"https://github.com/mzhurovich","followers_url":"https://api.github.com/users/mzhurovich/followers","following_url":"https://api.github.com/users/mzhurovich/following{/other_user}","gists_url":"https://api.github.com/users/mzhurovich/gists{/gist_id}","starred_url":"https://api.github.com/users/mzhurovich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mzhurovich/subscriptions","organizations_url":"https://api.github.com/users/mzhurovich/orgs","repos_url":"https://api.github.com/users/mzhurovich/repos","events_url":"https://api.github.com/users/mzhurovich/events{/privacy}","received_events_url":"https://api.github.com/users/mzhurovich/received_events","type":"User","site_admin":false},"repo":{"id":33790556,"name":"Sherlock","full_name":"mzhurovich/Sherlock","owner":{"login":"mzhurovich","id":11226961,"avatar_url":"https://avatars.githubusercontent.com/u/11226961?v=3","gravatar_id":"","url":"https://api.github.com/users/mzhurovich","html_url":"https://github.com/mzhurovich","followers_url":"https://api.github.com/users/mzhurovich/followers","following_url":"https://api.github.com/users/mzhurovich/following{/other_user}","gists_url":"https://api.github.com/users/mzhurovich/gists{/gist_id}","starred_url":"https://api.github.com/users/mzhurovich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mzhurovich/subscriptions","organizations_url":"https://api.github.com/users/mzhurovich/orgs","repos_url":"https://api.github.com/users/mzhurovich/repos","events_url":"https://api.github.com/users/mzhurovich/events{/privacy}","received_events_url":"https://api.github.com/users/mzhurovich/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mzhurovich/Sherlock","description":"Structured, append-only, immutable data persistence layer with publish-subscribe.","fork":true,"url":"https://api.github.com/repos/mzhurovich/Sherlock","forks_url":"https://api.github.com/repos/mzhurovich/Sherlock/forks","keys_url":"https://api.github.com/repos/mzhurovich/Sherlock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mzhurovich/Sherlock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mzhurovich/Sherlock/teams","hooks_url":"https://api.github.com/repos/mzhurovich/Sherlock/hooks","issue_events_url":"https://api.github.com/repos/mzhurovich/Sherlock/issues/events{/number}","events_url":"https://api.github.com/repos/mzhurovich/Sherlock/events","assignees_url":"https://api.github.com/repos/mzhurovich/Sherlock/assignees{/user}","branches_url":"https://api.github.com/repos/mzhurovich/Sherlock/branches{/branch}","tags_url":"https://api.github.com/repos/mzhurovich/Sherlock/tags","blobs_url":"https://api.github.com/repos/mzhurovich/Sherlock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mzhurovich/Sherlock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mzhurovich/Sherlock/git/refs{/sha}","trees_url":"https://api.github.com/repos/mzhurovich/Sherlock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mzhurovich/Sherlock/statuses/{sha}","languages_url":"https://api.github.com/repos/mzhurovich/Sherlock/languages","stargazers_url":"https://api.github.com/repos/mzhurovich/Sherlock/stargazers","contributors_url":"https://api.github.com/repos/mzhurovich/Sherlock/contributors","subscribers_url":"https://api.github.com/repos/mzhurovich/Sherlock/subscribers","subscription_url":"https://api.github.com/repos/mzhurovich/Sherlock/subscription","commits_url":"https://api.github.com/repos/mzhurovich/Sherlock/commits{/sha}","git_commits_url":"https://api.github.com/repos/mzhurovich/Sherlock/git/commits{/sha}","comments_url":"https://api.github.com/repos/mzhurovich/Sherlock/comments{/number}","issue_comment_url":"https://api.github.com/repos/mzhurovich/Sherlock/issues/comments{/number}","contents_url":"https://api.github.com/repos/mzhurovich/Sherlock/contents/{+path}","compare_url":"https://api.github.com/repos/mzhurovich/Sherlock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mzhurovich/Sherlock/merges","archive_url":"https://api.github.com/repos/mzhurovich/Sherlock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mzhurovich/Sherlock/downloads","issues_url":"https://api.github.com/repos/mzhurovich/Sherlock/issues{/number}","pulls_url":"https://api.github.com/repos/mzhurovich/Sherlock/pulls{/number}","milestones_url":"https://api.github.com/repos/mzhurovich/Sherlock/milestones{/number}","notifications_url":"https://api.github.com/repos/mzhurovich/Sherlock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mzhurovich/Sherlock/labels{/name}","releases_url":"https://api.github.com/repos/mzhurovich/Sherlock/releases{/id}","created_at":"2015-04-11T20:09:30Z","updated_at":"2015-04-11T20:09:31Z","pushed_at":"2015-04-16T23:27:42Z","git_url":"git://github.com/mzhurovich/Sherlock.git","ssh_url":"git@github.com:mzhurovich/Sherlock.git","clone_url":"https://github.com/mzhurovich/Sherlock.git","svn_url":"https://github.com/mzhurovich/Sherlock","homepage":null,"size":289,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"KnowSheet:master","ref":"master","sha":"a44c0445c05492e4a0c075475b3159da05aa4c80","user":{"login":"KnowSheet","id":9897562,"avatar_url":"https://avatars.githubusercontent.com/u/9897562?v=3","gravatar_id":"","url":"https://api.github.com/users/KnowSheet","html_url":"https://github.com/KnowSheet","followers_url":"https://api.github.com/users/KnowSheet/followers","following_url":"https://api.github.com/users/KnowSheet/following{/other_user}","gists_url":"https://api.github.com/users/KnowSheet/gists{/gist_id}","starred_url":"https://api.github.com/users/KnowSheet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KnowSheet/subscriptions","organizations_url":"https://api.github.com/users/KnowSheet/orgs","repos_url":"https://api.github.com/users/KnowSheet/repos","events_url":"https://api.github.com/users/KnowSheet/events{/privacy}","received_events_url":"https://api.github.com/users/KnowSheet/received_events","type":"Organization","site_admin":false},"repo":{"id":31759722,"name":"Sherlock","full_name":"KnowSheet/Sherlock","owner":{"login":"KnowSheet","id":9897562,"avatar_url":"https://avatars.githubusercontent.com/u/9897562?v=3","gravatar_id":"","url":"https://api.github.com/users/KnowSheet","html_url":"https://github.com/KnowSheet","followers_url":"https://api.github.com/users/KnowSheet/followers","following_url":"https://api.github.com/users/KnowSheet/following{/other_user}","gists_url":"https://api.github.com/users/KnowSheet/gists{/gist_id}","starred_url":"https://api.github.com/users/KnowSheet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KnowSheet/subscriptions","organizations_url":"https://api.github.com/users/KnowSheet/orgs","repos_url":"https://api.github.com/users/KnowSheet/repos","events_url":"https://api.github.com/users/KnowSheet/events{/privacy}","received_events_url":"https://api.github.com/users/KnowSheet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/KnowSheet/Sherlock","description":"Structured, append-only, immutable data persistence layer with publish-subscribe.","fork":false,"url":"https://api.github.com/repos/KnowSheet/Sherlock","forks_url":"https://api.github.com/repos/KnowSheet/Sherlock/forks","keys_url":"https://api.github.com/repos/KnowSheet/Sherlock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KnowSheet/Sherlock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KnowSheet/Sherlock/teams","hooks_url":"https://api.github.com/repos/KnowSheet/Sherlock/hooks","issue_events_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/events{/number}","events_url":"https://api.github.com/repos/KnowSheet/Sherlock/events","assignees_url":"https://api.github.com/repos/KnowSheet/Sherlock/assignees{/user}","branches_url":"https://api.github.com/repos/KnowSheet/Sherlock/branches{/branch}","tags_url":"https://api.github.com/repos/KnowSheet/Sherlock/tags","blobs_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/refs{/sha}","trees_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KnowSheet/Sherlock/statuses/{sha}","languages_url":"https://api.github.com/repos/KnowSheet/Sherlock/languages","stargazers_url":"https://api.github.com/repos/KnowSheet/Sherlock/stargazers","contributors_url":"https://api.github.com/repos/KnowSheet/Sherlock/contributors","subscribers_url":"https://api.github.com/repos/KnowSheet/Sherlock/subscribers","subscription_url":"https://api.github.com/repos/KnowSheet/Sherlock/subscription","commits_url":"https://api.github.com/repos/KnowSheet/Sherlock/commits{/sha}","git_commits_url":"https://api.github.com/repos/KnowSheet/Sherlock/git/commits{/sha}","comments_url":"https://api.github.com/repos/KnowSheet/Sherlock/comments{/number}","issue_comment_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues/comments{/number}","contents_url":"https://api.github.com/repos/KnowSheet/Sherlock/contents/{+path}","compare_url":"https://api.github.com/repos/KnowSheet/Sherlock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KnowSheet/Sherlock/merges","archive_url":"https://api.github.com/repos/KnowSheet/Sherlock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KnowSheet/Sherlock/downloads","issues_url":"https://api.github.com/repos/KnowSheet/Sherlock/issues{/number}","pulls_url":"https://api.github.com/repos/KnowSheet/Sherlock/pulls{/number}","milestones_url":"https://api.github.com/repos/KnowSheet/Sherlock/milestones{/number}","notifications_url":"https://api.github.com/repos/KnowSheet/Sherlock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KnowSheet/Sherlock/labels{/name}","releases_url":"https://api.github.com/repos/KnowSheet/Sherlock/releases{/id}","created_at":"2015-03-06T08:26:50Z","updated_at":"2015-04-10T17:04:16Z","pushed_at":"2015-04-16T23:30:36Z","git_url":"git://github.com/KnowSheet/Sherlock.git","ssh_url":"git@github.com:KnowSheet/Sherlock.git","clone_url":"https://github.com/KnowSheet/Sherlock.git","svn_url":"https://github.com/KnowSheet/Sherlock","homepage":null,"size":579,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":4,"forks":4,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15"},"html":{"href":"https://github.com/KnowSheet/Sherlock/pull/15"},"issue":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/issues/15"},"comments":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/KnowSheet/Sherlock/statuses/157ee5a7c64803a6877c8ba4e94927a4ab46ccdd"}}}}