PageRenderTime 57ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/ToMigrate/Raven.Tests/Conflicts/ShouldntCreateConflictIfIdentical.cs

http://github.com/ayende/ravendb
C# | 64 lines | 57 code | 3 blank | 4 comment | 0 complexity | eabf064f24e04671b80c7562f43ffedb MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, Apache-2.0, BSD-3-Clause, CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Raven.Abstractions.Json.Linq;
  8. using Raven.Client.Document;
  9. using Raven.Json.Linq;
  10. using Raven.Tests.Common;
  11. using Xunit;
  12. using Constants = Raven.Abstractions.Data.Constants;
  13. namespace Raven.Tests.Conflicts
  14. {
  15. public class ShouldntCreateConflictIfIdentical : ReplicationBase
  16. {
  17. private static RavenJObject userAsObject = RavenJObject.FromObject(
  18. new { Name = "Tal", Address = new { Country = "Israel", City = "Zichron" } });
  19. private static byte[] data = {13, 35, 65};
  20. [Fact]
  21. public void IdenticalDocumentsShouldntCreateConflicts()
  22. {
  23. using (var store1 = CreateStore())
  24. using (var store2 = CreateStore())
  25. {
  26. store1.DatabaseCommands.Put("users/1", null, userAsObject, null);
  27. store2.DatabaseCommands.Put("users/1", null, userAsObject, null);
  28. var userOnStore1 = store1.DatabaseCommands.Get("users/1");
  29. var user = store2.DatabaseCommands.Get("users/1");
  30. TellFirstInstanceToReplicateToSecondInstance();
  31. WaitForReplication(store2, "users/1", changedSince: user.Etag);
  32. //if this line doesn't throw this means that the conflict was resolved.
  33. user = store2.DatabaseCommands.Get("users/1");
  34. //Making sure user on store 2 has the history of versions from store 1
  35. Assert.Equal(1, ((RavenJArray)user.Metadata[Constants.RavenReplicationHistory]).Length);
  36. Assert.Equal(userOnStore1.Metadata[Constants.RavenReplicationSource].Value<string>(),
  37. ((RavenJObject)((RavenJArray)user.Metadata[Constants.RavenReplicationHistory]).First())[Constants.RavenReplicationSource].Value<string>());
  38. }
  39. }
  40. [Fact]
  41. public void IdenticalAttachmentsShouldntCreateConflicts()
  42. {
  43. using (var store1 = CreateStore())
  44. using (var store2 = CreateStore())
  45. {
  46. store1.DatabaseCommands.PutAttachment("attachments/1", null, new MemoryStream(data), null);
  47. store2.DatabaseCommands.PutAttachment("attachments/1", null, new MemoryStream(data), null);
  48. var attOnStore1 = store1.DatabaseCommands.GetAttachment("attachments/1");
  49. var att = store2.DatabaseCommands.GetAttachment("attachments/1");
  50. TellFirstInstanceToReplicateToSecondInstance();
  51. WaitForAttachment(store2, "attachments/1", att.Etag);
  52. //if this line doesn't throw this means that the conflict was resolved.
  53. att = store2.DatabaseCommands.GetAttachment("attachments/1");
  54. //Making sure user on store 2 has the history of versions from store 1
  55. Assert.Equal(1, ((RavenJArray)att.Metadata[Constants.RavenReplicationHistory]).Length);
  56. Assert.Equal(attOnStore1.Metadata[Constants.RavenReplicationSource].Value<string>(),
  57. ((RavenJObject)((RavenJArray)att.Metadata[Constants.RavenReplicationHistory]).First())[Constants.RavenReplicationSource].Value<string>());
  58. }
  59. }
  60. }
  61. }