You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/05/18 11:15:12 UTC

[GitHub] [pulsar] eolivelli commented on a diff in pull request #14102: PIP-144: Making SchemaRegistry implementation configurable

eolivelli commented on code in PR #14102:
URL: https://github.com/apache/pulsar/pull/14102#discussion_r875768695


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/MockSchemaRegistry.java:
##########
@@ -0,0 +1,220 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service.schema;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.pulsar.broker.service.schema.SchemaRegistryServiceImpl.Functions.convertToDomainType;
+import static org.apache.pulsar.broker.service.schema.SchemaRegistryServiceImpl.Functions.toMap;
+import com.google.protobuf.InvalidProtocolBufferException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.schema.proto.SchemaRegistryFormat;
+import org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy;
+import org.apache.pulsar.common.protocol.schema.SchemaData;
+import org.apache.pulsar.common.protocol.schema.SchemaHash;
+import org.apache.pulsar.common.protocol.schema.SchemaStorage;
+import org.apache.pulsar.common.protocol.schema.SchemaVersion;
+import org.apache.pulsar.common.protocol.schema.StoredSchema;
+import org.apache.pulsar.common.schema.LongSchemaVersion;
+
+public class MockSchemaRegistry extends SchemaRegistryServiceImpl {
+    ServiceConfiguration serviceConfiguration;
+    SchemaStorage schemaStorage;
+
+    @Override
+    public CompletableFuture<SchemaAndMetadata> getSchema(String schemaId) {
+        CompletableFuture<SchemaAndMetadata> result = new CompletableFuture<>();
+        CompletableFuture<List<CompletableFuture<StoredSchema>>> storedSchemaCompletableFuture =
+                this.schemaStorage.getAll(schemaId);
+
+        try {
+            int version = storedSchemaCompletableFuture.get().size() - 1;
+            SchemaRegistryFormat.SchemaInfo info = SchemaRegistryFormat.SchemaInfo.parseFrom(
+                    storedSchemaCompletableFuture.get().get(version).get().data);
+            SchemaData schemaData = SchemaData.builder()
+                    .user(info.getUser())
+                    .type(convertToDomainType(info.getType()))
+                    .data(info.getSchema().toByteArray())
+                    .isDeleted(info.getDeleted())
+                    .props(toMap(info.getPropsList()))
+                    .build();
+            result.complete(new SchemaAndMetadata(schemaId, schemaData,
+                    storedSchemaCompletableFuture.get().get(version).get().version));
+        } catch (InterruptedException e) {
+            e.printStackTrace();

Review Comment:
   please use logger



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/MockSchemaRegistry.java:
##########
@@ -0,0 +1,220 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service.schema;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.pulsar.broker.service.schema.SchemaRegistryServiceImpl.Functions.convertToDomainType;
+import static org.apache.pulsar.broker.service.schema.SchemaRegistryServiceImpl.Functions.toMap;
+import com.google.protobuf.InvalidProtocolBufferException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.service.schema.proto.SchemaRegistryFormat;
+import org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy;
+import org.apache.pulsar.common.protocol.schema.SchemaData;
+import org.apache.pulsar.common.protocol.schema.SchemaHash;
+import org.apache.pulsar.common.protocol.schema.SchemaStorage;
+import org.apache.pulsar.common.protocol.schema.SchemaVersion;
+import org.apache.pulsar.common.protocol.schema.StoredSchema;
+import org.apache.pulsar.common.schema.LongSchemaVersion;
+
+public class MockSchemaRegistry extends SchemaRegistryServiceImpl {
+    ServiceConfiguration serviceConfiguration;
+    SchemaStorage schemaStorage;
+
+    @Override
+    public CompletableFuture<SchemaAndMetadata> getSchema(String schemaId) {
+        CompletableFuture<SchemaAndMetadata> result = new CompletableFuture<>();
+        CompletableFuture<List<CompletableFuture<StoredSchema>>> storedSchemaCompletableFuture =
+                this.schemaStorage.getAll(schemaId);
+
+        try {
+            int version = storedSchemaCompletableFuture.get().size() - 1;
+            SchemaRegistryFormat.SchemaInfo info = SchemaRegistryFormat.SchemaInfo.parseFrom(
+                    storedSchemaCompletableFuture.get().get(version).get().data);
+            SchemaData schemaData = SchemaData.builder()
+                    .user(info.getUser())
+                    .type(convertToDomainType(info.getType()))
+                    .data(info.getSchema().toByteArray())
+                    .isDeleted(info.getDeleted())
+                    .props(toMap(info.getPropsList()))
+                    .build();
+            result.complete(new SchemaAndMetadata(schemaId, schemaData,
+                    storedSchemaCompletableFuture.get().get(version).get().version));
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            e.printStackTrace();
+        } catch (InvalidProtocolBufferException e) {
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+    @Override
+    public CompletableFuture<SchemaAndMetadata> getSchema(String schemaId, SchemaVersion version) {
+        CompletableFuture<SchemaAndMetadata> result = new CompletableFuture<>();
+        int versionInt = ByteBuffer.wrap(version.bytes()).getInt();
+        CompletableFuture<List<CompletableFuture<StoredSchema>>> storedSchemaCompletableFuture =
+                this.schemaStorage.getAll(schemaId);
+
+        try {
+            SchemaRegistryFormat.SchemaInfo info = SchemaRegistryFormat.SchemaInfo.parseFrom(
+                    storedSchemaCompletableFuture.get().get(versionInt).get().data);
+            SchemaData schemaData = SchemaData.builder()
+                    .user(info.getUser())
+                    .type(convertToDomainType(info.getType()))
+                    .data(info.getSchema().toByteArray())
+                    .isDeleted(info.getDeleted())
+                    .props(toMap(info.getPropsList()))
+                    .build();
+            result.complete(new SchemaAndMetadata(schemaId, schemaData,
+                    storedSchemaCompletableFuture.get().get(versionInt).get().version));
+        } catch (InterruptedException e) {
+            e.printStackTrace();

Review Comment:
   please use logger



##########
tests/integration/src/test/java/org/apache/pulsar/tests/integration/schema/SchemaRegistryTest.java:
##########
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.tests.integration.schema;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.fail;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.function.Supplier;
+import lombok.Cleanup;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.SubscriptionType;
+import org.apache.pulsar.tests.integration.messaging.TopicMessagingBase;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+@Slf4j
+public class SchemaRegistryTest extends TopicMessagingBase {
+    protected String methodName;
+    private String SCHEMA_REGISTRY="org.apache.pulsar.broker.service.schema.MockSchemaRegistry";

Review Comment:
   nit: static ? also please add a white space around the '=' char



##########
pulsar-common/src/main/java/org/apache/pulsar/common/naming/Constants.java:
##########
@@ -24,6 +24,11 @@
 public class Constants {
 
     public static final String GLOBAL_CLUSTER = "global";
+    public static final String SCHEMA_REGISTRY_CLASS_NAME;

Review Comment:
   nit: please declare the value here: "org.apache.pulsar.broker.service.schema.SchemaRegistryServiceDisabled"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org