Skip to content

Commit ad81431

Browse files
committed
[ksqlDb.RestApi.Client]: fixed Source table can't be queried #87
1 parent 6eb056b commit ad81431

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

Tests/ksqlDB.RestApi.Client.Tests/KSql/RestApi/KSqlDbRestApiClientTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq.Expressions;
2+
using System.Net;
23
using System.Text;
34
using FluentAssertions;
45
using ksqlDb.RestApi.Client.Infrastructure.Logging;
@@ -701,4 +702,52 @@ public async Task AssertSchemaExistsAsync_ReturnsFalse()
701702
//Assert
702703
response[0].Exists.Should().BeFalse();
703704
}
705+
706+
[Test]
707+
public async Task CreateSourceTableAsync()
708+
{
709+
//Arrange
710+
CreateHttpMocks(@"[{""@type"":""tables""}]");
711+
712+
var creationMetadata = new EntityCreationMetadata("moviesByTitle", 1)
713+
{
714+
Replicas = 1,
715+
Partitions = 1,
716+
ShouldPluralizeEntityName = true,
717+
};
718+
719+
//Act
720+
var response = await ClassUnderTest.CreateSourceTableAsync<Movie>(creationMetadata);
721+
722+
//Assert
723+
var expectedContent = GetExpectedContent(@"CREATE SOURCE TABLE Movies (\r\n\tTitle VARCHAR,\r\n\tId INT PRIMARY KEY,\r\n\tRelease_Year INT\r\n) WITH ( KAFKA_TOPIC=\u0027moviesByTitle\u0027, VALUE_FORMAT=\u0027Json\u0027, PARTITIONS=\u00271\u0027, REPLICAS=\u00271\u0027 );".ReplaceLineEndings());
724+
725+
VerifySendAsync(expectedContent);
726+
727+
response.StatusCode.Should().Be(HttpStatusCode.OK);
728+
}
729+
730+
[Test]
731+
public async Task CreateSourceStreamAsync()
732+
{
733+
//Arrange
734+
CreateHttpMocks(@"[{""@type"":""streams""}]");
735+
736+
var creationMetadata = new EntityCreationMetadata("moviesByTitle", 1)
737+
{
738+
Replicas = 1,
739+
Partitions = 1,
740+
ShouldPluralizeEntityName = true,
741+
};
742+
743+
//Act
744+
var response = await ClassUnderTest.CreateSourceStreamAsync<Movie>(creationMetadata);
745+
746+
//Assert
747+
var expectedContent = GetExpectedContent(@"CREATE SOURCE STREAM Movies (\r\n\tTitle VARCHAR,\r\n\tId INT KEY,\r\n\tRelease_Year INT\r\n) WITH ( KAFKA_TOPIC=\u0027moviesByTitle\u0027, VALUE_FORMAT=\u0027Json\u0027, PARTITIONS=\u00271\u0027, REPLICAS=\u00271\u0027 );".ReplaceLineEndings());
748+
749+
VerifySendAsync(expectedContent);
750+
751+
response.StatusCode.Should().Be(HttpStatusCode.OK);
752+
}
704753
}

ksqlDb.RestApi.Client/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ksqlDB.RestApi.Client
22

3+
# 6.2.1
4+
5+
## BugFix
6+
- Source table can't be queried #87 - fixed `KSqlDbRestApiClient.CreateSourceTableAsync` and `KSqlDbRestApiClient.CreateSourceStreamAsync`
7+
38
# 6.2.0
49

510
1. **KSqlDbRestApiClient Constructor Update**:

ksqlDb.RestApi.Client/KSql/RestApi/KSqlDbRestApiClient.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,15 @@ public Task<HttpResponseMessage> CreateSourceStreamAsync<T>(EntityCreationMetada
281281
ArgumentNullException.ThrowIfNull(creationMetadata);
282282
#endif
283283

284+
creationMetadata = creationMetadata with
285+
{
286+
IsReadOnly = true
287+
};
288+
284289
if (creationMetadata.ShouldPluralizeEntityName == null)
285290
creationMetadata = creationMetadata with
286291
{
287292
ShouldPluralizeEntityName = clientOptions.ShouldPluralizeFromItemName,
288-
IsReadOnly = true
289293
};
290294

291295
var ksql = statementGenerator.CreateStream<T>(creationMetadata, ifNotExists);
@@ -333,11 +337,15 @@ public Task<HttpResponseMessage> CreateSourceTableAsync<T>(EntityCreationMetadat
333337
ArgumentNullException.ThrowIfNull(creationMetadata);
334338
#endif
335339

340+
creationMetadata = creationMetadata with
341+
{
342+
IsReadOnly = true
343+
};
344+
336345
if (creationMetadata.ShouldPluralizeEntityName == null)
337346
creationMetadata = creationMetadata with
338347
{
339348
ShouldPluralizeEntityName = clientOptions.ShouldPluralizeFromItemName,
340-
IsReadOnly = true
341349
};
342350

343351
var ksql = statementGenerator.CreateTable<T>(creationMetadata, ifNotExists);

ksqlDb.RestApi.Client/ksqlDb.RestApi.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Documentation for the library can be found at https://github.com/tomasfabian/ksqlDB.RestApi.Client-DotNet/blob/main/README.md.
1616
</Description>
1717
<PackageTags>ksql ksqlDB LINQ .NET csharp push query</PackageTags>
18-
<Version>6.2.0</Version>
18+
<Version>6.2.1</Version>
1919
<AssemblyVersion>6.2.0.0</AssemblyVersion>
2020
<LangVersion>12.0</LangVersion>
2121
<ImplicitUsings>enable</ImplicitUsings>

0 commit comments

Comments
 (0)