use of org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata in project pulsar by yahoo.
the class SchemaServiceTest method trimDeletedSchemaAndGetListTest.
@Test
public void trimDeletedSchemaAndGetListTest() throws Exception {
List<SchemaAndMetadata> list = new ArrayList<>();
CompletableFuture<SchemaVersion> put = schemaRegistryService.putSchemaIfAbsent(schemaId1, schemaData1, SchemaCompatibilityStrategy.FULL);
SchemaVersion newVersion = put.get();
list.add(new SchemaAndMetadata(schemaId1, schemaData1, newVersion));
put = schemaRegistryService.putSchemaIfAbsent(schemaId1, schemaData2, SchemaCompatibilityStrategy.FULL);
newVersion = put.get();
list.add(new SchemaAndMetadata(schemaId1, schemaData2, newVersion));
List<SchemaAndMetadata> list1 = schemaRegistryService.trimDeletedSchemaAndGetList(schemaId1).get();
assertEquals(list.size(), list1.size());
HashFunction hashFunction = Hashing.sha256();
for (int i = 0; i < list.size(); i++) {
SchemaAndMetadata schemaAndMetadata1 = list.get(i);
SchemaAndMetadata schemaAndMetadata2 = list1.get(i);
assertEquals(hashFunction.hashBytes(schemaAndMetadata1.schema.getData()).asBytes(), hashFunction.hashBytes(schemaAndMetadata2.schema.getData()).asBytes());
assertEquals(((LongSchemaVersion) schemaAndMetadata1.version).getVersion(), ((LongSchemaVersion) schemaAndMetadata2.version).getVersion());
assertEquals(schemaAndMetadata1.id, schemaAndMetadata2.id);
}
}
use of org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata in project incubator-pulsar by apache.
the class SchemasResourceBase method getSchemaAsync.
public CompletableFuture<SchemaAndMetadata> getSchemaAsync(boolean authoritative, String version) {
return validateDestinationAndAdminOperationAsync(authoritative).thenApply(__ -> getSchemaId()).thenCompose(schemaId -> {
ByteBuffer bbVersion = ByteBuffer.allocate(Long.BYTES);
bbVersion.putLong(Long.parseLong(version));
SchemaRegistryService schemaRegistryService = pulsar().getSchemaRegistryService();
SchemaVersion schemaVersion = schemaRegistryService.versionFromBytes(bbVersion.array());
return schemaRegistryService.getSchema(schemaId, schemaVersion);
});
}
use of org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata in project incubator-pulsar by apache.
the class SchemaServiceTest method trimDeletedSchemaAndGetListTest.
@Test
public void trimDeletedSchemaAndGetListTest() throws Exception {
List<SchemaAndMetadata> list = new ArrayList<>();
CompletableFuture<SchemaVersion> put = schemaRegistryService.putSchemaIfAbsent(schemaId1, schemaData1, SchemaCompatibilityStrategy.FULL);
SchemaVersion newVersion = put.get();
list.add(new SchemaAndMetadata(schemaId1, schemaData1, newVersion));
put = schemaRegistryService.putSchemaIfAbsent(schemaId1, schemaData2, SchemaCompatibilityStrategy.FULL);
newVersion = put.get();
list.add(new SchemaAndMetadata(schemaId1, schemaData2, newVersion));
List<SchemaAndMetadata> list1 = schemaRegistryService.trimDeletedSchemaAndGetList(schemaId1).get();
assertEquals(list.size(), list1.size());
HashFunction hashFunction = Hashing.sha256();
for (int i = 0; i < list.size(); i++) {
SchemaAndMetadata schemaAndMetadata1 = list.get(i);
SchemaAndMetadata schemaAndMetadata2 = list1.get(i);
assertEquals(hashFunction.hashBytes(schemaAndMetadata1.schema.getData()).asBytes(), hashFunction.hashBytes(schemaAndMetadata2.schema.getData()).asBytes());
assertEquals(((LongSchemaVersion) schemaAndMetadata1.version).getVersion(), ((LongSchemaVersion) schemaAndMetadata2.version).getVersion());
assertEquals(schemaAndMetadata1.id, schemaAndMetadata2.id);
}
}
use of org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata in project pulsar by apache.
the class SchemaServiceTest method trimDeletedSchemaAndGetListTest.
@Test
public void trimDeletedSchemaAndGetListTest() throws Exception {
List<SchemaAndMetadata> list = new ArrayList<>();
CompletableFuture<SchemaVersion> put = schemaRegistryService.putSchemaIfAbsent(schemaId1, schemaData1, SchemaCompatibilityStrategy.FULL);
SchemaVersion newVersion = put.get();
list.add(new SchemaAndMetadata(schemaId1, schemaData1, newVersion));
put = schemaRegistryService.putSchemaIfAbsent(schemaId1, schemaData2, SchemaCompatibilityStrategy.FULL);
newVersion = put.get();
list.add(new SchemaAndMetadata(schemaId1, schemaData2, newVersion));
List<SchemaAndMetadata> list1 = schemaRegistryService.trimDeletedSchemaAndGetList(schemaId1).get();
assertEquals(list.size(), list1.size());
HashFunction hashFunction = Hashing.sha256();
for (int i = 0; i < list.size(); i++) {
SchemaAndMetadata schemaAndMetadata1 = list.get(i);
SchemaAndMetadata schemaAndMetadata2 = list1.get(i);
assertEquals(hashFunction.hashBytes(schemaAndMetadata1.schema.getData()).asBytes(), hashFunction.hashBytes(schemaAndMetadata2.schema.getData()).asBytes());
assertEquals(((LongSchemaVersion) schemaAndMetadata1.version).getVersion(), ((LongSchemaVersion) schemaAndMetadata2.version).getVersion());
assertEquals(schemaAndMetadata1.id, schemaAndMetadata2.id);
}
}
Aggregations