Skip to content

Commit 13cede4

Browse files
authored
Karapace 3.3.0 compatibility (#18) (#19)
* Karapace 3.3.0 compatibility (#18) * add version not found as valid ex * add new test * improvements * fix logic * fix: fix cs Authored by: Nick <[email protected]>
1 parent ea730bb commit 13cede4

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/KafkaSchemaRegistryApiClient.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jobcloud\Kafka\SchemaRegistryClient;
44

55
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SchemaRegistryExceptionInterface;
6+
use Jobcloud\Kafka\SchemaRegistryClient\Exception\VersionNotFoundException;
67
use Psr\Http\Client\ClientExceptionInterface;
78
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SchemaNotFoundException;
89
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SubjectNotFoundException;
@@ -111,7 +112,7 @@ public function registerNewSchemaVersion(string $subjectName, string $schema): a
111112
/**
112113
* @throws ClientExceptionInterface
113114
* @throws SchemaRegistryExceptionInterface
114-
* @throws JsonException
115+
* @throws JsonException|VersionNotFoundException
115116
*/
116117
public function checkSchemaCompatibilityForVersion(
117118
string $subjectName,
@@ -126,7 +127,11 @@ public function checkSchemaCompatibilityForVersion(
126127
sprintf('compatibility/subjects/%s/versions/%s', $subjectName, $version),
127128
$this->createRequestBodyFromSchema($schema)
128129
);
129-
} catch (SubjectNotFoundException $e) {
130+
} catch (SubjectNotFoundException | VersionNotFoundException $e) {
131+
if ($e instanceof VersionNotFoundException && self::VERSION_LATEST !== $version) {
132+
throw $e;
133+
}
134+
130135
return true;
131136
}
132137

tests/KafkaSchemaRegistryApiClientTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Jobcloud\Kafka\SchemaRegistryClient\Exception\ImportException;
66
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SchemaNotFoundException;
77
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SubjectNotFoundException;
8+
use Jobcloud\Kafka\SchemaRegistryClient\Exception\VersionNotFoundException;
89
use Jobcloud\Kafka\SchemaRegistryClient\HttpClient;
910
use Jobcloud\Kafka\SchemaRegistryClient\HttpClientInterface;
1011
use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClient;
@@ -208,7 +209,7 @@ public function testCheckSchemaCompatibilityForVersionFalse(): void
208209
self::assertFalse($result);
209210
}
210211

211-
public function testCheckSchemaCompatibilityForVersionNotFound(): void
212+
public function testCheckSchemaCompatibilityForSubjectNotFound(): void
212213
{
213214
$httpClientMock = $this->getHttpClientMock();
214215

@@ -231,6 +232,56 @@ public function testCheckSchemaCompatibilityForVersionNotFound(): void
231232
self::assertTrue($result);
232233
}
233234

235+
public function testCheckSchemaCompatibilityForVersionNotFound(): void
236+
{
237+
self::expectException(VersionNotFoundException::class);
238+
$httpClientMock = $this->getHttpClientMock();
239+
240+
$httpClientMock
241+
->expects(self::once())
242+
->method('call')
243+
->with(
244+
'POST',
245+
sprintf('compatibility/subjects/%s/versions/%s', self::TEST_SUBJECT_NAME, self::TEST_VERSION),
246+
['schema' => '[]']
247+
)
248+
->willThrowException(new VersionNotFoundException());
249+
250+
$api = new KafkaSchemaRegistryApiClient($httpClientMock);
251+
$result = $api->checkSchemaCompatibilityForVersion(
252+
self::TEST_SUBJECT_NAME,
253+
self::TEST_SCHEMA,
254+
self::TEST_VERSION
255+
);
256+
}
257+
258+
public function testCheckSchemaCompatibilityForVersionNotFoundLatest(): void
259+
{
260+
$httpClientMock = $this->getHttpClientMock();
261+
262+
$httpClientMock
263+
->expects(self::once())
264+
->method('call')
265+
->with(
266+
'POST',
267+
sprintf(
268+
'compatibility/subjects/%s/versions/%s',
269+
self::TEST_SUBJECT_NAME,
270+
KafkaSchemaRegistryApiClient::VERSION_LATEST
271+
),
272+
['schema' => '[]']
273+
)
274+
->willThrowException(new VersionNotFoundException());
275+
276+
$api = new KafkaSchemaRegistryApiClient($httpClientMock);
277+
$result = $api->checkSchemaCompatibilityForVersion(
278+
self::TEST_SUBJECT_NAME,
279+
self::TEST_SCHEMA,
280+
KafkaSchemaRegistryApiClient::VERSION_LATEST
281+
);
282+
self::assertTrue($result);
283+
}
284+
234285
public function testGetSubjectCompatibilityLevel(): void
235286
{
236287
$httpClientMock = $this->getHttpClientMock();

0 commit comments

Comments
 (0)