Search in sources :

Example 1 with ReplicatorDocument

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");
}
Also used : Response(com.cloudant.client.api.model.Response) HashMap(java.util.HashMap) ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) Test(org.junit.jupiter.api.Test)

Example 2 with ReplicatorDocument

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");
}
Also used : Response(com.cloudant.client.api.model.Response) ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) Test(org.junit.jupiter.api.Test)

Example 3 with ReplicatorDocument

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;
}
Also used : ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with ReplicatorDocument

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)));
}
Also used : Response(com.cloudant.client.api.model.Response) ReplicatorDocument(com.cloudant.client.api.model.ReplicatorDocument) Test(org.junit.jupiter.api.Test)

Aggregations

ReplicatorDocument (com.cloudant.client.api.model.ReplicatorDocument)4 Response (com.cloudant.client.api.model.Response)3 Test (org.junit.jupiter.api.Test)3 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1