Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
lookup before sync cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Raab committed Apr 6, 2016
1 parent 7adb67e commit edbcc82
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bindings/cpp/include/kdbvalue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ class Value : public ValueObserver, public ValueSubject, public Wrapped
{
Command::Func fun = [this]() -> Command::Pair {
std::string const & oldKey = m_key.getName ();
this->unsafeLookupKey ();
this->unsafeSyncCache ();
return std::make_pair (oldKey, m_key.getName ());
};
Expand Down Expand Up @@ -635,8 +636,17 @@ class Value : public ValueObserver, public ValueSubject, public Wrapped
assert (m_key);
}

void unsafeLookupKey () const
{
// Key spec (m_spec.dup ());
// spec.setName (m_context.evaluate(m_spec.getName()));
// m_key = Policies::GetPolicy::get (m_ks, spec);
m_key = Policies::GetPolicy::get (m_ks, m_key);
assert (m_key);
}

/**
* @brief Execute this method *only* in a Command execution
* @brief Unsafe: Execute this method *only* in a Command execution
*/
void unsafeSyncCache () const
{
Expand Down
14 changes: 14 additions & 0 deletions src/bindings/cpp/tests/testcpp_contextual_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,22 @@ TYPED_TEST (test_contextual_basic, cvWrapped)
KEY_META, "default", s_value, KEY_END));

ASSERT_EQ (x.getName (), "/%/key");
ASSERT_TRUE (ks.lookup ("/%/key"));
c.template activate (i);
ASSERT_EQ (x.getName (), "/my/key");
ASSERT_TRUE (ks.lookup ("/my/key"));

ks.append (Key("/other/key", KEY_VALUE, "88", KEY_END));
i = "other";
c.template activate (i);
ASSERT_EQ (x.getName (), "/other/key");
ASSERT_TRUE (ks.lookup ("/other/key"));
ASSERT_EQ (x, 88);
ASSERT_EQ (ks.lookup ("/other/key").getString(), "88");

ks.append (Key("/other/key", KEY_VALUE, "100", KEY_END));
ASSERT_EQ (ks.lookup ("/other/key").getString(), "100");
ASSERT_EQ (x, 88) << "updated from KeySet?";
}


Expand Down
50 changes: 50 additions & 0 deletions src/bindings/cpp/tests/testcpp_contextual_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,53 @@ TEST (test_contextual_thread, syncBeforeWith)
ASSERT_EQ (v.getName (), "user/act/active");
ASSERT_EQ (v, 22);
}

TEST (test_contextual_thread, cvWrappedUpdate)
{
using namespace kdb;

KeySet ks;
Coordinator gc;
ThreadContext c (gc);
ThreadValue<std::string> i (
ks, c, Key ("/ignore/id",
KEY_META, "default", "my", KEY_END));

ThreadValue<int> x (
ks, c, Key ("/%id%/key",
KEY_META, "default", s_value, KEY_END));

ASSERT_EQ (x.getName (), "/%/key");
ASSERT_TRUE (ks.lookup ("/%/key"));
c.template activate (i);
ASSERT_EQ (x.getName (), "/my/key");
ASSERT_TRUE (ks.lookup ("/my/key"));

ks.append (Key("/other/key", KEY_VALUE, "88", KEY_END));
i = "other";
c.template activate (i);
ASSERT_EQ (x.getName (), "/other/key");
ASSERT_TRUE (ks.lookup ("/other/key"));
ASSERT_EQ (x, 88);
ASSERT_EQ (ks.lookup ("/other/key").getString(), "88");

ks.lookup ("/other/key").setString("100");

c.syncLayers();
ASSERT_EQ (x, 88) << "should not influence cache";
ASSERT_EQ (x.getName (), "/other/key");
ASSERT_EQ (ks.lookup ("/other/key").getString(), "100");

x.syncCache();
ASSERT_EQ (x.getName (), "/other/key");
ASSERT_EQ (ks.lookup ("/other/key").getString(), "100");
ASSERT_EQ (x, 100) << "cache should be updated";

ks.append (Key("/other/key", KEY_VALUE, "111", KEY_END));

x.syncCache();
ASSERT_EQ (x.getName (), "/other/key");
ASSERT_EQ (ks.lookup ("/other/key").getString(), "111");
ASSERT_EQ (x, 111) << "reevaluated context, should have found new key";
}

0 comments on commit edbcc82

Please sign in to comment.