Skip to content

Commit f37fa20

Browse files
authored
Actually use LoggingClient. (#950)
The storage::Client was supposed to create a chain of decorated RawClient objects: RetryClient -> LoggingClient -> CurlClient. Somehow I dropped LoggingClient from the chain, created a test and fixed the problem.
1 parent eb54d8b commit f37fa20

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

google/cloud/storage/client.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H_
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H_
1717

18-
#include "google/cloud/storage/internal/raw_client.h"
18+
#include "google/cloud/storage/internal/logging_client.h"
1919
#include "google/cloud/storage/internal/retry_client.h"
2020
#include "google/cloud/storage/list_buckets_reader.h"
2121
#include "google/cloud/storage/list_objects_reader.h"
@@ -28,7 +28,7 @@ inline namespace STORAGE_CLIENT_NS {
2828
/**
2929
* The Google Cloud Storage Client.
3030
*
31-
* @warning this implementation is incomplete, we are still prototyping.
31+
* @warning this implementation is incomplete.
3232
*/
3333
class Client {
3434
public:
@@ -52,12 +52,12 @@ class Client {
5252
template <typename... Policies>
5353
explicit Client(std::shared_ptr<internal::RawClient> client,
5454
Policies&&... policies)
55-
: raw_client_(new internal::RetryClient(
56-
std::move(client), std::forward<Policies>(policies)...)) {}
55+
: raw_client_(
56+
Decorate(std::move(client), std::forward<Policies>(policies)...)) {}
5757

58-
/// Build a client with an specific RawClient, without retry policies.
59-
struct NoRetry {};
60-
explicit Client(std::shared_ptr<internal::RawClient> client, NoRetry)
58+
/// Build a client with an specific RawClient, without decorations.
59+
struct NoDecorations {};
60+
explicit Client(std::shared_ptr<internal::RawClient> client, NoDecorations)
6161
: raw_client_(std::move(client)) {}
6262

6363
/**
@@ -385,13 +385,26 @@ class Client {
385385
return raw_client_->UpdateObjectAcl(request).second;
386386
}
387387

388+
std::shared_ptr<internal::RawClient> raw_client() const {
389+
return raw_client_;
390+
}
391+
388392
private:
389393
BucketMetadata GetBucketMetadataImpl(
390394
internal::GetBucketMetadataRequest const& request);
391395

392396
ObjectMetadata InsertObjectMediaImpl(
393397
internal::InsertObjectMediaRequest const& request);
394398

399+
template <typename... Policies>
400+
std::shared_ptr<internal::RawClient> Decorate(
401+
std::shared_ptr<internal::RawClient> client, Policies&&... policies) {
402+
auto logging = std::make_shared<internal::LoggingClient>(std::move(client));
403+
auto retry = std::make_shared<internal::RetryClient>(
404+
std::move(logging), std::forward<Policies>(policies)...);
405+
return retry;
406+
}
407+
395408
private:
396409
std::shared_ptr<internal::RawClient> raw_client_;
397410
};

google/cloud/storage/client_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/client.h"
16+
#include "google/cloud/storage/internal/curl_client.h"
1617
#include "google/cloud/storage/retry_policy.h"
1718
#include "google/cloud/storage/testing/canonical_errors.h"
1819
#include "google/cloud/storage/testing/mock_client.h"
@@ -125,6 +126,23 @@ TEST_F(ClientTest, OverrideBothPolicies) {
125126
EXPECT_LE(1, ObservableBackoffPolicy::on_completion_call_count);
126127
}
127128

129+
/// @test Verify the constructor creates the right set of RawClient decorations.
130+
TEST_F(ClientTest, DefaultDecorators) {
131+
// Create a client, use the insecure credentials because on the CI environment
132+
// there may not be other credentials configured.
133+
Client tested(CreateInsecureCredentials());
134+
135+
EXPECT_TRUE(tested.raw_client() != nullptr);
136+
auto retry = dynamic_cast<internal::RetryClient*>(tested.raw_client().get());
137+
ASSERT_TRUE(retry != nullptr);
138+
139+
auto logging = dynamic_cast<internal::LoggingClient*>(retry->client().get());
140+
ASSERT_TRUE(logging != nullptr);
141+
142+
auto curl = dynamic_cast<internal::CurlClient*>(logging->client().get());
143+
ASSERT_TRUE(curl != nullptr);
144+
}
145+
128146
} // namespace
129147
} // namespace STORAGE_CLIENT_NS
130148
} // namespace storage

google/cloud/storage/internal/logging_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class LoggingClient : public RawClient {
6767
std::pair<Status, ObjectAccessControl> UpdateObjectAcl(
6868
UpdateObjectAclRequest const&) override;
6969

70+
std::shared_ptr<RawClient> client() const { return client_; }
71+
7072
private:
7173
std::shared_ptr<RawClient> client_;
7274
};

google/cloud/storage/internal/retry_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class RetryClient : public RawClient {
7777
std::pair<Status, ObjectAccessControl> UpdateObjectAcl(
7878
UpdateObjectAclRequest const&) override;
7979

80+
std::shared_ptr<RawClient> client() const { return client_; }
81+
8082
private:
8183
void Apply(RetryPolicy& policy) { retry_policy_ = policy.clone(); }
8284

0 commit comments

Comments
 (0)