Skip to content

Commit ca3d380

Browse files
authored
Add clearLatestCaches/clearCaches API, fix test to call clearLatestCaches (#102)
* Add clearLatestCaches for use in tests * Minor cleanup * Minor cleanup
1 parent c64b0da commit ca3d380

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

schemaregistry/mock-schemaregistry-client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ class MockClient implements Client {
426426
return config;
427427
}
428428

429+
clearLatestCaches(): void {
430+
return;
431+
}
432+
433+
clearCaches(): void {
434+
return;
435+
}
436+
429437
async close(): Promise<void> {
430438
return;
431439
}

schemaregistry/schemaregistry-client.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export interface Client {
135135
updateConfig(subject: string, update: ServerConfig): Promise<ServerConfig>;
136136
getDefaultConfig(): Promise<ServerConfig>;
137137
updateDefaultConfig(update: ServerConfig): Promise<ServerConfig>;
138+
clearLatestCaches(): void;
139+
clearCaches(): void;
138140
close(): void;
139141
}
140142

@@ -557,13 +559,23 @@ export class SchemaRegistryClient implements Client {
557559
return response.data;
558560
}
559561

560-
close(): void {
562+
clearLatestCaches(): void {
563+
this.latestToSchemaCache.clear();
564+
this.metadataToSchemaCache.clear();
565+
}
566+
567+
clearCaches(): void {
568+
this.schemaToIdCache.clear();
569+
this.idToSchemaInfoCache.clear();
561570
this.infoToSchemaCache.clear();
571+
this.latestToSchemaCache.clear();
562572
this.schemaToVersionCache.clear();
563573
this.versionToSchemaCache.clear();
564-
this.idToSchemaInfoCache.clear();
574+
this.metadataToSchemaCache.clear();
575+
}
565576

566-
return;
577+
async close(): Promise<void> {
578+
this.clearCaches();
567579
}
568580

569581
// Cache methods for testing

test/schemaregistry/serde/avro.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ describe('AvroSerializer', () => {
401401

402402
await client.register(subject, info, false)
403403

404+
client.clearLatestCaches()
404405
let deser = new AvroDeserializer(client, SerdeType.VALUE, {useLatestVersion: true})
405406
let obj2 = await deser.deserialize(topic, bytes)
406407
expect(obj2.fieldToDelete).toEqual(undefined);

0 commit comments

Comments
 (0)