Skip to content

Commit deae887

Browse files
authored
update GetBukcetStatResult for more bucket states (#120)
* update GetBukcetStatResult for more bucket states * update GetBukcetStatResult last modify time to int
1 parent 0f3fc2b commit deae887

File tree

3 files changed

+132
-16
lines changed

3 files changed

+132
-16
lines changed

sdk/include/alibabacloud/oss/model/GetBucketStatResult.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,10 +33,31 @@ namespace OSS
3333
uint64_t Storage() const { return storage_; }
3434
uint64_t ObjectCount() const { return objectCount_; }
3535
uint64_t MultipartUploadCount() const { return multipartUploadCount_; }
36+
uint64_t LiveChannelCount() const { return liveChannelCount_; }
37+
uint64_t LastModifiedTime() const { return lastModifiedTime_; }
38+
uint64_t StandardStorage() const { return standardStorage_; }
39+
uint64_t StandardObjectCount() const { return standardObjectCount_; }
40+
uint64_t InfrequentAccessStorage() const { return infrequentAccessStorage_; }
41+
uint64_t InfrequentAccessObjectCount() const { return infrequentAccessObjectCount_; }
42+
uint64_t ArchiveStorage() const { return archiveStorage_; }
43+
uint64_t ArchiveObjectCount() const { return archiveObjectCount_; }
44+
uint64_t ColdArchiveStorage() const { return coldArchiveStorage_; }
45+
uint64_t ColdArchiveObjectCount() const { return coldArchiveObjectCount_; }
46+
3647
private:
3748
uint64_t storage_;
3849
uint64_t objectCount_;
3950
uint64_t multipartUploadCount_;
51+
uint64_t liveChannelCount_;
52+
uint64_t lastModifiedTime_;
53+
uint64_t standardStorage_;
54+
uint64_t standardObjectCount_;
55+
uint64_t infrequentAccessStorage_;
56+
uint64_t infrequentAccessObjectCount_;
57+
uint64_t archiveStorage_;
58+
uint64_t archiveObjectCount_;
59+
uint64_t coldArchiveStorage_;
60+
uint64_t coldArchiveObjectCount_;
4061
};
41-
}
62+
}
4263
}

sdk/src/model/GetBucketStatResult.cc

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,17 @@ GetBucketStatResult::GetBucketStatResult() :
2626
OssResult(),
2727
storage_(0),
2828
objectCount_(0),
29-
multipartUploadCount_(0)
29+
multipartUploadCount_(0),
30+
liveChannelCount_(0),
31+
lastModifiedTime_(0),
32+
standardStorage_(0),
33+
standardObjectCount_(0),
34+
infrequentAccessStorage_(0),
35+
infrequentAccessObjectCount_(0),
36+
archiveStorage_(0),
37+
archiveObjectCount_(0),
38+
coldArchiveStorage_(0),
39+
coldArchiveObjectCount_(0)
3040
{
3141
}
3242

@@ -61,7 +71,38 @@ GetBucketStatResult& GetBucketStatResult::operator =(const std::string& result)
6171
node = root->FirstChildElement("MultipartUploadCount");
6272
if (node && node->GetText()) multipartUploadCount_ = atoll(node->GetText());
6373

74+
node = root->FirstChildElement("LiveChannelCount");
75+
if (node && node->GetText()) liveChannelCount_ = atoll(node->GetText());
76+
77+
node = root->FirstChildElement("LastModifiedTime");
78+
if (node && node->GetText()) lastModifiedTime_ = atoll(node->GetText());
79+
80+
node = root->FirstChildElement("StandardStorage");
81+
if (node && node->GetText()) standardStorage_ = atoll(node->GetText());
82+
83+
node = root->FirstChildElement("StandardObjectCount");
84+
if (node && node->GetText()) standardObjectCount_ = atoll(node->GetText());
85+
86+
node = root->FirstChildElement("InfrequentAccessStorage");
87+
if (node && node->GetText()) infrequentAccessStorage_ = atoll(node->GetText());
88+
89+
node = root->FirstChildElement("InfrequentAccessObjectCount");
90+
if (node && node->GetText()) infrequentAccessObjectCount_ = atoll(node->GetText());
91+
92+
node = root->FirstChildElement("ArchiveStorage");
93+
if (node && node->GetText()) archiveStorage_ = atoll(node->GetText());
94+
95+
node = root->FirstChildElement("ArchiveObjectCount");
96+
if (node && node->GetText()) archiveObjectCount_ = atoll(node->GetText());
97+
98+
node = root->FirstChildElement("ColdArchiveStorage");
99+
if (node && node->GetText()) coldArchiveStorage_ = atoll(node->GetText());
100+
101+
node = root->FirstChildElement("ColdArchiveObjectCount");
102+
if (node && node->GetText()) coldArchiveObjectCount_ = atoll(node->GetText());
103+
64104
parseDone_ = true;
105+
65106
}
66107
}
67108
return *this;

test/src/Bucket/BucketBasicOperationTest.cc

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class BucketBasicOperationTest : public ::testing::Test {
3333
}
3434

3535
// Sets up the stuff shared by all tests in this test case.
36-
static void SetUpTestCase()
36+
static void SetUpTestCase()
3737
{
3838
Client = std::make_shared<OssClient>(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration());
3939
}
4040

4141
// Tears down the stuff shared by all tests in this test case.
42-
static void TearDownTestCase()
42+
static void TearDownTestCase()
4343
{
4444
Client = nullptr;
4545
}
@@ -210,7 +210,7 @@ TEST_F(BucketBasicOperationTest, GetBucketInfoTest)
210210
auto bfOutcome = Client->GetBucketInfo(request);
211211
EXPECT_EQ(bfOutcome.isSuccess(), true);
212212
EXPECT_EQ(bfOutcome.result().Acl(), CannedAccessControlList::Private);
213-
213+
214214
Client->SetBucketAcl(SetBucketAclRequest(bucketName, CannedAccessControlList::PublicRead));
215215
TestUtils::WaitForCacheExpire(5);
216216
bfOutcome = Client->GetBucketInfo(request);
@@ -505,6 +505,42 @@ TEST_F(BucketBasicOperationTest, GetBucketStatResult)
505505
EXPECT_EQ(result.Storage(), 1024123ULL);
506506
}
507507

508+
TEST_F(BucketBasicOperationTest, GetBucketStatResultEnhancedTest)
509+
{
510+
std::string xml = R"(<?xml version="1.0" encoding="UTF-8"?>
511+
<BucketStat>
512+
<Storage>1600</Storage>
513+
<ObjectCount>230</ObjectCount>
514+
<MultipartUploadCount>40</MultipartUploadCount>
515+
<LiveChannelCount>4</LiveChannelCount>
516+
<LastModifiedTime>153221331</LastModifiedTime>
517+
<StandardStorage>430</StandardStorage>
518+
<StandardObjectCount>66</StandardObjectCount>
519+
<InfrequentAccessStorage>2359296</InfrequentAccessStorage>
520+
<InfrequentAccessObjectCount>54</InfrequentAccessObjectCount>
521+
<ArchiveStorage>2949120</ArchiveStorage>
522+
<ArchiveObjectCount>74</ArchiveObjectCount>
523+
<ColdArchiveStorage>2359296</ColdArchiveStorage>
524+
<ColdArchiveObjectCount>36</ColdArchiveObjectCount>
525+
</BucketStat>)";
526+
527+
GetBucketStatResult result(xml);
528+
EXPECT_EQ(result.MultipartUploadCount(), 40ULL);
529+
EXPECT_EQ(result.ObjectCount(), 230ULL);
530+
EXPECT_EQ(result.Storage(), 1600ULL);
531+
EXPECT_EQ(result.LiveChannelCount(), 4ULL);
532+
EXPECT_EQ(result.LastModifiedTime(), 153221331ULL);
533+
EXPECT_EQ(result.StandardStorage(), 430ULL);
534+
EXPECT_EQ(result.StandardObjectCount(), 66ULL);
535+
EXPECT_EQ(result.InfrequentAccessStorage(), 2359296ULL);
536+
EXPECT_EQ(result.InfrequentAccessObjectCount(), 54ULL);
537+
EXPECT_EQ(result.ArchiveStorage(), 2949120ULL);
538+
EXPECT_EQ(result.ArchiveObjectCount(), 74ULL);
539+
EXPECT_EQ(result.ColdArchiveStorage(), 2359296ULL);
540+
EXPECT_EQ(result.ColdArchiveObjectCount(), 36ULL);
541+
}
542+
543+
508544
TEST_F(BucketBasicOperationTest, GetBucketLocationResult)
509545
{
510546
std::string xml = R"(<?xml version="1.0" encoding="UTF-8"?>
@@ -792,6 +828,24 @@ TEST_F(BucketBasicOperationTest, GetBucketInfoResultBranchTest)
792828

793829
xml = R"(<?xml version="1.0" encoding="UTF-8"?>)";
794830
GetBucketStatResult result15(xml);
831+
832+
xml = R"(<?xml version="1.0" encoding="UTF-8"?>
833+
<BucketStat>
834+
<Storage></Storage>
835+
<ObjectCount></ObjectCount>
836+
<MultipartUploadCount></MultipartUploadCount>
837+
<LiveChannelCount></LiveChannelCount>
838+
<LastModifiedTime></LastModifiedTime>
839+
<StandardStorage></StandardStorage>
840+
<StandardObjectCount></StandardObjectCount>
841+
<InfrequentAccessStorage></InfrequentAccessStorage>
842+
<InfrequentAccessObjectCount></InfrequentAccessObjectCount>
843+
<ArchiveStorage></ArchiveStorage>
844+
<ArchiveObjectCount></ArchiveObjectCount>
845+
<ColdArchiveStorage></ColdArchiveStorage>
846+
<ColdArchiveObjectCount></ColdArchiveObjectCount>
847+
</BucketStat>)";
848+
GetBucketStatResult result16(xml);
795849
}
796850

797851
TEST_F(BucketBasicOperationTest, ListBucketsResultBranchTest)
@@ -800,7 +854,7 @@ TEST_F(BucketBasicOperationTest, ListBucketsResultBranchTest)
800854

801855
std::string xml = R"(<?xml version="1.0" encoding="UTF-8"?>
802856
<ListAllMyBuckets>
803-
857+
804858
</ListAllMyBuckets>)";
805859
ListBucketsResult result1(xml);
806860

@@ -828,9 +882,9 @@ TEST_F(BucketBasicOperationTest, ListBucketsResultBranchTest)
828882
</Owner>
829883
<Buckets>
830884
<Bucket>
831-
885+
832886
</Bucket>
833-
887+
834888
</Buckets>
835889
</ListAllMyBucketsResult>)";
836890
ListBucketsResult result4(xml);
@@ -856,7 +910,7 @@ TEST_F(BucketBasicOperationTest, ListBucketsResultBranchTest)
856910
<Name></Name>
857911
<StorageClass></StorageClass>
858912
</Bucket>
859-
913+
860914
</Buckets>
861915
</ListAllMyBucketsResult>)";
862916
ListBucketsResult result5(xml);
@@ -867,7 +921,7 @@ TEST_F(BucketBasicOperationTest, ListBucketsResultBranchTest)
867921

868922
TEST_F(BucketBasicOperationTest, BucketColdArchiveTest)
869923
{
870-
std::string endpoint = "http://oss-ap-southeast-2.aliyuncs.com";
924+
std::string endpoint = "http://oss-ap-southeast-2.aliyuncs.com";
871925
auto client = std::make_shared<OssClient>(endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration());
872926

873927
//get a random bucketName

0 commit comments

Comments
 (0)