Search in sources :

Example 1 with SchemaAndMetadata

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);
    }
}
Also used : SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) LongSchemaVersion(org.apache.pulsar.common.schema.LongSchemaVersion) HashFunction(com.google.common.hash.HashFunction) ArrayList(java.util.ArrayList) SchemaAndMetadata(org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata) PrometheusMetricsTest(org.apache.pulsar.broker.stats.PrometheusMetricsTest) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with SchemaAndMetadata

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);
    });
}
Also used : GetAllVersionsSchemaResponse(org.apache.pulsar.common.protocol.schema.GetAllVersionsSchemaResponse) TopicName(org.apache.pulsar.common.naming.TopicName) IsCompatibilityResponse(org.apache.pulsar.common.protocol.schema.IsCompatibilityResponse) AdminResource(org.apache.pulsar.broker.admin.AdminResource) SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService) LoggerFactory(org.slf4j.LoggerFactory) PostSchemaResponse(org.apache.pulsar.common.protocol.schema.PostSchemaResponse) CompletableFuture(java.util.concurrent.CompletableFuture) ByteBuffer(java.nio.ByteBuffer) SchemaType(org.apache.pulsar.common.schema.SchemaType) DefaultImplementation(org.apache.pulsar.client.internal.DefaultImplementation) MediaType(javax.ws.rs.core.MediaType) GetSchemaResponse(org.apache.pulsar.common.protocol.schema.GetSchemaResponse) Pair(org.apache.commons.lang3.tuple.Pair) RestException(org.apache.pulsar.broker.web.RestException) Objects.isNull(java.util.Objects.isNull) Charsets(com.google.common.base.Charsets) StringUtils.defaultIfEmpty(org.apache.commons.lang.StringUtils.defaultIfEmpty) Logger(org.slf4j.Logger) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) UTF_8(java.nio.charset.StandardCharsets.UTF_8) AsyncResponse(javax.ws.rs.container.AsyncResponse) IOException(java.io.IOException) DeleteSchemaResponse(org.apache.pulsar.common.protocol.schema.DeleteSchemaResponse) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) Collectors(java.util.stream.Collectors) LongSchemaVersionResponse(org.apache.pulsar.common.protocol.schema.LongSchemaVersionResponse) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Response(javax.ws.rs.core.Response) LongSchemaVersion(org.apache.pulsar.common.schema.LongSchemaVersion) Clock(java.time.Clock) SchemaData(org.apache.pulsar.common.protocol.schema.SchemaData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PostSchemaPayload(org.apache.pulsar.common.protocol.schema.PostSchemaPayload) SchemaAndMetadata(org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata) InvalidSchemaDataException(org.apache.pulsar.broker.service.schema.exceptions.InvalidSchemaDataException) IncompatibleSchemaException(org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) LongSchemaVersion(org.apache.pulsar.common.schema.LongSchemaVersion) SchemaRegistryService(org.apache.pulsar.broker.service.schema.SchemaRegistryService) ByteBuffer(java.nio.ByteBuffer)

Example 3 with SchemaAndMetadata

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);
    }
}
Also used : SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) LongSchemaVersion(org.apache.pulsar.common.schema.LongSchemaVersion) HashFunction(com.google.common.hash.HashFunction) ArrayList(java.util.ArrayList) SchemaAndMetadata(org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata) PrometheusMetricsTest(org.apache.pulsar.broker.stats.PrometheusMetricsTest) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with SchemaAndMetadata

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);
    }
}
Also used : SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) LongSchemaVersion(org.apache.pulsar.common.schema.LongSchemaVersion) HashFunction(com.google.common.hash.HashFunction) ArrayList(java.util.ArrayList) SchemaAndMetadata(org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

SchemaAndMetadata (org.apache.pulsar.broker.service.schema.SchemaRegistry.SchemaAndMetadata)4 SchemaVersion (org.apache.pulsar.common.protocol.schema.SchemaVersion)4 LongSchemaVersion (org.apache.pulsar.common.schema.LongSchemaVersion)4 HashFunction (com.google.common.hash.HashFunction)3 ArrayList (java.util.ArrayList)3 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)3 PrometheusMetricsTest (org.apache.pulsar.broker.stats.PrometheusMetricsTest)2 Test (org.testng.annotations.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Charsets (com.google.common.base.Charsets)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Clock (java.time.Clock)1 List (java.util.List)1 Objects.isNull (java.util.Objects.isNull)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1 MediaType (javax.ws.rs.core.MediaType)1