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

Commit 427013c

Browse files
jjrodrigemlaver
authored andcommitted
Fix exception when replicating with CouchDB 2.3 (#594)
Fixed purge_seq to return a String object when replicating with CouchDB 2.3 databases - Define purge_seq as String as required by CouchDB 2.3 - Add test checking that long purge_seq is correctly deserialized into String
1 parent 4e55c63 commit 427013c

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
- [NEW] `Database` methods `read`, `contains`, `create`, and `delete` now accept local
33
(non-replicating documents). These documents must have their document ID prefixed with `_local/`
44
and must have their revision ID set to `null` (where applicable).
5-
5+
- [FIXED] Fixed purge_seq to return a String object when replicating with CouchDB 2.3 databases.
6+
67
# 2.3.0 (2018-08-14)
78
- [NEW] Added API for specifying a list of document IDs in the filtered pull replicator.
89
- [IMPROVED] Forced a TLS1.2 `SSLSocketFactory` where possible on Android API versions < 20 (it is

cloudant-sync-datastore-core/src/main/java/com/cloudant/sync/internal/mazha/CouchDbInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class CouchDbInfo {
4040
private Object updateSeq;
4141

4242
@JsonProperty("purge_seq")
43-
private long purgeSeq;
43+
private String purgeSeq;
4444

4545
@JsonProperty("compact_running")
4646
private boolean compactRunning;
@@ -73,7 +73,7 @@ public Object getUpdateSeq() {
7373
return updateSeq;
7474
}
7575

76-
public long getPurgeSeq() {
76+
public String getPurgeSeq() {
7777
return purgeSeq;
7878
}
7979

cloudant-sync-datastore-core/src/test/java/com/cloudant/sync/util/JSONUtilsTest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@
1616

1717
package com.cloudant.sync.util;
1818

19-
import com.cloudant.sync.internal.util.JSONUtils;
19+
import com.cloudant.sync.internal.mazha.CouchDbInfo;
2020
import com.cloudant.sync.internal.replication.Foo;
21-
import org.junit.Assert;
21+
import com.cloudant.sync.internal.util.JSONUtils;
22+
import com.fasterxml.jackson.core.type.TypeReference;
23+
2224
import org.apache.commons.io.FileUtils;
25+
import static org.hamcrest.CoreMatchers.is;
26+
import org.junit.Assert;
2327
import org.junit.Test;
2428

29+
import java.io.File;
30+
import java.io.FileReader;
2531
import java.io.IOException;
2632
import java.util.Arrays;
2733
import java.util.HashMap;
2834
import java.util.List;
2935
import java.util.Map;
36+
import java.util.regex.Matcher;
3037

3138
public class JSONUtilsTest {
3239

@@ -149,6 +156,16 @@ public void deserialize_complexDocumentWith_correctlySerializedToMap() throws Ex
149156
Assert.assertEquals(Integer.valueOf(40), breakfast.get("Duration"));
150157
}
151158

159+
@Test
160+
public void deserialize_CouchDBInfo_purgeSeq_from_long() throws Exception {
161+
File dbinfoData = TestUtils.loadFixture("fixture/dbinfo-pre23.json");
162+
CouchDbInfo deserialized = JSONUtils.fromJson(new FileReader(dbinfoData), new
163+
TypeReference<CouchDbInfo>() {
164+
});
165+
Long purgeSeq = Long.valueOf(deserialized.getPurgeSeq());
166+
Assert.assertThat(purgeSeq, is(0l));
167+
}
168+
152169
private byte[] readJsonDataFromFile(String filename) throws IOException {
153170
byte[] data = FileUtils.readFileToByteArray(TestUtils.loadFixture(filename));
154171
return data;

fixture/dbinfo-pre23.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"db_name": "test",
3+
"update_seq": "4-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUoxJTIkyf___z8rkQGPoiQFIJlkD1bHiE-dA0hdPFgdEz51CSB19QTtzWMBkgwNQAqodD4xahdA1O4nRu0BiNr7-P0EUfsAohbk3iwA10dvMg",
4+
"sizes": {
5+
"file": 161030,
6+
"external": 112978,
7+
"active": 113762
8+
},
9+
"purge_seq": 0,
10+
"other": {
11+
"data_size": 112978
12+
},
13+
"doc_del_count": 0,
14+
"doc_count": 3,
15+
"disk_size": 161030,
16+
"disk_format_version": 6,
17+
"data_size": 113762,
18+
"compact_running": false,
19+
"instance_start_time": "0"
20+
}

0 commit comments

Comments
 (0)