Skip to content

Commit

Permalink
runtime: changing snapshot access to be const (envoyproxy#7677) (#26)
Browse files Browse the repository at this point in the history
This is a precursor to envoyproxy#7601 just to land the API change more quickly and make sure it sticks.

Risk Level: Low
Testing: existing unit tests
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
  • Loading branch information
PiotrSikora authored and LukeShu committed Aug 9, 2019
1 parent 9af4885 commit 82067af
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions include/envoy/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ class Loader {
virtual void initialize(Upstream::ClusterManager& cm) PURE;

/**
* @return Snapshot& the current snapshot. This reference is safe to use for the duration of
* @return const Snapshot& the current snapshot. This reference is safe to use for the duration of
* the calling routine, but may be overwritten on a future event loop cycle so should be
* fetched again when needed.
*/
virtual Snapshot& snapshot() PURE;
virtual const Snapshot& snapshot() PURE;

/**
* Merge the given map of key-value pairs into the runtime's state. To remove a previous merge for
Expand Down
2 changes: 1 addition & 1 deletion source/common/runtime/runtime_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void LoaderImpl::loadNewSnapshot() {
});
}

Snapshot& LoaderImpl::snapshot() { return tls_->getTyped<Snapshot>(); }
const Snapshot& LoaderImpl::snapshot() { return tls_->getTyped<Snapshot>(); }

void LoaderImpl::mergeValues(const std::unordered_map<std::string, std::string>& values) {
if (admin_layer_ == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion source/common/runtime/runtime_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class LoaderImpl : public Loader, Logger::Loggable<Logger::Id::runtime> {

// Runtime::Loader
void initialize(Upstream::ClusterManager& cm) override;
Snapshot& snapshot() override;
const Snapshot& snapshot() override;
void mergeValues(const std::unordered_map<std::string, std::string>& values) override;

private:
Expand Down
4 changes: 2 additions & 2 deletions test/common/runtime/runtime_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ TEST_F(DiskLoaderImplTest, All) {
EXPECT_EQ(123UL, loader_->snapshot().getInteger("file4", 1));

bool value;
SnapshotImpl* snapshot = reinterpret_cast<SnapshotImpl*>(&loader_->snapshot());
const SnapshotImpl* snapshot = reinterpret_cast<const SnapshotImpl*>(&loader_->snapshot());

// Validate that the layer name is set properly for static layers.
EXPECT_EQ("base", snapshot->getLayers()[0]->name());
Expand Down Expand Up @@ -538,7 +538,7 @@ TEST_F(StaticLoaderImplTest, ProtoParsing) {

// Boolean getting.
bool value;
SnapshotImpl* snapshot = reinterpret_cast<SnapshotImpl*>(&loader_->snapshot());
const SnapshotImpl* snapshot = reinterpret_cast<const SnapshotImpl*>(&loader_->snapshot());

EXPECT_EQ(true, snapshot->getBoolean("file11", value));
EXPECT_EQ(true, value);
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/runtime/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MockLoader : public Loader {
~MockLoader();

MOCK_METHOD1(initialize, void(Upstream::ClusterManager& cm));
MOCK_METHOD0(snapshot, Snapshot&());
MOCK_METHOD0(snapshot, const Snapshot&());
MOCK_METHOD1(mergeValues, void(const std::unordered_map<std::string, std::string>&));

testing::NiceMock<MockSnapshot> snapshot_;
Expand Down

0 comments on commit 82067af

Please sign in to comment.