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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased
- [DEPRECATED] This library is now deprecated and will be EOL on Dec 31 2021.
- [FIXED] Type of `sinceSeq` can be also a `String` besides an `Integer`.

# 2.19.2 (2021-04-07)
- [NEW] Add migration guide to the newly supported cloudant-java-sdk (coordinates: com.ibm.cloud:cloudant).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 IBM Corp. All rights reserved.
* Copyright (c) 2015, 2021 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 All @@ -17,6 +17,7 @@
import com.cloudant.client.org.lightcouch.ReplicationResult;
import com.cloudant.client.org.lightcouch.ReplicationResult.ReplicationHistory;
import com.cloudant.client.org.lightcouch.Replicator;
import com.google.gson.JsonParser;

import java.util.Map;

Expand Down Expand Up @@ -172,13 +173,24 @@ public Replication createTarget(Boolean createTarget) {
}

/**
* Starts a replication since an update sequence.
* Create or modify a replication since an update sequence using a replication document.
*
* @param sinceSeq sequence number
* @return this Replication instance to set more options or trigger the replication
*/
public Replication sinceSeq(Integer sinceSeq) {
this.replication = replication.sinceSeq(sinceSeq);
this.replication = replication.sinceSeq(new JsonParser().parse(sinceSeq.toString()));
return this;
}

/**
* Create or modify a replication since an update sequence using a replication document.
*
* @param sinceSeq sequence string
* @return this Replication instance to set more options or trigger the replication
*/
public Replication sinceSeq(String sinceSeq) {
this.replication = replication.sinceSeq(new JsonParser().parse(sinceSeq));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019 IBM Corp. All rights reserved.
* Copyright (c) 2015, 2021 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 All @@ -18,6 +18,7 @@
import com.cloudant.client.org.lightcouch.Replication;
import com.cloudant.client.org.lightcouch.ReplicatorDocument;
import com.cloudant.client.org.lightcouch.Response;
import com.google.gson.JsonParser;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -221,8 +222,25 @@ public Replicator userCtxRoles(String... userCtxRoles) {
return this;
}

/**
* Create a transient replication since an update sequence.
*
* @param sinceSeq sequence number
* @return this Replicator instance to set more options or trigger the replication
*/
public Replicator sinceSeq(Integer sinceSeq) {
this.replicator = replicator.sinceSeq(sinceSeq);
this.replicator = replicator.sinceSeq(new JsonParser().parse(sinceSeq.toString()));
return this;
}

/**
* Create a transient replication since an update sequence.
*
* @param sinceSeq sequence string
* @return this Replicator instance to set more options or trigger the replication
*/
public Replicator sinceSeq(String sinceSeq) {
this.replicator = replicator.sinceSeq(new JsonParser().parse(sinceSeq));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 IBM Corp. All rights reserved.
* Copyright (c) 2015, 2021 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 All @@ -16,7 +16,9 @@

import com.cloudant.client.org.lightcouch.Attachment;
import com.cloudant.client.org.lightcouch.Replicator;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -228,11 +230,19 @@ public void setRetriesPerRequest(Integer retriesPerRequest) {
}

public Integer getSinceSeq() {
return replicatorDocument.getSinceSeq();
return replicatorDocument.getSinceSeq().getAsInt();
}

public String getSinceSeqString() {
return replicatorDocument.getSinceSeq().getAsString();
}

public void setSinceSeq(Integer sinceSeq) {
replicatorDocument.setSinceSeq(sinceSeq);
replicatorDocument.setSinceSeq(new JsonParser().parse(sinceSeq.toString()));
}

public void setSinceSeq(String sinceSeq) {
replicatorDocument.setSinceSeq(new JsonParser().parse(sinceSeq));
}

public void setSourceIamApiKey(String iamApiKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 lightcouch.org
* Copyright (c) 2015 IBM Corp. All rights reserved.
* Copyright (c) 2015, 2021 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 All @@ -19,6 +19,7 @@
import static com.cloudant.client.org.lightcouch.internal.CouchDbUtil.close;

import com.cloudant.client.internal.DatabaseURIHelper;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.io.InputStream;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class Replication {
private String[] docIds;
private String proxy;
private Boolean createTarget;
private Integer sinceSeq;
private JsonElement sinceSeq;

// IAM
private String sourceIamApiKey;
Expand Down Expand Up @@ -177,7 +178,7 @@ public Replication createTarget(Boolean createTarget) {
/**
* Starts a replication since an update sequence.
*/
public Replication sinceSeq(Integer sinceSeq) {
public Replication sinceSeq(JsonElement sinceSeq) {
this.sinceSeq = sinceSeq;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 lightcouch.org
* Copyright (c) 2015, 2019 IBM Corp. All rights reserved.
* Copyright (c) 2015, 2021 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 @@ -274,7 +274,7 @@ public Replicator userCtxRoles(String... userCtxRoles) {
return this;
}

public Replicator sinceSeq(Integer sinceSeq) {
public Replicator sinceSeq(JsonElement sinceSeq) {
replicatorDoc.setSinceSeq(sinceSeq);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 lightcouch.org
* Copyright (c) 2015, 2019 IBM Corp. All rights reserved.
* Copyright (c) 2015, 2021 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 @@ -68,7 +68,7 @@ public class ReplicatorDocument extends Document {
@SerializedName("user_ctx")
private UserCtx userCtx;
@SerializedName("since_seq")
private Integer sinceSeq;
private JsonElement sinceSeq;
private JsonElement selector;

public String getSource() {
Expand Down Expand Up @@ -268,11 +268,11 @@ public void setRetriesPerRequest(Integer retriesPerRequest) {
this.retriesPerRequest = retriesPerRequest;
}

public Integer getSinceSeq() {
public JsonElement getSinceSeq() {
return sinceSeq;
}

public void setSinceSeq(Integer sinceSeq) {
public void setSinceSeq(JsonElement sinceSeq) {
this.sinceSeq = sinceSeq;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 lightcouch.org
* Copyright © 2015, 2019 IBM Corp. All rights reserved.
* Copyright © 2015, 2021 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 @@ -106,4 +106,39 @@ public void replication_conflict() throws Exception {
//a conflict
assertConflictsNotZero(db2);
}

Comment thread
mojito317 marked this conversation as resolved.
@Test
public void replication_since_seq() throws Exception {
String seq = db1.changes().getChanges().getResults().get(2).getSeq();
ReplicationResult result = db1Resource.appendReplicationAuth(account.replication()
.createTarget(true)
.source(db1URI)
.target(db2URI)
.sinceSeq(seq)
)
.trigger();

assertTrue(result.isOk(), "The replication should complete ok");

List<ReplicationHistory> histories = result.getHistories();
assertThat(histories.size(), not(0));
}

@Test
public void replication_last_seq() throws Exception {
String lastSeq = db1Resource.get().changes().getChanges().getLastSeq();

ReplicationResult result = db1Resource.appendReplicationAuth(account.replication()
.createTarget(true)
.source(db1URI)
.target(db2URI)
.sinceSeq(lastSeq)
)
.trigger();

assertTrue(result.isOk(), "The replication should complete ok");

List<ReplicationHistory> histories = result.getHistories();
assertThat(histories.size(), not(0));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2015, 2019 IBM Corp. All rights reserved.
* Copyright © 2015, 2021 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 @@ -131,4 +131,41 @@ public void replication_conflict() throws Exception {
//a conflict
assertConflictsNotZero(db2);
}

Comment thread
mojito317 marked this conversation as resolved.
@Test
public void replicator_since_seq() throws Exception {
String seq = db1.changes().getChanges().getResults().get(2).getSeq();
Response response = db1Resource.appendReplicatorAuth(account.replicator()
.replicatorDocId(repDocId)
.createTarget(true)
.source(db1URI)
.target(db2URI)
.sinceSeq(seq)
)
.save();

// find and remove replicator doc
String state = Utils.waitForReplicatorToComplete(account, response.getId());
assertTrue("completed".equalsIgnoreCase(state), "The replicator " +
"should reach completed state");
}

@Test
public void replicator_last_seq() throws Exception {
String lastSeq = db1Resource.get().changes().getChanges().getLastSeq();

Response response = db1Resource.appendReplicatorAuth(account.replicator()
.replicatorDocId(repDocId)
.createTarget(true)
.source(db1URI)
.target(db2URI)
.sinceSeq(lastSeq)
)
.save();

// find and remove replicator doc
String state = Utils.waitForReplicatorToComplete(account, response.getId());
assertTrue("completed".equalsIgnoreCase(state), "The replicator " +
"should reach completed state");
}
}