Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased
- [NEW] Add getter for total row count to AllDocsResponse
- [NEW] Added `DbInfo#getSizes()` for access to improved sizes information.
- [FIXED] Corrected `DbInfo#getDiskSize()` to work with `sizes` object if `disk_size` is unavailable.
- [FIXED] `ViewMultipleRequest` updated to preferentially use view `queries` format URL instead of
deprecated format.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2015, 2019 IBM Corp. All rights reserved.
* Copyright © 2015, 2020 IBM Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -113,6 +113,25 @@ public boolean getPartitioned() {
}
}

public static class Sizes {

private long active = 0;
private long external = 0;
private long file = 0;

public long getActive() {
return this.active;
}

public long getExternal() {
return this.external;
}

public long getFile() {
return this.file;
}
}

@SerializedName("db_name")
private String dbName;
@SerializedName("doc_count")
Expand All @@ -134,6 +153,8 @@ public boolean getPartitioned() {
private Props props;
@SerializedName("partitioned_indexes")
private PartitionedIndexes partitionedIndexes;
@SerializedName("sizes")
private Sizes sizes;

public String getDbName() {
return dbName;
Expand Down Expand Up @@ -204,6 +225,12 @@ public boolean isCompactRunning() {
}

public long getDiskSize() {
if (diskSize == 0) {
Sizes s = getSizes();
if (s != null) {
return s.getFile();
}
}
return diskSize;
}

Expand Down Expand Up @@ -235,6 +262,10 @@ public PartitionedIndexes getPartitionedIndexes() {
return partitionedIndexes;
}

public Sizes getSizes() {
return sizes;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -270,5 +301,4 @@ public String toString() {

return sb.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2018, 2019 IBM Corp. All rights reserved.
* Copyright © 2018, 2020 IBM Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -152,4 +152,73 @@ public void getDbInfoDocDelCount() {
assertEquals(7l, info.getDocDelCountLong());
}

/**
* Make sure the fallback caused by disk_size 0, doesn't cause an exception
*/
@Test
public void getDbInfoDiskSizeZeroWithoutException() {
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
Database db = c.database("animaldb", false);

MockResponse response = new MockResponse()
.setResponseCode(200)
.setBody("{\"disk_size\":0}");
server.enqueue(response);

DbInfo info = db.info();
assertEquals(0L, info.getDiskSize(), "The mock disk size should be 0");
}

/**
* Make sure disk_size still works
*/
@Test
public void getDbInfoDiskSize() {
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
Database db = c.database("animaldb", false);

MockResponse response = new MockResponse()
.setResponseCode(200)
.setBody("{\"disk_size\":17}");
server.enqueue(response);

DbInfo info = db.info();
assertEquals(17L, info.getDiskSize(), "The mock disk size should be 17");
}

/**
* Make sure disk_size using sizes works
*/
@Test
public void getDbInfoDiskSizeFromSizes() {
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
Database db = c.database("animaldb", false);

MockResponse response = new MockResponse()
.setResponseCode(200)
.setBody("{\"sizes\": {\"active\": 21, \"external\":22, \"file\": 23}}");
server.enqueue(response);

DbInfo info = db.info();
assertEquals(23L, info.getDiskSize(), "The mock disk size should be 23");
}

/**
* Make sure disk_size using sizes works
*/
@Test
public void getDbInfoSizes() {
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
Database db = c.database("animaldb", false);

MockResponse response = new MockResponse()
.setResponseCode(200)
.setBody("{\"sizes\": {\"active\": 21, \"external\":22, \"file\": 23}}");
server.enqueue(response);

DbInfo info = db.info();
assertEquals(21L, info.getSizes().getActive(), "The mock active disk size should be 21");
assertEquals(22L, info.getSizes().getExternal(), "The mock external disk size should be 22");
assertEquals(23L, info.getSizes().getFile(), "The mock file disk size should be 23");
}
}