/// <exception cref="System.Exception"></exception>
 public virtual void TestRemoteConflictResolution()
 {
     // Create a document with two conflicting edits.
     Document doc = database.CreateDocument();
     SavedRevision rev1 = doc.CreateRevision().Save();
     SavedRevision rev2a = CreateRevisionWithRandomProps(rev1, false);
     SavedRevision rev2b = CreateRevisionWithRandomProps(rev1, true);
     // make sure we can query the db to get the conflict
     Query allDocsQuery = database.CreateAllDocumentsQuery();
     allDocsQuery.SetAllDocsMode(Query.AllDocsMode.OnlyConflicts);
     QueryEnumerator rows = allDocsQuery.Run();
     bool foundDoc = false;
     NUnit.Framework.Assert.AreEqual(1, rows.GetCount());
     for (IEnumerator<QueryRow> it = rows; it.HasNext(); )
     {
         QueryRow row = it.Next();
         if (row.GetDocument().GetId().Equals(doc.GetId()))
         {
             foundDoc = true;
         }
     }
     NUnit.Framework.Assert.IsTrue(foundDoc);
     // Push the conflicts to the remote DB.
     Replication push = database.CreatePushReplication(GetReplicationURL());
     RunReplication(push);
     NUnit.Framework.Assert.IsNull(push.GetLastError());
     // Prepare a bulk docs request to resolve the conflict remotely. First, advance rev 2a.
     JSONObject rev3aBody = new JSONObject();
     rev3aBody.Put("_id", doc.GetId());
     rev3aBody.Put("_rev", rev2a.GetId());
     // Then, delete rev 2b.
     JSONObject rev3bBody = new JSONObject();
     rev3bBody.Put("_id", doc.GetId());
     rev3bBody.Put("_rev", rev2b.GetId());
     rev3bBody.Put("_deleted", true);
     // Combine into one _bulk_docs request.
     JSONObject requestBody = new JSONObject();
     requestBody.Put("docs", new JSONArray(Arrays.AsList(rev3aBody, rev3bBody)));
     // Make the _bulk_docs request.
     HttpClient client = new DefaultHttpClient();
     string bulkDocsUrl = GetReplicationURL().ToExternalForm() + "/_bulk_docs";
     HttpPost request = new HttpPost(bulkDocsUrl);
     request.SetHeader("Content-Type", "application/json");
     string json = requestBody.ToString();
     request.SetEntity(new StringEntity(json));
     HttpResponse response = client.Execute(request);
     // Check the response to make sure everything worked as it should.
     NUnit.Framework.Assert.AreEqual(201, response.GetStatusLine().GetStatusCode());
     string rawResponse = IOUtils.ToString(response.GetEntity().GetContent());
     JSONArray resultArray = new JSONArray(rawResponse);
     NUnit.Framework.Assert.AreEqual(2, resultArray.Length());
     for (int i = 0; i < resultArray.Length(); i++)
     {
         NUnit.Framework.Assert.IsTrue(((JSONObject)resultArray.Get(i)).IsNull("error"));
     }
     WorkaroundSyncGatewayRaceCondition();
     // Pull the remote changes.
     Replication pull = database.CreatePullReplication(GetReplicationURL());
     RunReplication(pull);
     NUnit.Framework.Assert.IsNull(pull.GetLastError());
     // Make sure the conflict was resolved locally.
     NUnit.Framework.Assert.AreEqual(1, doc.GetConflictingRevisions().Count);
 }
예제 #2
0
		private List<Song> MapSongs(string ret)
		{
			var arr = new JSONArray(ret);
			var list = new List<Song>();
			for (var i = 0; i < arr.Length(); i++)
			{
				var item = (JSONObject)arr.Get(i);
				var id = item.GetInt("id");
				var name = item.GetString("name");
				var relativePath = item.GetString("relativePath");
				var artist = item.GetString("artist");
				var lenght = this.JsonToTimeSpan(item.GetJSONObject("length"));
				var lastModified = DateTime.Parse(item.GetString("lastModified"));
				var fileLenght = item.GetInt("fileLength");
				var song = new Song(id,
					name,
					relativePath,
					artist,
					lenght,
					lastModified,
					fileLenght);
				list.Add(song);
			}

			return list;
		}
예제 #3
0
		/// <exception cref="System.Exception"></exception>
		public virtual void TestRemoteConflictResolution()
		{
			// Create a document with two conflicting edits.
			Document doc = database.CreateDocument();
			SavedRevision rev1 = doc.CreateRevision().Save();
			SavedRevision rev2a = rev1.CreateRevision().Save();
			SavedRevision rev2b = rev1.CreateRevision().Save(true);
			// Push the conflicts to the remote DB.
			Replication push = database.CreatePushReplication(GetReplicationURL());
			RunReplication(push);
			// Prepare a bulk docs request to resolve the conflict remotely. First, advance rev 2a.
			JSONObject rev3aBody = new JSONObject();
			rev3aBody.Put("_id", doc.GetId());
			rev3aBody.Put("_rev", rev2a.GetId());
			// Then, delete rev 2b.
			JSONObject rev3bBody = new JSONObject();
			rev3bBody.Put("_id", doc.GetId());
			rev3bBody.Put("_rev", rev2b.GetId());
			rev3bBody.Put("_deleted", true);
			// Combine into one _bulk_docs request.
			JSONObject requestBody = new JSONObject();
			requestBody.Put("docs", new JSONArray(Arrays.AsList(rev3aBody, rev3bBody)));
			// Make the _bulk_docs request.
			HttpClient client = new DefaultHttpClient();
			string bulkDocsUrl = GetReplicationURL().ToExternalForm() + "/_bulk_docs";
			HttpPost request = new HttpPost(bulkDocsUrl);
			request.SetHeader("Content-Type", "application/json");
			string json = requestBody.ToString();
			request.SetEntity(new StringEntity(json));
			HttpResponse response = client.Execute(request);
			// Check the response to make sure everything worked as it should.
			NUnit.Framework.Assert.AreEqual(201, response.GetStatusLine().GetStatusCode());
			string rawResponse = IOUtils.ToString(response.GetEntity().GetContent());
			JSONArray resultArray = new JSONArray(rawResponse);
			NUnit.Framework.Assert.AreEqual(2, resultArray.Length());
			for (int i = 0; i < resultArray.Length(); i++)
			{
				NUnit.Framework.Assert.IsTrue(((JSONObject)resultArray.Get(i)).IsNull("error"));
			}
			WorkaroundSyncGatewayRaceCondition();
			// Pull the remote changes.
			Replication pull = database.CreatePullReplication(GetReplicationURL());
			RunReplication(pull);
			// Make sure the conflict was resolved locally.
			NUnit.Framework.Assert.AreEqual(1, doc.GetConflictingRevisions().Count);
		}