Skip to content

Commit

Permalink
RavenDB-22128 : add test to verify that ETL script will filter increm…
Browse files Browse the repository at this point in the history
…ent time series when using upper cased inc prefix
  • Loading branch information
aviv committed Mar 7, 2024
1 parent be2539a commit 52d85ae
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/SlowTests/Issues/RavenDB_22128.cs
Original file line number Diff line number Diff line change
@@ -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<string> { "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);
}
}

}
}

0 comments on commit 52d85ae

Please sign in to comment.