private IQbservable <Location> CreateStreamSource(bool shouldPluralizeStreamName = true)
        {
            contextOptions.ShouldPluralizeStreamName = shouldPluralizeStreamName;

            var context = new TestableDbProvider(contextOptions);

            return(context.CreateQueryStream <Location>());
        }
    private IQbservable <City> CreateQbservable()
    {
        var context = new TestableDbProvider(TestParameters.KsqlDBUrl);

        context.KSqlDbProviderMock.Setup(c => c.Run <int>(It.IsAny <object>(), It.IsAny <CancellationToken>())).Returns(GetTestValues);
        context.KSqlDbProviderMock.Setup(c => c.Run <long>(It.IsAny <object>(), It.IsAny <CancellationToken>())).Returns(GetDecimalTestValues);

        return(context.CreateQueryStream <City>());
    }
Example #3
0
    public void CreateStreamSet_CalledMultipleTimes_KSqlQueryGeneratorBuildKSqlWasNotCalled()
    {
        //Arrange
        var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl);

        //Act
        var subscription = context.CreateQueryStream <string>().Subscribe(_ => {});

        //Assert
        context.KSqlQueryGenerator.Verify(c => c.BuildKSql(It.IsAny <Expression>(), It.IsAny <QueryContext>()), Times.Once);
    }
Example #4
0
    public void CreateStreamSet_Subscribe_KSqlDbProvidersRunWasCalled()
    {
        //Arrange
        var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl);

        //Act
        var streamSet = context.CreateQueryStream <string>().Subscribe(_ => {});

        //Assert
        streamSet.Should().NotBeNull();
        context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.IsAny <object>(), It.IsAny <CancellationToken>()), Times.Once);
    }
Example #5
0
    public async Task DisposeAsync_ServiceProviderWasBuilt_ContextWasDisposed()
    {
        //Arrange
        var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl);

        context.CreateQueryStream <string>();

        //Act
        await context.DisposeAsync().ConfigureAwait(false);

        //Assert
        context.IsDisposed.Should().BeTrue();
    }
Example #6
0
    public void CreateStreamSet_Subscribe_ProcessingGuarantee()
    {
        //Arrange
        var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl);

        contextOptions.SetProcessingGuarantee(ProcessingGuarantee.ExactlyOnce);

        var context = new TestableDbProvider <string>(contextOptions);

        //Act
        var subscription = context.CreateQueryStream <string>().Subscribe(_ => {});

        //Assert
        context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c[KSqlDbConfigs.ProcessingGuarantee] == "exactly_once"), It.IsAny <CancellationToken>()), Times.Once);
    }
Example #7
0
    public void SetAutoOffsetReset_Subscribe_ProcessingGuarantee()
    {
        //Arrange
        var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl);

        contextOptions.SetAutoOffsetReset(AutoOffsetReset.Latest);

        var context = new TestableDbProvider <string>(contextOptions);

        //Act
        var subscription = context.CreateQueryStream <string>().Subscribe(_ => {});

        //Assert
        context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once);
    }
Example #8
0
    public void CreateStreamSet_Subscribe_KSqlQueryGenerator()
    {
        //Arrange
        var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl);

        contextOptions.QueryStreamParameters["auto.offset.reset"] = "latest";

        var context = new TestableDbProvider <string>(contextOptions);

        //Act
        var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}, e => {});

        //Assert
        context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(parameters => parameters["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once);
    }
Example #9
0
    public void WithOffsetResetPolicy_Subscribe_QueryOptionsWereTakenFromContext()
    {
        //Arrange
        var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl);

        var context = new TestableDbProvider <string>(contextOptions)
        {
            RegisterKSqlQueryGenerator = false
        };

        //Act
        var subscription = context.CreateQueryStream <string>().WithOffsetResetPolicy(AutoOffsetReset.Latest).Subscribe(_ => {});

        //Assert
        // context.KSqldbProviderMock.Verify(c => c.Run<string>(It.Is<IQueryParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny<CancellationToken>()), Times.Once);
        context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c.AutoOffsetReset == AutoOffsetReset.Latest), It.IsAny <CancellationToken>()), Times.Once);

        subscription.Dispose();
    }
Example #10
0
    public void CreateQueryStream_RawKSQL_ReturnAsyncEnumerable()
    {
        //Arrange
        string ksql = "SELECT * FROM tweetsTest EMIT CHANGES LIMIT 2;";

        QueryStreamParameters queryStreamParameters = new QueryStreamParameters
        {
            Sql = ksql,
            [QueryStreamParameters.AutoOffsetResetPropertyName] = "earliest",
        };

        var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl);

        //Act
        var source = context.CreateQueryStream <string>(queryStreamParameters);

        //Assert
        source.Should().NotBeNull();
    }
Example #11
0
    public void CreateStreamSet_Subscribe_QueryOptionsWereTakenFromContext()
    {
        //Arrange
        var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl)
        {
            QueryStreamParameters =
            {
                ["auto.offset.reset"] = "latest"
            }
        };

        var context = new TestableDbProvider <string>(contextOptions);

        //Act
        var subscription = context.CreateQueryStream <string>().Subscribe(_ => {});

        //Assert
        context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once);

        subscription.Dispose();
    }
    public void GroupByCompoundKey_BuildKSql_PrintsQuery()
    {
        //Arrange
        var context = new TestableDbProvider(TestParameters.KsqlDBUrl);

        //https://kafka-tutorials.confluent.io/finding-distinct-events/ksql.html
        var grouping = context.CreateQueryStream <Click>()
                       .GroupBy(c => new { c.IP_ADDRESS, c.URL, c.TIMESTAMP })
                       .WindowedBy(new TimeWindows(Duration.OfMinutes(2)))
                       .Having(c => c.Count(g => c.Key.IP_ADDRESS) == 1)
                       .Select(g => new { g.Key.IP_ADDRESS, g.Key.URL, g.Key.TIMESTAMP })
                       .Take(3);

        //Act
        var ksql = grouping.ToQueryString();

        //Assert
        string expectedKSql = @"SELECT IP_ADDRESS, URL, TIMESTAMP FROM Clicks WINDOW TUMBLING (SIZE 2 MINUTES) GROUP BY IP_ADDRESS, URL, TIMESTAMP HAVING COUNT(IP_ADDRESS) = 1 EMIT CHANGES LIMIT 3;";

        ksql.Should().BeEquivalentTo(expectedKSql);
    }
Example #13
0
        private IQbservable <Tweet> CreateTweetsStreamSource()
        {
            var context = new TestableDbProvider(contextOptions);

            return(context.CreateQueryStream <Tweet>());
        }