Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 30f5c4c

Browse files
authored
Merge pull request #478 from cloudant/add-partition-index-meta
Add partition Index count to db info response.
2 parents bed31fc + fa25318 commit 30f5c4c

4 files changed

Lines changed: 178 additions & 10 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# UNRELEASED
2+
- [NEW] Added database partition metadata fields for partitioned index count/limit.
3+
14
# 2.15.0 (2019-02-12)
25
- [NEW] Added option for client to authenticate with IAM token server.
36
- [NEW] Added partitioned database support.

cloudant-client/findbugs_excludes.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ For example because it requires an API change
120120
</Match>
121121
<Match>
122122
<Bug code="UwF" pattern="UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"/>
123-
<Class name="com.cloudant.client.api.model.PartitionInfo$Sizes"/>
124-
<Field name="active"/>
123+
<Class name="com.cloudant.client.api.model.DbInfo$PartitionedIndexes"/>
124+
125+
</Match>
126+
<Match>
127+
<Bug code="UwF" pattern="UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"/>
128+
<Class name="com.cloudant.client.api.model.DbInfo$PartitionedIndexes$Indexes"/>
129+
125130
</Match>
126131
<Match>
127132
<Bug code="UwF" pattern="UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"/>
128133
<Class name="com.cloudant.client.api.model.PartitionInfo$Sizes"/>
129-
<Field name="external"/>
130134
</Match>
131135

132136
<!-- This is likely a false positive in Findbugs, the IDE doesn't complain an unchecked cast.

cloudant-client/src/main/java/com/cloudant/client/api/model/DbInfo.java

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,76 @@
2626
*/
2727
public class DbInfo {
2828

29+
/**
30+
* Encapsulates partitioned index properties.
31+
*/
32+
public static class PartitionedIndexes {
33+
34+
/**
35+
* Encapsulates index properties.
36+
*/
37+
public static class Indexes {
38+
39+
private long search;
40+
private long view;
41+
42+
43+
/**
44+
* Get a count of the partitioned search indexes.
45+
*
46+
* @return The partitioned search index count.
47+
*/
48+
public long getSearch() {
49+
return search;
50+
}
51+
52+
53+
/**
54+
* Get a count of the partitioned view indexes.
55+
*
56+
* @return The partitioned view index count.
57+
*/
58+
public long getView() {
59+
return view;
60+
}
61+
62+
}
63+
64+
private long count;
65+
private long limit;
66+
private Indexes indexes;
67+
68+
/**
69+
* Get a total count of the partitioned indexes.
70+
*
71+
* @return The total partitioned index count.
72+
*/
73+
public long getCount() {
74+
return count;
75+
}
76+
77+
/**
78+
* Get the partitioned index limit.
79+
*
80+
* @return The partitioned index limit.
81+
*/
82+
public long getLimit() {
83+
return limit;
84+
}
85+
86+
/**
87+
* Get the {@link com.cloudant.client.api.model.DbInfo.PartitionedIndexes.Indexes} object
88+
* for this database.
89+
*
90+
* @return The {@link com.cloudant.client.api.model.DbInfo.PartitionedIndexes.Indexes}
91+
* object, containing the count breakdown of partitioned indexes.
92+
*/
93+
public Indexes getIndexes() {
94+
return indexes;
95+
}
96+
97+
}
98+
2999
/**
30100
* Encapsulates database properties.
31101
*/
@@ -62,6 +132,8 @@ public boolean getPartitioned() {
62132
@SerializedName("disk_format_version")
63133
private int diskFormatVersion;
64134
private Props props;
135+
@SerializedName("partitioned_indexes")
136+
private PartitionedIndexes partitionedIndexes;
65137

66138
public String getDbName() {
67139
return dbName;
@@ -137,15 +209,51 @@ public Props getProps() {
137209
return props;
138210
}
139211

212+
/**
213+
* Get the {@link com.cloudant.client.api.model.DbInfo.PartitionedIndexes} object for
214+
* this database.
215+
*
216+
* @return The {@link com.cloudant.client.api.model.DbInfo.PartitionedIndexes} object,
217+
* containing metadata about partitioned indexes in this database.
218+
*/
219+
public PartitionedIndexes getPartitionedIndexes() {
220+
return partitionedIndexes;
221+
}
222+
140223
@Override
141224
public String toString() {
142-
return String
143-
.format("CouchDbInfo [dbName=%s, docCount=%s, docDelCount=%s, updateSeq=%s, " +
144-
"purgeSeq=%s, compactRunning=%s, diskSize=%s, instanceStartTime=%s, diskFormatVersion=%s]",
145-
dbName, docCount, docDelCount, updateSeq, purgeSeq,
146-
compactRunning, diskSize, instanceStartTime,
147-
diskFormatVersion);
148-
}
225+
StringBuilder sb = new StringBuilder();
226+
sb
227+
.append("CouchDbInfo [")
228+
.append("dbName=").append(dbName)
229+
.append(", docCount=").append(docCount)
230+
.append(", docDelCount=").append(docDelCount)
231+
.append(", updateSeq=").append(updateSeq)
232+
.append(", purgeSeq=").append(purgeSeq)
233+
.append(", compactRunning=").append(compactRunning)
234+
.append(", diskSize=").append(diskSize)
235+
.append(", instanceStartTime=").append(instanceStartTime)
236+
.append(", diskFormatVersion=").append(diskFormatVersion);
237+
238+
if (this.getProps() != null) {
239+
sb.append(", props.partitioned=").append(this.getProps().getPartitioned());
240+
}
241+
242+
if (this.getPartitionedIndexes() != null) {
243+
sb
244+
.append(", partitionedIndexes.count=")
245+
.append(this.getPartitionedIndexes().getCount())
246+
.append(", partitionedIndexes.limit=")
247+
.append(this.getPartitionedIndexes().getLimit())
248+
.append(", partitionedIndexes.indexes.search=")
249+
.append(this.getPartitionedIndexes().getIndexes().getSearch())
250+
.append(", partitionedIndexes.indexes.view=")
251+
.append(this.getPartitionedIndexes().getIndexes().getView());
252+
}
149253

254+
sb.append("]");
255+
256+
return sb.toString();
257+
}
150258

151259
}

cloudant-client/src/test/java/com/cloudant/tests/DbInfoMockTests.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,57 @@ public void getDbInfoStringPurgeSeqAsString() {
8383

8484
assertEquals(mockPurgeSeq, db.info().getStringPurgeSeq());
8585
}
86+
87+
@Test
88+
public void getDbPartitionPartitionedIndexesCount() {
89+
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
90+
Database db = c.database("animaldb", false);
91+
92+
MockResponse response = new MockResponse()
93+
.setResponseCode(200)
94+
.setBody("{\"partitioned_indexes\":{\"count\":9}}");
95+
server.enqueue(response);
96+
97+
assertEquals(9, db.info().getPartitionedIndexes().getCount());
98+
}
99+
100+
@Test
101+
public void getDbPartitionPartitionedIndexesLimit() {
102+
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
103+
Database db = c.database("animaldb", false);
104+
105+
MockResponse response = new MockResponse()
106+
.setResponseCode(200)
107+
.setBody("{\"partitioned_indexes\":{\"limit\":10}}");
108+
server.enqueue(response);
109+
110+
assertEquals(10, db.info().getPartitionedIndexes().getLimit());
111+
}
112+
113+
@Test
114+
public void getDbPartitionPartitionedIndexesIndexesSearch() {
115+
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
116+
Database db = c.database("animaldb", false);
117+
118+
MockResponse response = new MockResponse()
119+
.setResponseCode(200)
120+
.setBody("{\"partitioned_indexes\":{\"indexes\":{\"search\":3}}}");
121+
server.enqueue(response);
122+
123+
assertEquals(3, db.info().getPartitionedIndexes().getIndexes().getSearch());
124+
}
125+
126+
@Test
127+
public void getDbPartitionPartitionedIndexesIndexesView() {
128+
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
129+
Database db = c.database("animaldb", false);
130+
131+
MockResponse response = new MockResponse()
132+
.setResponseCode(200)
133+
.setBody("{\"partitioned_indexes\":{\"indexes\":{\"view\":6}}}");
134+
server.enqueue(response);
135+
136+
assertEquals(6, db.info().getPartitionedIndexes().getIndexes().getView());
137+
}
138+
86139
}

0 commit comments

Comments
 (0)