From 52d85aeba829318dc5486730c2c95b7051748662 Mon Sep 17 00:00:00 2001 From: aviv Date: Thu, 7 Mar 2024 14:28:19 +0200 Subject: [PATCH] RavenDB-22128 : add test to verify that ETL script will filter increment time series when using upper cased inc prefix --- test/SlowTests/Issues/RavenDB_22128.cs | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/SlowTests/Issues/RavenDB_22128.cs diff --git a/test/SlowTests/Issues/RavenDB_22128.cs b/test/SlowTests/Issues/RavenDB_22128.cs new file mode 100644 index 000000000000..633588bb6cc6 --- /dev/null +++ b/test/SlowTests/Issues/RavenDB_22128.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using Raven.Client; +using Raven.Client.Documents; +using SlowTests.Core.Utils.Entities; +using SlowTests.Server.Documents.ETL; +using Tests.Infrastructure; +using Xunit; +using Xunit.Abstractions; + +namespace SlowTests.Issues +{ + public class RavenDB_22128 : EtlTestBase + { + public RavenDB_22128(ITestOutputHelper output) : base(output) + { + } + + private const string IncrementalTsName = Constants.Headers.IncrementalTimeSeriesPrefix + "HeartRate"; + private const string TsName = "HeartRate"; + + [RavenFact(RavenTestCategory.TimeSeries | RavenTestCategory.Etl)] + public void TimeSeriesEtlShouldSkipIncrementalTsBasingOnUpperCasedIncPrefix() + { + var collections = new List { "Users" }; + + const string etlScript = """ + loadToUsers(this); + function loadTimeSeriesOfUsersBehavior(doc, ts) + { + if (ts.startsWith("INC")){ + return false; + } + return true; + } + """; + + (DocumentStore src, DocumentStore dest, _) = CreateSrcDestAndAddEtl(collections, script: etlScript); + var baseline = RavenTestHelper.UtcToday; + var etlDone = WaitForEtl(src, (s, statistics) => statistics.LoadSuccesses > 0); + + using (var session = src.OpenSession()) + { + session.Store(new User { Name = "Oren" }, "users/ayende"); + session.Store(new User { Name = "Gracjan" }, "users/poisson"); + var ts = session.IncrementalTimeSeriesFor("users/ayende", IncrementalTsName); + var ts2 = session.TimeSeriesFor("users/poisson", TsName); + ts.Increment(baseline, 100_000); + ts2.Append(baseline, 100); + session.SaveChanges(); + } + + Assert.True(etlDone.Wait(TimeSpan.FromSeconds(30))); + + using (var session = dest.OpenSession()) + { + var ts = session.IncrementalTimeSeriesFor("users/ayende", IncrementalTsName); + var ts2 = session.TimeSeriesFor("users/poisson", TsName); + var incTsEntries = ts.Get(); + var tsEntries = ts2.Get(); + + Assert.Equal(1, tsEntries.Length); + + // should be filtered + Assert.Null(incTsEntries); + } + } + + } +}