Make StorageEntry a struct and move into Storage class.

This commit is contained in:
Peter Johnson
2015-07-31 13:48:33 -07:00
parent 138ebf5b4d
commit cde7782c21
3 changed files with 118 additions and 136 deletions

View File

@@ -36,7 +36,7 @@ void Storage::ClearOutgoing() {
NT_Type Storage::GetEntryType(unsigned int id) const {
std::lock_guard<std::mutex> lock(m_mutex);
if (id >= m_idmap.size()) return NT_UNASSIGNED;
auto value = m_idmap[id]->value();
auto value = m_idmap[id]->value;
if (!value) return NT_UNASSIGNED;
return value->type();
}
@@ -57,7 +57,7 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
case Message::kEntryAssign: {
unsigned int id = msg->id();
StringRef name = msg->str();
std::shared_ptr<StorageEntry> entry;
std::shared_ptr<Entry> entry;
bool may_need_update = false;
if (m_server) {
// if we're a server, id=0xffff requests are requests for an id
@@ -70,18 +70,18 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
// create it locally
id = m_idmap.size();
auto& new_entry = m_entries[name];
if (!new_entry) new_entry = std::make_shared<StorageEntry>(name);
if (!new_entry) new_entry = std::make_shared<Entry>(name);
entry = new_entry;
entry->set_value(msg->value());
entry->set_flags(msg->flags());
entry->set_id(id);
entry->value = msg->value();
entry->flags = msg->flags();
entry->id = id;
m_idmap.push_back(entry);
// send the assignment to everyone (including the originator)
if (m_queue_outgoing) {
auto queue_outgoing = m_queue_outgoing;
auto outmsg = Message::EntryAssign(
name, id, entry->seq_num().value(), msg->value(), msg->flags());
name, id, entry->seq_num.value(), msg->value(), msg->flags());
lock.unlock();
queue_outgoing(outmsg, nullptr, nullptr);
}
@@ -110,13 +110,13 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
if (!new_entry) {
// didn't exist at all (rather than just being a response to a
// id assignment request)
new_entry = std::make_shared<StorageEntry>(name);
new_entry->set_value(msg->value());
new_entry->set_flags(msg->flags());
new_entry = std::make_shared<Entry>(name);
new_entry->value = msg->value();
new_entry->flags = msg->flags();
} else
may_need_update = true; // we may need to send an update message
entry = new_entry;
entry->set_id(id);
entry->id = id;
m_idmap[id] = entry;
return;
}
@@ -126,11 +126,11 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
// already exists; ignore if sequence number not higher than local
SequenceNumber seq_num(msg->seq_num_uid());
if (seq_num <= entry->seq_num()) {
if (seq_num <= entry->seq_num) {
if (may_need_update) {
auto queue_outgoing = m_queue_outgoing;
auto msg = Message::EntryUpdate(entry->id(), entry->seq_num().value(),
entry->value());
auto msg = Message::EntryUpdate(entry->id, entry->seq_num.value(),
entry->value);
lock.unlock();
queue_outgoing(msg, nullptr, nullptr);
}
@@ -138,26 +138,26 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
}
// sanity check: name should match id
if (msg->str() != entry->name()) {
if (msg->str() != entry->name) {
lock.unlock();
DEBUG("entry assignment for same id with different name?");
return;
}
// update local
entry->set_value(msg->value());
entry->set_seq_num(seq_num);
entry->value = msg->value();
entry->seq_num = seq_num;
// don't update flags from a <3.0 remote (not part of message)
if (proto_rev >= 0x0300) entry->set_flags(msg->flags());
if (proto_rev >= 0x0300) entry->flags = msg->flags();
// broadcast to all other connections (note for client there won't
// be any other connections, so don't bother)
if (m_server && m_queue_outgoing) {
auto queue_outgoing = m_queue_outgoing;
auto outmsg =
Message::EntryAssign(entry->name(), id, msg->seq_num_uid(),
msg->value(), entry->flags());
Message::EntryAssign(entry->name, id, msg->seq_num_uid(),
msg->value(), entry->flags);
lock.unlock();
queue_outgoing(outmsg, nullptr, conn);
}
@@ -176,11 +176,11 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
// ignore if sequence number not higher than local
SequenceNumber seq_num(msg->seq_num_uid());
if (seq_num <= entry->seq_num()) return;
if (seq_num <= entry->seq_num) return;
// update local
entry->set_value(msg->value());
entry->set_seq_num(seq_num);
entry->value = msg->value();
entry->seq_num = seq_num;
// broadcast to all other connections (note for client there won't
// be any other connections, so don't bother)
@@ -203,7 +203,7 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
auto& entry = m_idmap[id];
// update local
entry->set_flags(msg->flags());
entry->flags = msg->flags();
// broadcast to all other connections (note for client there won't
// be any other connections, so don't bother)
@@ -226,7 +226,7 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
auto& entry = m_idmap[id];
// update local
m_entries.erase(entry->name()); // erase from map
m_entries.erase(entry->name); // erase from map
entry.reset(); // delete it from idmap too
// broadcast to all other connections (note for client there won't
@@ -268,10 +268,10 @@ void Storage::SendAssignments(
std::lock_guard<std::mutex> lock(m_mutex);
for (auto& i : m_entries) {
auto entry = i.getValue();
msgs.emplace_back(Message::EntryAssign(i.getKey(), entry->id(),
entry->seq_num().value(),
entry->value(), entry->flags()));
if (!m_server && reset_ids) entry->set_id(0xffff);
msgs.emplace_back(Message::EntryAssign(i.getKey(), entry->id,
entry->seq_num.value(),
entry->value, entry->flags));
if (!m_server && reset_ids) entry->id = 0xffff;
}
if (!m_server && reset_ids) m_idmap.resize(0);
}
@@ -281,7 +281,7 @@ void Storage::SendAssignments(
std::shared_ptr<Value> Storage::GetEntryValue(StringRef name) const {
std::lock_guard<std::mutex> lock(m_mutex);
auto i = m_entries.find(name);
return i == m_entries.end() ? nullptr : i->getValue()->value();
return i == m_entries.end() ? nullptr : i->getValue()->value;
}
bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
@@ -289,17 +289,17 @@ bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
if (!value) return true;
std::unique_lock<std::mutex> lock(m_mutex);
auto& new_entry = m_entries[name];
if (!new_entry) new_entry = std::make_shared<StorageEntry>(name);
if (!new_entry) new_entry = std::make_shared<Entry>(name);
auto entry = new_entry;
auto old_value = entry->value();
auto old_value = entry->value;
if (old_value && old_value->type() != value->type())
return false; // error on type mismatch
entry->set_value(value);
entry->value = value;
// if we're the server, assign an id if it doesn't have one
if (m_server && entry->id() == 0xffff) {
if (m_server && entry->id == 0xffff) {
unsigned int id = m_idmap.size();
entry->set_id(id);
entry->id = id;
m_idmap.push_back(entry);
}
@@ -307,16 +307,16 @@ bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
if (!m_queue_outgoing) return true;
auto queue_outgoing = m_queue_outgoing;
if (!old_value) {
auto msg = Message::EntryAssign(name, entry->id(), entry->seq_num().value(),
value, entry->flags());
auto msg = Message::EntryAssign(name, entry->id, entry->seq_num.value(),
value, entry->flags);
lock.unlock();
queue_outgoing(msg, nullptr, nullptr);
} else if (*old_value != *value) {
entry->seq_num_inc();
++entry->seq_num;
// don't send an update if we don't have an assigned id yet
if (entry->id() != 0xffff) {
if (entry->id != 0xffff) {
auto msg =
Message::EntryUpdate(entry->id(), entry->seq_num().value(), value);
Message::EntryUpdate(entry->id, entry->seq_num.value(), value);
lock.unlock();
queue_outgoing(msg, nullptr, nullptr);
}
@@ -329,15 +329,15 @@ void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value) {
if (!value) return;
std::unique_lock<std::mutex> lock(m_mutex);
auto& entry = m_entries[name];
if (!entry) entry = std::make_shared<StorageEntry>(name);
auto old_value = entry->value();
entry->set_value(value);
if (!entry) entry = std::make_shared<Entry>(name);
auto old_value = entry->value;
entry->value = value;
if (old_value && *old_value == *value) return;
// if we're the server, assign an id if it doesn't have one
if (m_server && entry->id() == 0xffff) {
if (m_server && entry->id == 0xffff) {
unsigned int id = m_idmap.size();
entry->set_id(id);
entry->id = id;
m_idmap.push_back(entry);
}
@@ -345,17 +345,17 @@ void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value) {
if (!m_queue_outgoing) return;
auto queue_outgoing = m_queue_outgoing;
if (!old_value || old_value->type() != value->type()) {
entry->seq_num_inc();
auto msg = Message::EntryAssign(name, entry->id(), entry->seq_num().value(),
value, entry->flags());
++entry->seq_num;
auto msg = Message::EntryAssign(name, entry->id, entry->seq_num.value(),
value, entry->flags);
lock.unlock();
queue_outgoing(msg, nullptr, nullptr);
} else {
entry->seq_num_inc();
++entry->seq_num;
// don't send an update if we don't have an assigned id yet
if (entry->id() != 0xffff) {
if (entry->id != 0xffff) {
auto msg =
Message::EntryUpdate(entry->id(), entry->seq_num().value(), value);
Message::EntryUpdate(entry->id, entry->seq_num.value(), value);
lock.unlock();
queue_outgoing(msg, nullptr, nullptr);
}
@@ -368,13 +368,13 @@ void Storage::SetEntryFlags(StringRef name, unsigned int flags) {
auto i = m_entries.find(name);
if (i == m_entries.end()) return;
auto entry = i->getValue();
if (entry->flags() == flags) return;
entry->set_flags(flags);
if (entry->flags == flags) return;
entry->flags = flags;
// generate message
if (!m_queue_outgoing) return;
auto queue_outgoing = m_queue_outgoing;
unsigned int id = entry->id();
unsigned int id = entry->id;
// don't send an update if we don't have an assigned id yet
if (id != 0xffff) {
lock.unlock();
@@ -385,7 +385,7 @@ void Storage::SetEntryFlags(StringRef name, unsigned int flags) {
unsigned int Storage::GetEntryFlags(StringRef name) const {
std::lock_guard<std::mutex> lock(m_mutex);
auto i = m_entries.find(name);
return i == m_entries.end() ? 0 : i->getValue()->flags();
return i == m_entries.end() ? 0 : i->getValue()->flags;
}
void Storage::DeleteEntry(StringRef name) {
@@ -393,11 +393,11 @@ void Storage::DeleteEntry(StringRef name) {
auto i = m_entries.find(name);
if (i == m_entries.end()) return;
auto entry = i->getValue();
unsigned int id = entry->id();
unsigned int id = entry->id;
m_entries.erase(i); // erase from map
if (id < m_idmap.size()) m_idmap[id].reset();
if (!entry->value()) return;
if (!entry->value) return;
// if it had a value, generate message
// don't send an update if we don't have an assigned id yet
@@ -429,13 +429,13 @@ std::vector<EntryInfo> Storage::GetEntryInfo(StringRef prefix,
for (auto& i : m_entries) {
if (!i.getKey().startswith(prefix)) continue;
auto entry = i.getValue();
auto value = entry->value();
auto value = entry->value;
if (!value) continue;
if (types != 0 && (types & value->type()) == 0) continue;
EntryInfo info;
info.name = i.getKey();
info.type = value->type();
info.flags = entry->flags();
info.flags = entry->flags;
info.last_change = value->last_change();
infos.push_back(std::move(info));
}
@@ -484,7 +484,7 @@ void Storage::SavePersistent(std::ostream& os) const {
auto entry = i.getValue();
// only write persistent-flagged values
if (!entry->IsPersistent()) continue;
entries.push_back(std::make_pair(i.getKey(), entry->value()));
entries.push_back(std::make_pair(i.getKey(), entry->value));
}
}
@@ -869,34 +869,34 @@ next_line:
std::unique_lock<std::mutex> lock(m_mutex);
for (auto& i : entries) {
auto& entry = m_entries[i.first];
if (!entry) entry = std::make_shared<StorageEntry>(i.first);
auto old_value = entry->value();
entry->set_value(i.second);
if (!entry) entry = std::make_shared<Entry>(i.first);
auto old_value = entry->value;
entry->value = i.second;
bool was_persist = entry->IsPersistent();
if (!was_persist) entry->set_flags(entry->flags() | NT_PERSISTENT);
if (!was_persist) entry->flags |= NT_PERSISTENT;
// if we're the server, assign an id if it doesn't have one
if (m_server && entry->id() == 0xffff) {
if (m_server && entry->id == 0xffff) {
unsigned int id = m_idmap.size();
entry->set_id(id);
entry->id = id;
m_idmap.push_back(entry);
}
if (!m_queue_outgoing) continue; // shortcut
entry->seq_num_inc();
++entry->seq_num;
// put on update queue
if (!old_value || old_value->type() != i.second->type())
msgs.emplace_back(Message::EntryAssign(i.first, entry->id(),
entry->seq_num().value(),
i.second, entry->flags()));
else if (entry->id() != 0xffff) {
msgs.emplace_back(Message::EntryAssign(i.first, entry->id,
entry->seq_num.value(),
i.second, entry->flags));
else if (entry->id != 0xffff) {
// don't send an update if we don't have an assigned id yet
if (*old_value != *i.second)
msgs.emplace_back(Message::EntryUpdate(
entry->id(), entry->seq_num().value(), i.second));
entry->id, entry->seq_num.value(), i.second));
if (!was_persist)
msgs.emplace_back(Message::FlagsUpdate(entry->id(), entry->flags()));
msgs.emplace_back(Message::FlagsUpdate(entry->id, entry->flags));
}
}

View File

@@ -26,35 +26,6 @@ namespace nt {
class NetworkConnection;
class StorageTest;
class StorageEntry {
public:
StorageEntry(llvm::StringRef name) : m_name(name), m_flags(0), m_id(0xffff) {}
bool IsPersistent() const { return (m_flags & NT_PERSISTENT) != 0; }
std::shared_ptr<Value> value() const { return m_value; }
void set_value(std::shared_ptr<Value> value) { m_value = value; }
unsigned int flags() const { return m_flags; }
void set_flags(unsigned int flags) { m_flags = flags; }
StringRef name() const { return m_name; }
unsigned int id() const { return m_id; }
void set_id(unsigned int id) { m_id = id; }
SequenceNumber seq_num() const { return m_seq_num; }
void set_seq_num(SequenceNumber seq_num) { m_seq_num = seq_num; }
SequenceNumber seq_num_inc() { return ++m_seq_num; }
private:
std::string m_name;
std::shared_ptr<Value> m_value;
unsigned int m_flags;
unsigned int m_id;
SequenceNumber m_seq_num;
};
class Storage {
friend class StorageTest;
public:
@@ -100,8 +71,19 @@ class Storage {
Storage(const Storage&) = delete;
Storage& operator=(const Storage&) = delete;
typedef llvm::StringMap<std::shared_ptr<StorageEntry>> EntriesMap;
typedef std::vector<std::shared_ptr<StorageEntry>> IdMap;
struct Entry {
Entry(llvm::StringRef name_) : name(name_), flags(0), id(0xffff) {}
bool IsPersistent() const { return (flags & NT_PERSISTENT) != 0; }
std::string name;
std::shared_ptr<Value> value;
unsigned int flags;
unsigned int id;
SequenceNumber seq_num;
};
typedef llvm::StringMap<std::shared_ptr<Entry>> EntriesMap;
typedef std::vector<std::shared_ptr<Entry>> IdMap;
mutable std::mutex m_mutex;
EntriesMap m_entries;

View File

@@ -25,9 +25,9 @@ class StorageTest : public ::testing::TestWithParam<bool> {
Storage::EntriesMap& entries() { return storage.m_entries; }
Storage::IdMap& idmap() { return storage.m_idmap; }
std::shared_ptr<StorageEntry> GetEntry(StringRef name) {
std::shared_ptr<Storage::Entry> GetEntry(StringRef name) {
auto i = storage.m_entries.find(name);
return i == storage.m_entries.end() ? std::make_shared<StorageEntry>(name)
return i == storage.m_entries.end() ? std::make_shared<Storage::Entry>(name)
: i->getValue();
}
struct OutgoingData {
@@ -118,11 +118,11 @@ TEST_P(StorageTest, Construct) {
TEST_P(StorageTest, StorageEntryInit) {
auto entry = GetEntry("foo");
EXPECT_FALSE(entry->value());
EXPECT_EQ(0u, entry->flags());
EXPECT_EQ("foo", entry->name());
EXPECT_EQ(0xffffu, entry->id());
EXPECT_EQ(SequenceNumber(), entry->seq_num());
EXPECT_FALSE(entry->value);
EXPECT_EQ(0u, entry->flags);
EXPECT_EQ("foo", entry->name);
EXPECT_EQ(0xffffu, entry->id);
EXPECT_EQ(SequenceNumber(), entry->seq_num);
}
TEST_P(StorageTest, GetEntryValueNotExist) {
@@ -143,10 +143,10 @@ TEST_P(StorageTest, SetEntryTypeValueAssignNew) {
// brand new entry
auto value = Value::MakeBoolean(true);
storage.SetEntryTypeValue("foo", value);
EXPECT_EQ(value, GetEntry("foo")->value());
EXPECT_EQ(value, GetEntry("foo")->value);
if (GetParam()) {
ASSERT_EQ(1u, idmap().size());
EXPECT_EQ(value, idmap()[0]->value());
EXPECT_EQ(value, idmap()[0]->value);
} else {
EXPECT_TRUE(idmap().empty());
}
@@ -170,7 +170,7 @@ TEST_P(StorageTestPopulateOne, SetEntryTypeValueAssignTypeChange) {
// update with different type results in assignment message
auto value = Value::MakeDouble(0.0);
storage.SetEntryTypeValue("foo", value);
EXPECT_EQ(value, GetEntry("foo")->value());
EXPECT_EQ(value, GetEntry("foo")->value);
ASSERT_EQ(1u, outgoing.size());
EXPECT_FALSE(outgoing[0].only);
@@ -192,7 +192,7 @@ TEST_P(StorageTestPopulateOne, SetEntryTypeValueEqualValue) {
// message is issued (minimizing bandwidth usage)
auto value = Value::MakeBoolean(true);
storage.SetEntryTypeValue("foo", value);
EXPECT_EQ(value, GetEntry("foo")->value());
EXPECT_EQ(value, GetEntry("foo")->value);
EXPECT_TRUE(outgoing.empty());
}
@@ -200,7 +200,7 @@ TEST_P(StorageTestPopulated, SetEntryTypeValueDifferentValue) {
// update with same type and different value results in value update message
auto value = Value::MakeDouble(1.0);
storage.SetEntryTypeValue("foo2", value);
EXPECT_EQ(value, GetEntry("foo2")->value());
EXPECT_EQ(value, GetEntry("foo2")->value);
if (GetParam()) {
ASSERT_EQ(1u, outgoing.size());
@@ -214,7 +214,7 @@ TEST_P(StorageTestPopulated, SetEntryTypeValueDifferentValue) {
} else {
// shouldn't send an update id not assigned yet (happens on client only)
EXPECT_TRUE(outgoing.empty());
EXPECT_EQ(2u, GetEntry("foo2")->seq_num().value()); // still should be incremented
EXPECT_EQ(2u, GetEntry("foo2")->seq_num.value()); // still should be incremented
}
}
@@ -237,7 +237,7 @@ TEST_P(StorageTest, SetEntryValueAssignNew) {
// brand new entry
auto value = Value::MakeBoolean(true);
EXPECT_TRUE(storage.SetEntryValue("foo", value));
EXPECT_EQ(value, GetEntry("foo")->value());
EXPECT_EQ(value, GetEntry("foo")->value);
ASSERT_EQ(1u, outgoing.size());
EXPECT_FALSE(outgoing[0].only);
@@ -259,7 +259,7 @@ TEST_P(StorageTestPopulateOne, SetEntryValueAssignTypeChange) {
auto value = Value::MakeDouble(0.0);
EXPECT_FALSE(storage.SetEntryValue("foo", value));
auto entry = GetEntry("foo");
EXPECT_NE(value, entry->value());
EXPECT_NE(value, entry->value);
EXPECT_TRUE(outgoing.empty());
}
@@ -269,7 +269,7 @@ TEST_P(StorageTestPopulateOne, SetEntryValueEqualValue) {
auto value = Value::MakeBoolean(true);
EXPECT_TRUE(storage.SetEntryValue("foo", value));
auto entry = GetEntry("foo");
EXPECT_EQ(value, entry->value());
EXPECT_EQ(value, entry->value);
EXPECT_TRUE(outgoing.empty());
}
@@ -278,7 +278,7 @@ TEST_P(StorageTestPopulated, SetEntryValueDifferentValue) {
auto value = Value::MakeDouble(1.0);
EXPECT_TRUE(storage.SetEntryValue("foo2", value));
auto entry = GetEntry("foo2");
EXPECT_EQ(value, entry->value());
EXPECT_EQ(value, entry->value);
if (GetParam()) {
ASSERT_EQ(1u, outgoing.size());
@@ -292,7 +292,7 @@ TEST_P(StorageTestPopulated, SetEntryValueDifferentValue) {
} else {
// shouldn't send an update id not assigned yet (happens on client only)
EXPECT_TRUE(outgoing.empty());
EXPECT_EQ(2u, GetEntry("foo2")->seq_num().value()); // still should be incremented
EXPECT_EQ(2u, GetEntry("foo2")->seq_num.value()); // still should be incremented
}
}
@@ -324,14 +324,14 @@ TEST_P(StorageTestPopulateOne, SetEntryFlagsEqualValue) {
// usage)
storage.SetEntryFlags("foo", 0u);
auto entry = GetEntry("foo");
EXPECT_EQ(0u, entry->flags());
EXPECT_EQ(0u, entry->flags);
EXPECT_TRUE(outgoing.empty());
}
TEST_P(StorageTestPopulated, SetEntryFlagsDifferentValue) {
// update with different value results in flags update message
storage.SetEntryFlags("foo2", 1u);
EXPECT_EQ(1u, GetEntry("foo2")->flags());
EXPECT_EQ(1u, GetEntry("foo2")->flags);
if (GetParam()) {
ASSERT_EQ(1u, outgoing.size());
@@ -460,7 +460,7 @@ TEST_P(StorageTestPersistent, SavePersistentEmpty) {
}
TEST_P(StorageTestPersistent, SavePersistent) {
for (auto& i : entries()) i.getValue()->set_flags(NT_PERSISTENT);
for (auto& i : entries()) i.getValue()->flags = NT_PERSISTENT;
std::ostringstream oss;
storage.SavePersistent(oss);
std::string out = oss.str();
@@ -566,8 +566,8 @@ TEST_P(StorageTest, LoadPersistentAssign) {
"[NetworkTables Storage 3.0]\nboolean \"foo\"=true\n");
EXPECT_TRUE(storage.LoadPersistent(iss, warn_func));
auto entry = GetEntry("foo");
EXPECT_EQ(*Value::MakeBoolean(true), *entry->value());
EXPECT_EQ(NT_PERSISTENT, entry->flags());
EXPECT_EQ(*Value::MakeBoolean(true), *entry->value);
EXPECT_EQ(NT_PERSISTENT, entry->flags);
ASSERT_EQ(1u, outgoing.size());
EXPECT_FALSE(outgoing[0].only);
@@ -593,8 +593,8 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateFlags) {
"[NetworkTables Storage 3.0]\ndouble \"foo2\"=0.0\n");
EXPECT_TRUE(storage.LoadPersistent(iss, warn_func));
auto entry = GetEntry("foo2");
EXPECT_EQ(*Value::MakeDouble(0.0), *entry->value());
EXPECT_EQ(NT_PERSISTENT, entry->flags());
EXPECT_EQ(*Value::MakeDouble(0.0), *entry->value);
EXPECT_EQ(NT_PERSISTENT, entry->flags);
if (GetParam()) {
ASSERT_EQ(1u, outgoing.size());
@@ -615,14 +615,14 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateValue) {
auto warn_func =
[&](std::size_t line, const char* msg) { warn.Warn(line, msg); };
GetEntry("foo2")->set_flags(NT_PERSISTENT);
GetEntry("foo2")->flags = NT_PERSISTENT;
std::istringstream iss(
"[NetworkTables Storage 3.0]\ndouble \"foo2\"=1.0\n");
EXPECT_TRUE(storage.LoadPersistent(iss, warn_func));
auto entry = GetEntry("foo2");
EXPECT_EQ(*Value::MakeDouble(1.0), *entry->value());
EXPECT_EQ(NT_PERSISTENT, entry->flags());
EXPECT_EQ(*Value::MakeDouble(1.0), *entry->value);
EXPECT_EQ(NT_PERSISTENT, entry->flags);
if (GetParam()) {
ASSERT_EQ(1u, outgoing.size());
@@ -636,7 +636,7 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateValue) {
} else {
// shouldn't send an update id not assigned yet (happens on client only)
EXPECT_TRUE(outgoing.empty());
EXPECT_EQ(2u, GetEntry("foo2")->seq_num().value()); // still should be incremented
EXPECT_EQ(2u, GetEntry("foo2")->seq_num.value()); // still should be incremented
}
}
@@ -649,8 +649,8 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateValueFlags) {
"[NetworkTables Storage 3.0]\ndouble \"foo2\"=1.0\n");
EXPECT_TRUE(storage.LoadPersistent(iss, warn_func));
auto entry = GetEntry("foo2");
EXPECT_EQ(*Value::MakeDouble(1.0), *entry->value());
EXPECT_EQ(NT_PERSISTENT, entry->flags());
EXPECT_EQ(*Value::MakeDouble(1.0), *entry->value);
EXPECT_EQ(NT_PERSISTENT, entry->flags);
if (GetParam()) {
ASSERT_EQ(2u, outgoing.size());
@@ -671,7 +671,7 @@ TEST_P(StorageTestPopulated, LoadPersistentUpdateValueFlags) {
} else {
// shouldn't send an update id not assigned yet (happens on client only)
EXPECT_TRUE(outgoing.empty());
EXPECT_EQ(2u, GetEntry("foo2")->seq_num().value()); // still should be incremented
EXPECT_EQ(2u, GetEntry("foo2")->seq_num.value()); // still should be incremented
}
}