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

Commit 699f683

Browse files
authored
Merge pull request #482 from cloudant/481-deleted-count
481 deleted count
2 parents 42c4386 + c2483cc commit 699f683

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Unreleased
2+
- [NEW] Added `com.cloudant.client.api.model.DbInfo#getDocDelCountLong()` to return
3+
deleted document count as a `long` instead of a `String`.
4+
- [DEPRECATED] `com.cloudant.client.api.model.DbInfo#getDocDelCount()`.
5+
16
# 2.16.0 (2019-04-01)
27
- [NEW] Added database partition metadata fields for partitioned index count/limit.
38
- [NEW] Added replication selector support.

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public boolean getPartitioned() {
118118
@SerializedName("doc_count")
119119
private long docCount;
120120
@SerializedName("doc_del_count")
121-
private String docDelCount;
121+
private long docDelCount;
122122
@SerializedName("update_seq")
123123
private JsonElement updateSeq;
124124
@SerializedName("purge_seq")
@@ -143,7 +143,22 @@ public long getDocCount() {
143143
return docCount;
144144
}
145145

146+
/**
147+
*
148+
* @return string form of the number of deleted documents in the database
149+
*
150+
* @see DbInfo#getDocDelCountLong
151+
*/
152+
@Deprecated
146153
public String getDocDelCount() {
154+
return Long.toString(docDelCount);
155+
}
156+
157+
/**
158+
*
159+
* @return number of deleted documents in the database
160+
*/
161+
public long getDocDelCountLong() {
147162
return docDelCount;
148163
}
149164

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2018 IBM Corp. All rights reserved.
2+
* Copyright © 2018, 2019 IBM Corp. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
55
* except in compliance with the License. You may obtain a copy of the License at
@@ -18,6 +18,7 @@
1818

1919
import com.cloudant.client.api.CloudantClient;
2020
import com.cloudant.client.api.Database;
21+
import com.cloudant.client.api.model.DbInfo;
2122
import com.cloudant.tests.base.TestWithMockedServer;
2223

2324
import org.junit.jupiter.api.Test;
@@ -136,4 +137,19 @@ public void getDbPartitionPartitionedIndexesIndexesView() {
136137
assertEquals(6, db.info().getPartitionedIndexes().getIndexes().getView());
137138
}
138139

140+
@Test
141+
public void getDbInfoDocDelCount() {
142+
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
143+
Database db = c.database("animaldb", false);
144+
145+
MockResponse response = new MockResponse()
146+
.setResponseCode(200)
147+
.setBody("{\"doc_del_count\":7}");
148+
server.enqueue(response);
149+
150+
DbInfo info = db.info();
151+
assertEquals("7", info.getDocDelCount());
152+
assertEquals(7l, info.getDocDelCountLong());
153+
}
154+
139155
}

cloudant-client/src/test/java/com/cloudant/tests/extensions/MultiExtension.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2018 IBM Corp. All rights reserved.
2+
* Copyright © 2018, 2019 IBM Corp. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
55
* except in compliance with the License. You may obtain a copy of the License at
@@ -22,19 +22,29 @@
2222
import org.junit.jupiter.api.extension.Extension;
2323
import org.junit.jupiter.api.extension.ExtensionContext;
2424

25+
import java.util.ArrayList;
26+
import java.util.Arrays;
27+
import java.util.Collections;
28+
import java.util.List;
29+
2530
public class MultiExtension implements Extension, AfterAllCallback, AfterEachCallback,
2631
AfterTestExecutionCallback, BeforeAllCallback, BeforeEachCallback,
2732
BeforeTestExecutionCallback {
2833

29-
private final Extension[] extensions;
34+
private final List<Extension> extensions;
35+
private final List<Extension> reversedExtensions;
3036

3137
public MultiExtension(Extension... extensions) {
32-
this.extensions = extensions;
38+
this.extensions = Arrays.asList(extensions);
39+
// After tests we need to call extensions in the reverse order
40+
this.reversedExtensions = new ArrayList<>(this.extensions.size());
41+
this.reversedExtensions.addAll(this.extensions);
42+
Collections.reverse(reversedExtensions);
3343
}
3444

3545
@Override
3646
public void afterAll(ExtensionContext extensionContext) throws Exception {
37-
for (Extension extension : extensions) {
47+
for (Extension extension : reversedExtensions) {
3848
if (extension instanceof AfterAllCallback) {
3949
((AfterAllCallback) extension).afterAll(extensionContext);
4050
}
@@ -43,7 +53,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception {
4353

4454
@Override
4555
public void afterEach(ExtensionContext extensionContext) throws Exception {
46-
for (Extension extension : extensions) {
56+
for (Extension extension : reversedExtensions) {
4757
if (extension instanceof AfterEachCallback) {
4858
((AfterEachCallback) extension).afterEach(extensionContext);
4959
}
@@ -52,7 +62,7 @@ public void afterEach(ExtensionContext extensionContext) throws Exception {
5262

5363
@Override
5464
public void afterTestExecution(ExtensionContext extensionContext) throws Exception {
55-
for (Extension extension : extensions) {
65+
for (Extension extension : reversedExtensions) {
5666
if (extension instanceof AfterTestExecutionCallback) {
5767
((AfterTestExecutionCallback) extension).afterTestExecution(extensionContext);
5868
}

0 commit comments

Comments
 (0)