public async Task CanGetListOfAttachmentsAndReadOrderedAsync(int count, int size) { using (var test = new AttachmentsStreamTests(Output)) { await test.CanGetListOfAttachmentsAndReadOrderedAsync(count, size); } }
public void CanGetListOfAttachmentsAndReadOrdered(int count, int size) { using (var test = new AttachmentsStreamTests(Output)) { test.CanGetListOfAttachmentsAndReadOrdered(count, size); } }
public void CanGetOneAttachment(int size) { using (var test = new AttachmentsStreamTests(Output)) { test.CanGetOneAttachment(size); } }
public void CanGetListOfHugeAttachmentsAndReadOrdered(int count, long size) { var attachmentDictionary = new Dictionary <string, BigDummyStream>(); const string id = "users/1"; const string attachmentName = "Typical attachment name"; using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { var user = new User { Name = "su" }; session.Store(user, id); session.SaveChanges(); } for (var i = 0; i < count; i++) { var bigStream = new BigDummyStream(size); store.Operations.Send(new PutAttachmentOperation("users/1", $"{attachmentName}_{i}", bigStream)); attachmentDictionary[$"{attachmentName}_{i}"] = bigStream; } foreach (var stream in attachmentDictionary.Values) { stream.Position = 0; } using (var session = store.OpenSession()) { var user = session.Load <User>(id); var attachmentsNames = session.Advanced.Attachments.GetNames(user).Select(x => new AttachmentRequest(id, x.Name)); var attachmentsEnumerator = session.Advanced.Attachments.Get(attachmentsNames); while (attachmentsEnumerator.MoveNext()) { Assert.NotNull(attachmentsEnumerator.Current); Assert.True(AttachmentsStreamTests.CompareStreams(attachmentsEnumerator.Current.Stream, attachmentDictionary[$"{attachmentsEnumerator.Current.Details.Name}"])); attachmentsEnumerator.Current.Stream?.Dispose(); } } } foreach (var stream in attachmentDictionary.Values) { stream.Dispose(); } }
public async Task CanHaveBulkInsertWithDocumentsAndAttachmentAndCountersAndTypedTimeSeries() { const int count = 100; const int size = 64 * 1024; using (var store = GetDocumentStore()) { var baseline = RavenTestHelper.UtcToday.EnsureUtc(); var streams = new Dictionary <string, Dictionary <string, MemoryStream> >(); var counters = new Dictionary <string, string>(); var bulks = new Dictionary <string, BulkInsertOperation.AttachmentsBulkInsert>(); using (var bulkInsert = store.BulkInsert()) { for (int i = 0; i < count; i++) { var id = $"name/{i}"; streams[id] = new Dictionary <string, MemoryStream>(); // insert Documents bulkInsert.Store(new User { Name = $"Name_{i}" }, id); bulks[id] = bulkInsert.AttachmentsFor(id); } foreach (var bulk in bulks) { var rnd = new Random(DateTime.Now.Millisecond); var bArr = new byte[size]; rnd.NextBytes(bArr); var name = $"{bulk.Key}_{rnd.Next(100)}"; var stream = new MemoryStream(bArr); // insert Attachments await bulk.Value.StoreAsync(name, stream); stream.Position = 0; streams[bulk.Key][name] = stream; // insert Counters await bulkInsert.CountersFor(bulk.Key).IncrementAsync(name); counters[bulk.Key] = name; // insert Time Series using (var timeSeriesBulkInsert = bulkInsert.TimeSeriesFor <HeartRateMeasure>(bulk.Key, "HeartRate")) { timeSeriesBulkInsert.Append(baseline.AddMinutes(1), new HeartRateMeasure { HeartRate = 59 }, "watches/fitBit"); } } } foreach (var id in streams.Keys) { using (var session = store.OpenSession()) { var timeSeriesVal = session.TimeSeriesFor <HeartRateMeasure>(id, "HeartRate") .Get(DateTime.MinValue, DateTime.MaxValue) .FirstOrDefault(); Assert.NotNull(timeSeriesVal); Assert.Equal(59, timeSeriesVal.Value.HeartRate); Assert.Equal("watches/fitBit", timeSeriesVal.Tag); Assert.Equal(baseline.AddMinutes(1), timeSeriesVal.Timestamp, RavenTestHelper.DateTimeComparer.Instance); var attachmentsNames = streams.Select(x => new AttachmentRequest(id, x.Key)); var attachmentsEnumerator = session.Advanced.Attachments.Get(attachmentsNames); while (attachmentsEnumerator.MoveNext()) { Assert.NotNull(attachmentsEnumerator.Current); Assert.True(AttachmentsStreamTests.CompareStreams(attachmentsEnumerator.Current.Stream, streams[id][attachmentsEnumerator.Current.Details.Name])); attachmentsEnumerator.Current.Stream?.Dispose(); } } var val = store.Operations .Send(new GetCountersOperation(id, new[] { counters[id] })) .Counters[0]?.TotalValue; Assert.Equal(1, val); } } }
public void CanGetListOfDifferentAttachmentsAndRead(int count) { var attachmentDictionary = new Dictionary <string, MemoryStream>(); const string id = "users/1"; const string attachmentName = "Typical attachment name"; var factorials = new List <int>(); using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { var user = new User { Name = "su" }; session.Store(user, id); for (var i = 0; i < count; i++) { var factorial = AttachmentsStreamTests.Factorial(i); factorials.Add(factorial); var rnd = new Random(); var b = new byte[factorial]; rnd.NextBytes(b); var stream = new MemoryStream(b); session.Advanced.Attachments.Store(id, $"{attachmentName}_{i}", stream, "application/zip"); attachmentDictionary[$"{attachmentName}_{i}"] = stream; } session.SaveChanges(); } foreach (var stream in attachmentDictionary.Values) { stream.Position = 0; } using (var session = store.OpenSession()) { var user = session.Load <User>(id); var attachmentsNames = session.Advanced.Attachments.GetNames(user).Select(x => new AttachmentRequest(id, x.Name)); var attachmentsEnumerator = session.Advanced.Attachments.Get(attachmentsNames); int i = 0; while (attachmentsEnumerator.MoveNext()) { var size = factorials[i]; var memoryStream = new MemoryStream(); var attachmentResult = attachmentsEnumerator.Current; Assert.NotNull(attachmentsEnumerator.Current != null); attachmentResult.Stream.CopyTo(memoryStream); memoryStream.Position = 0; var buffer1 = new byte[size]; var buffer2 = new byte[size]; Assert.Equal(attachmentDictionary[$"{attachmentResult.Details.Name}"].Read(buffer1, 0, size), memoryStream.Read(buffer2, 0, size)); Assert.True(buffer1.SequenceEqual(buffer2)); i++; } } } foreach (var stream in attachmentDictionary.Values) { stream.Dispose(); } }