Example #1
0
        protected static async Task InitializeDatabase()
        {
            RestApiProvider = KSqlDbRestApiProvider.Create();

            MoviesProvider = new MoviesProvider(RestApiProvider);
            await MoviesProvider.CreateTablesAsync();

            await MoviesProvider.InsertMovieAsync(MoviesProvider.Movie1);
        }
Example #2
0
    public static async Task ClassInitialize(TestContext context)
    {
        RestApiProvider = KSqlDbRestApiProvider.Create();

        moviesProvider = new MoviesProvider(RestApiProvider);
        await moviesProvider.CreateTablesAsync();

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);
    }
Example #3
0
    public async Task CreateOrReplaceStreamStatement_ToStatementString_ComplexQueryWasGenerated()
    {
        //Arrange
        var restApiClient = KSqlDbRestApiProvider.Create();

        var statement = new KSqlDbStatement(StatementTemplates.DropStream(StreamName));
        var response  = await restApiClient.ExecuteStatementAsync(statement);

        EntityCreationMetadata metadata = new()
        {
            EntityName = StreamEntityName,
            KafkaTopic = nameof(Movie) + "Test2",
            Partitions = 1,
            Replicas   = 1
        };

        var httpResponseMessage =
            await restApiClient.CreateStreamAsync <Movie>(metadata, ifNotExists : false);

        var creationMetadata = new CreationMetadata
        {
            KafkaTopic  = "moviesByTitle",
            KeyFormat   = SerializationFormats.Json,
            ValueFormat = SerializationFormats.Json,
            Replicas    = 1,
            Partitions  = 1
        };

        var createStatement = Context.CreateOrReplaceStreamStatement(StreamName)
                              .With(creationMetadata)
                              .As <Movie>(StreamEntityName)
                              .Where(c => c.Id < 3)
                              .Select(c => new { c.Id, c.Title, ReleaseYear = c.Release_Year })
                              .PartitionBy(c => c.Id);

        //Act
        var ksql = createStatement.ToStatementString();

        httpResponseMessage = await createStatement.ExecuteStatementAsync();

        //Assert
        ksql.Should().BeEquivalentTo(@$ "CREATE OR REPLACE STREAM {StreamName}
 WITH ( KAFKA_TOPIC='moviesByTitle', KEY_FORMAT='Json', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='1' )
AS SELECT Id, Title, Release_Year AS ReleaseYear FROM {StreamEntityName}
WHERE Id < 3 PARTITION BY Id EMIT CHANGES;");

        var responses = await httpResponseMessage.ToStatementResponsesAsync();

        responses[0].CommandStatus.Status.Should().BeOneOf("SUCCESS", "EXECUTING");
    }
    public static async Task ClassInitialize(TestContext context)
    {
        RestApiProvider = KSqlDbRestApiProvider.Create();

        var response = await RestApiProvider.CreateTypeAsync <TestState>();

        response = await RestApiProvider.CreateTypeAsync <TestCity>();

        response = await RestApiProvider.CreateTableAsync <TestCity>(new EntityCreationMetadata { EntityName = CitiesTableName, KafkaTopic = CitiesTableName, Partitions = 1 });

        var c = await response.Content.ReadAsStringAsync();

        response = await RestApiProvider.InsertIntoAsync(new TestCity
                                                         { RegionCode = "sk", State = State1 }, new InsertProperties { EntityName = CitiesTableName });
    }
Example #5
0
        public static async Task ClassInitialize(TestContext context)
        {
            RestApiProvider = KSqlDbRestApiProvider.Create();

            moviesProvider = new MoviesProvider(RestApiProvider);

            await moviesProvider.DropTablesAsync();

            await Task.Delay(TimeSpan.FromSeconds(1));

            await moviesProvider.CreateTablesAsync();

            await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);

            await moviesProvider.InsertLeadAsync(MoviesProvider.LeadActor1);
        }
        protected static async Task InitializeDatabase()
        {
            RestApiProvider = KSqlDbRestApiProvider.Create();

            var tweetsProvider = new TweetsProvider(RestApiProvider);
            var result         = await tweetsProvider.CreateTweetsStream(StreamName, topicName);

            result.Should().BeTrue();

            result = await tweetsProvider.InsertTweetAsync(Tweet1, StreamName);

            result.Should().BeTrue();

            result = await tweetsProvider.InsertTweetAsync(Tweet2, StreamName);

            result.Should().BeTrue();
        }
    public static async Task ClassInitialize(TestContext context)
    {
        RestApiProvider = KSqlDbRestApiProvider.Create();

        moviesProvider = new MoviesProvider(RestApiProvider);

        await moviesProvider.CreateTablesAsync();

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie2);

        tweetsProvider = new TweetsProvider(RestApiProvider);

        await tweetsProvider.CreateTweetsStream(TweetsStreamName, tweetsTopicName);

        await tweetsProvider.InsertTweetAsync(TweetsProvider.Tweet1, TweetsStreamName);

        await tweetsProvider.InsertTweetAsync(TweetsProvider.Tweet2, TweetsStreamName);
    }
Example #8
0
    public async Task CreateOrReplaceTableStatement_ExecuteStatementAsync_ResponseWasReceived()
    {
        //Arrange
        var restApiClient = KSqlDbRestApiProvider.Create();

        await restApiClient.CreateStreamAsync <Movie>(new EntityCreationMetadata(EntityName, 1) { EntityName = EntityName, ShouldPluralizeEntityName = false });

        var statement = new KSqlDbStatement(StatementTemplates.DropTable(TableName));
        var response  = await restApiClient.ExecuteStatementAsync(statement);

        int retryCount = 0;

        while ((await KSqlDbRestApiProvider.Create().GetTablesAsync()).SelectMany(c => c.Tables).Any(c => c.Name == TableName.ToUpper()))
        {
            if (retryCount++ > 5)
            {
                return;
            }

            await Task.Delay(TimeSpan.FromSeconds(1));
        }

        var createStatement = Context.CreateTableStatement(TableName)
                              .As <Movie>(EntityName)
                              .GroupBy(c => c.Title)
                              .Select(c => new { Title = c.Key, Count = c.Count() });

        //Act
        var httpResponseMessage = await createStatement.ExecuteStatementAsync();

        //Assert
        string responseContent = await httpResponseMessage.Content.ReadAsStringAsync();

        responseContent.Should().NotBeNull();

        var responses = await httpResponseMessage.ToStatementResponsesAsync();

        responses[0].CommandStatus.Status.Should().Be("SUCCESS");
    }
Example #9
0
    public static async Task ClassInitialize(TestContext context)
    {
        RestApiProvider = KSqlDbRestApiProvider.Create();

        var statement =
            new KSqlDbStatement(
                @"CREATE STREAM stream2 (id INT, lambda_arr ARRAY<INTEGER>) WITH (kafka_topic = 'stream2', partitions = 1, value_format = 'json');");

        var response = await RestApiProvider.ExecuteStatementAsync(statement);

        var statement2 =
            new KSqlDbStatement(
                @"CREATE OR REPLACE STREAM stream4 (id INT, lambda_map MAP<STRING,ARRAY<INTEGER>>) WITH (kafka_topic = 'stream4', partitions = 1, value_format = 'json');");

        response = await RestApiProvider.ExecuteStatementAsync(statement2);

        string insertIntoStream3 = "insert into stream4 (id, lambda_map) values (1, MAP('hello':= ARRAY [1,2,3], 'goodbye':= ARRAY [-1,-2,-3]) );";

        response = await RestApiProvider.ExecuteStatementAsync(
            new KSqlDbStatement("insert into stream2 (id, lambda_arr) values (1, ARRAY [1,2,3]);"));

        response = await RestApiProvider.ExecuteStatementAsync(
            new KSqlDbStatement(insertIntoStream3));
    }
    public static async Task ClassInitialize(TestContext context)
    {
        var restApiClient = KSqlDbRestApiProvider.Create();

        await restApiClient.CreateStreamAsync <Movie>(new EntityCreationMetadata(EntityName, 1) { EntityName = EntityName, ShouldPluralizeEntityName = false });
    }