public void TestPusherDeletedDoc()
{
if (!Boolean.Parse((string)Runtime.Properties["replicationTestsEnabled"]))
{
Assert.Inconclusive("Replication tests disabled.");
return;
}
using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
var remote = remoteDb.RemoteUri;
var docIdTimestamp = Convert.ToString(Runtime.CurrentTimeMillis());
// Create some documentsConvert
var documentProperties = new Dictionary<string, object>();
var doc1Id = string.Format("doc1-{0}", docIdTimestamp);
documentProperties["_id"] = doc1Id;
documentProperties["foo"] = 1;
documentProperties["bar"] = false;
var body = new Body(documentProperties);
var rev1 = new RevisionInternal(body);
rev1 = database.PutRevision(rev1, null, false);
documentProperties["_rev"] = rev1.GetRevId();
documentProperties["UPDATED"] = true;
documentProperties["_deleted"] = true;
database.PutRevision(new RevisionInternal(documentProperties), rev1.GetRevId(), false);
var repl = database.CreatePushReplication(remote);
if (!IsSyncGateway(remote)) {
((Pusher)repl).CreateTarget = true;
}
RunReplication(repl);
Assert.IsNull(repl.LastError);
// make sure doc1 is deleted
var replicationUrlTrailing = new Uri(string.Format("{0}/", remote));
var pathToDoc = new Uri(replicationUrlTrailing, doc1Id);
Log.D(Tag, "Send http request to " + pathToDoc);
var httpRequestDoneSignal = new CountDownLatch(1);
using (var httpclient = new HttpClient()) {
try {
var getDocResponse = httpclient.GetAsync(pathToDoc.ToString()).Result;
var statusLine = getDocResponse.StatusCode;
Log.D(ReplicationTest.Tag, "statusLine " + statusLine);
Assert.AreEqual(Couchbase.Lite.StatusCode.NotFound, statusLine.GetStatusCode());
}
catch (ProtocolViolationException e) {
Assert.IsNull(e, "Got ClientProtocolException: " + e.Message);
}
catch (IOException e) {
Assert.IsNull(e, "Got IOException: " + e.Message);
}
finally {
httpRequestDoneSignal.CountDown();
}
Log.D(Tag, "Waiting for http request to finish");
try {
httpRequestDoneSignal.Await(TimeSpan.FromSeconds(10));
Log.D(Tag, "http request finished");
}
catch (Exception e) {
Runtime.PrintStackTrace(e);
}
}
}
}