Skip to content

Commit

Permalink
network filter: fix upstream host storage (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Klein authored Aug 10, 2016
1 parent 3285c1a commit 2eef417
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/common/network/filter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class FilterManager {

Connection& connection() override { return parent_.connection_; }
void continueReading() override { parent_.onContinueReading(this); }
Upstream::HostDescriptionPtr upstreamHost() override { return host_description_; }
void upstreamHost(Upstream::HostDescriptionPtr host) override { host_description_ = host; }
Upstream::HostDescriptionPtr upstreamHost() override { return parent_.host_description_; }
void upstreamHost(Upstream::HostDescriptionPtr host) override {
parent_.host_description_ = host;
}

FilterManager& parent_;
ReadFilterPtr filter_;
Upstream::HostDescriptionPtr host_description_;
};

typedef std::unique_ptr<ActiveReadFilter> ActiveReadFilterPtr;
Expand All @@ -62,6 +63,7 @@ class FilterManager {
BufferSource& buffer_source_;
std::list<ActiveReadFilterPtr> upstream_filters_;
std::list<WriteFilterPtr> downstream_filters_;
Upstream::HostDescriptionPtr host_description_;
};

} // Network
5 changes: 5 additions & 0 deletions test/common/network/filter_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "test/mocks/buffer/mocks.h"
#include "test/mocks/network/mocks.h"
#include "test/mocks/upstream/host.h"

using testing::InSequence;
using testing::Return;
Expand Down Expand Up @@ -30,6 +31,10 @@ TEST_F(NetworkFilterManagerTest, All) {
manager.addWriteFilter(write_filter);
manager.addFilter(filter);

Upstream::HostDescriptionPtr host_description(new Upstream::MockHostDescription());
read_filter->callbacks_->upstreamHost(host_description);
EXPECT_EQ(read_filter->callbacks_->upstreamHost(), filter->callbacks_->upstreamHost());

read_buffer_.add("hello");
EXPECT_CALL(*read_filter, onData(BufferStringEqual("hello")))
.WillOnce(Return(FilterStatus::StopIteration));
Expand Down
2 changes: 2 additions & 0 deletions test/mocks/upstream/host.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "envoy/upstream/upstream.h"

namespace Upstream {

class MockHostDescription : public HostDescription {
Expand Down

0 comments on commit 2eef417

Please sign in to comment.