use of com.cloudant.client.api.model.ReplicatorDocument in project java-cloudant by cloudant.
the class ReplicatorTest method replication_filteredWithQueryParams.
@Test
public void replication_filteredWithQueryParams() throws Exception {
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("somekey1", "value 1");
Response response = account.replicator().createTarget(true).replicatorDocId(repDocId).source(db1URI).target(db2URI).filter("example/example_filter").queryParams(queryParams).save();
// find and remove replicator doc
ReplicatorDocument repDoc = Utils.waitForReplicatorToComplete(account, response.getId());
assertTrue("completed".equalsIgnoreCase(repDoc.getReplicationState()), "The replicator " + "should reach completed state");
}
use of com.cloudant.client.api.model.ReplicatorDocument in project java-cloudant by cloudant.
the class ReplicatorTest method replication.
@Test
public void replication() throws Exception {
Response response = account.replicator().replicatorDocId(repDocId).createTarget(true).source(db1URI).target(db2URI).save();
// find and remove replicator doc
ReplicatorDocument repDoc = Utils.waitForReplicatorToComplete(account, response.getId());
assertTrue("completed".equalsIgnoreCase(repDoc.getReplicationState()), "The replicator " + "should reach completed state");
}
use of com.cloudant.client.api.model.ReplicatorDocument in project java-cloudant by cloudant.
the class Utils method waitForReplicatorToReachStatus.
public static ReplicatorDocument waitForReplicatorToReachStatus(CloudantClient account, String replicatorDocId, String status) throws Exception {
ReplicatorDocument replicatorDoc = null;
boolean finished = false;
long startTime = System.currentTimeMillis();
long timeout = startTime + TIMEOUT_MILLISECONDS;
// initial wait of 100 ms
long delay = 100;
while (!finished && System.currentTimeMillis() < timeout) {
// Sleep before finding replication document
Thread.sleep(delay);
replicatorDoc = account.replicator().replicatorDocId(replicatorDocId).find();
// Check if replicator doc is in specified state
String state;
if (replicatorDoc != null && (state = replicatorDoc.getReplicationState()) != null) {
// if we've reached the status or we reached an error then we are finished
if (state.equalsIgnoreCase(status) || state.equalsIgnoreCase("error")) {
finished = true;
}
}
// double the delay for the next iteration
delay *= 2;
}
if (!finished) {
throw new TimeoutException("Timed out waiting for replication to complete");
}
return replicatorDoc;
}
use of com.cloudant.client.api.model.ReplicatorDocument in project java-cloudant by cloudant.
the class ReplicatorTest method replicatorDB.
@Test
public void replicatorDB() throws Exception {
// trigger a replication
Response response = account.replicator().replicatorDocId(repDocId).source(db1URI).target(db2URI).continuous(true).createTarget(true).save();
// we need the replication to start before continuing
Utils.waitForReplicatorToStart(account, response.getId());
// find all replicator docs
List<ReplicatorDocument> replicatorDocs = account.replicator().findAll();
assertThat(replicatorDocs.size(), is(not(0)));
}
Aggregations