Skip to content

Commit

Permalink
Merge branch '7.4.x' into 7.5.x by rayokota
Browse files Browse the repository at this point in the history
  • Loading branch information
ConfluentJenkins committed Dec 19, 2023
2 parents d988d5d + c62d8f9 commit 8460e7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,18 @@ public Collection<String> getAllSubjectsById(int id) {
public Collection<SubjectVersion> getAllVersionsById(int id) {
return idToSchemaCache.entrySet().stream()
.filter(entry -> entry.getValue().containsKey(id))
.map(e -> {
.flatMap(e -> {
ParsedSchema schema = e.getValue().get(id);
int version = schemaToVersionCache.get(e.getKey()).get(schema);
return new SubjectVersion(e.getKey(), version);
}).collect(Collectors.toList());
Map<ParsedSchema, Integer> schemaVersionMap = schemaToVersionCache.get(e.getKey());
if (schemaVersionMap != null) {
int version = schemaVersionMap.get(schema);
return Stream.of(new SubjectVersion(e.getKey(), version));
} else {
return Stream.empty();
}
})
.distinct()
.collect(Collectors.toList());
}

private int getLatestVersion(String subject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.confluent.kafka.schemaregistry.ClusterTestHarness;
import io.confluent.kafka.schemaregistry.avro.AvroSchema;
import io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider;
import io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion;
import java.util.Collection;
import java.util.Collections;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
Expand Down Expand Up @@ -200,5 +202,16 @@ public void testRegisterAndGetId() throws Exception {
id = client.getId("test2", schema2);
assertEquals(2, id);
}

@Test
public void testGetAllVersionsById() throws Exception {
AvroSchema avroSchema = new AvroSchema("{\"type\":\"record\",\"name\":\"ts1\","
+ "\"fields\":[{\"name\": \"fld1\",\"type\": \"int\"}]}");
MockSchemaRegistryClient client =
new MockSchemaRegistryClient(Collections.singletonList(new AvroSchemaProvider()));
int id = client.register("test-value", avroSchema);
Collection<SubjectVersion> versions = client.getAllVersionsById(id);
assertEquals(new SubjectVersion("test-value", 1), versions.iterator().next());
}
}

0 comments on commit 8460e7c

Please sign in to comment.