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

/Raven.Tests/MultiGet/MultiGetProfiling.cs

https://github.com/dangerwheeler/ravendb
C# | 266 lines | 223 code | 42 blank | 1 comment | 7 complexity | 917408c8e5eb6d7c0ec4d2e9a092824b MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using Newtonsoft.Json;
  4. using Raven.Abstractions.Data;
  5. using Raven.Client.Debug;
  6. using Raven.Client.Indexes;
  7. using Raven.Client.Linq;
  8. using Raven.Client.Document;
  9. using Raven.Json.Linq;
  10. using Raven.Tests.Bugs;
  11. using Xunit;
  12. namespace Raven.Tests.MultiGet
  13. {
  14. public class MultiGetProfiling : RemoteClientTest
  15. {
  16. [Fact]
  17. public void CanProfileLazyRequests()
  18. {
  19. using (GetNewServer())
  20. using (var store = new DocumentStore { Url = "http://localhost:8080" })
  21. {
  22. store.Initialize();
  23. using (var session = store.OpenSession())
  24. {
  25. // handle the initial request for replication information
  26. }
  27. Guid id;
  28. using (var session = store.OpenSession())
  29. {
  30. id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
  31. session.Advanced.Lazily.Load<User>("users/1");
  32. session.Advanced.Lazily.Load<User>("users/2");
  33. session.Advanced.Lazily.Load<User>("users/3");
  34. session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();
  35. }
  36. var profilingInformation = store.GetProfilingInformationFor(id);
  37. Assert.Equal(1, profilingInformation.Requests.Count);
  38. var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result);
  39. Assert.Equal(3, responses.Length);
  40. foreach (var response in responses)
  41. {
  42. Assert.Equal(404, response.Status);
  43. }
  44. }
  45. }
  46. [Fact]
  47. public void CanProfilePartiallyCachedLazyRequest()
  48. {
  49. using (GetNewServer())
  50. using (var store = new DocumentStore { Url = "http://localhost:8080" })
  51. {
  52. store.Initialize();
  53. using (var session = store.OpenSession())
  54. {
  55. session.Store(new User { Name = "oren" });
  56. session.Store(new User { Name = "ayende" });
  57. session.SaveChanges();
  58. }
  59. using (var session = store.OpenSession())
  60. {
  61. session.Query<User>().Where(x => x.Name == "oren").ToArray();
  62. }
  63. Guid id;
  64. using (var session = store.OpenSession())
  65. {
  66. id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
  67. session.Query<User>().Where(x => x.Name == "oren").Lazily();
  68. session.Query<User>().Where(x => x.Name == "ayende").Lazily();
  69. session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();
  70. }
  71. var profilingInformation = store.GetProfilingInformationFor(id);
  72. Assert.Equal(1, profilingInformation.Requests.Count);
  73. var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result);
  74. Assert.Equal(304, responses[0].Status);
  75. Assert.Contains("oren", responses[0].Result);
  76. Assert.Equal(200, responses[1].Status);
  77. Assert.Contains("ayende", responses[1].Result);
  78. }
  79. }
  80. [Fact]
  81. public void CanProfileFullyCached()
  82. {
  83. using (GetNewServer())
  84. using (var store = new DocumentStore { Url = "http://localhost:8080" })
  85. {
  86. store.Initialize();
  87. using (var session = store.OpenSession())
  88. {
  89. session.Store(new User { Name = "oren" });
  90. session.Store(new User { Name = "ayende" });
  91. session.SaveChanges();
  92. }
  93. using (var session = store.OpenSession())
  94. {
  95. session.Query<User>().Where(x => x.Name == "oren").ToArray();
  96. session.Query<User>().Where(x => x.Name == "ayende").ToArray();
  97. }
  98. Guid id;
  99. using (var session = store.OpenSession())
  100. {
  101. id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
  102. session.Query<User>().Where(x => x.Name == "oren").Lazily();
  103. session.Query<User>().Where(x => x.Name == "ayende").Lazily();
  104. session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();
  105. }
  106. var profilingInformation = store.GetProfilingInformationFor(id);
  107. Assert.Equal(1, profilingInformation.Requests.Count);
  108. var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result);
  109. Assert.Equal(304, responses[0].Status);
  110. Assert.Contains("oren", responses[0].Result);
  111. Assert.Equal(304, responses[1].Status);
  112. Assert.Contains("ayende", responses[1].Result);
  113. }
  114. }
  115. [Fact]
  116. public void CanProfilePartiallyAggressivelyCached()
  117. {
  118. using (GetNewServer())
  119. using (var store = new DocumentStore { Url = "http://localhost:8080" })
  120. {
  121. store.Initialize();
  122. using (var session = store.OpenSession())
  123. {
  124. session.Store(new User { Name = "oren" });
  125. session.Store(new User { Name = "ayende" });
  126. session.SaveChanges();
  127. }
  128. using (var session = store.OpenSession())
  129. {
  130. using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
  131. {
  132. session.Load<User>("users/1");
  133. }
  134. }
  135. Guid id;
  136. using (var session = store.OpenSession())
  137. {
  138. id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
  139. using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
  140. {
  141. session.Advanced.Lazily.Load<User>("users/1");
  142. session.Advanced.Lazily.Load<User>("users/2");
  143. session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();
  144. }
  145. }
  146. var profilingInformation = store.GetProfilingInformationFor(id);
  147. Assert.Equal(1, profilingInformation.Requests.Count);
  148. var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result);
  149. Assert.Equal(0, responses[0].Status);
  150. Assert.Contains("oren", responses[0].Result);
  151. Assert.Equal(200, responses[1].Status);
  152. Assert.Contains("ayende", responses[1].Result);
  153. }
  154. }
  155. [Fact]
  156. public void CanProfileFullyAggressivelyCached()
  157. {
  158. using (GetNewServer())
  159. using (var store = new DocumentStore { Url = "http://localhost:8080" })
  160. {
  161. store.Initialize();
  162. using (var session = store.OpenSession())
  163. {
  164. session.Store(new User { Name = "oren" });
  165. session.Store(new User { Name = "ayende" });
  166. session.SaveChanges();
  167. }
  168. using (var session = store.OpenSession())
  169. {
  170. using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
  171. {
  172. session.Load<User>("users/1");
  173. session.Load<User>("users/2");
  174. }
  175. }
  176. Guid id;
  177. using (var session = store.OpenSession())
  178. {
  179. id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
  180. using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
  181. {
  182. session.Advanced.Lazily.Load<User>("users/1");
  183. session.Advanced.Lazily.Load<User>("users/2");
  184. session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();
  185. }
  186. }
  187. var profilingInformation = store.GetProfilingInformationFor(id);
  188. Assert.Equal(1, profilingInformation.Requests.Count);
  189. var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result);
  190. Assert.Equal(0, responses[0].Status);
  191. Assert.Contains("oren", responses[0].Result);
  192. Assert.Equal(0, responses[1].Status);
  193. Assert.Contains("ayende", responses[1].Result);
  194. }
  195. }
  196. [Fact]
  197. public void CanProfileErrors()
  198. {
  199. using (GetNewServer())
  200. using (var store = new DocumentStore { Url = "http://localhost:8080" })
  201. {
  202. store.Initialize();
  203. using (var session = store.OpenSession())
  204. {
  205. session.Store(new User { Name = "oren" });
  206. session.Store(new User { Name = "ayende" });
  207. session.SaveChanges();
  208. }
  209. Guid id;
  210. using (var session = store.OpenSession())
  211. {
  212. id = session.Advanced.DatabaseCommands.ProfilingInformation.Id;
  213. session.Advanced.LuceneQuery<object, RavenDocumentsByEntityName>().WhereEquals("Not", "There").Lazily();
  214. Assert.Throws<InvalidOperationException>(() => session.Advanced.Eagerly.ExecuteAllPendingLazyOperations());
  215. }
  216. var profilingInformation = store.GetProfilingInformationFor(id);
  217. Assert.Equal(1, profilingInformation.Requests.Count);
  218. var responses = JsonConvert.DeserializeObject<GetResponse[]>(profilingInformation.Requests[0].Result);
  219. Assert.Equal(500, responses[0].Status);
  220. Assert.Contains("The field 'Not' is not indexed, cannot query on fields that are not indexed", responses[0].Result);
  221. }
  222. }
  223. }
  224. }