eolivelli commented on a change in pull request #9590:
URL: https://github.com/apache/pulsar/pull/9590#discussion_r593849914



##########
File path: 
tests/docker-images/java-test-functions/src/main/java/org/apache/pulsar/tests/integration/io/GenericRecordSource.java
##########
@@ -0,0 +1,88 @@
+/**
+ * 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.io;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.Field;
+import org.apache.pulsar.client.api.schema.GenericRecord;
+import org.apache.pulsar.client.api.schema.GenericSchema;
+import org.apache.pulsar.client.api.schema.RecordSchemaBuilder;
+import org.apache.pulsar.client.api.schema.SchemaBuilder;
+import org.apache.pulsar.common.schema.SchemaType;
+import org.apache.pulsar.functions.api.Record;
+import org.apache.pulsar.io.core.Source;
+import org.apache.pulsar.io.core.SourceContext;
+
+/**
+ * A source that generates {@link GenericRecord}s.
+ */
+@Slf4j
+public class GenericRecordSource implements Source<GenericRecord> {
+
+    private RecordSchemaBuilder recordSchemaBuilder;
+    private GenericSchema<GenericRecord> schema;
+    private List<Field> fields;
+    private AtomicInteger count = new AtomicInteger();
+
+    @Override
+    public void open(Map<String, Object> config, SourceContext sourceContext) 
throws Exception {
+        this.recordSchemaBuilder = SchemaBuilder.record("MyBean");
+        this.recordSchemaBuilder.field("number").type(SchemaType.INT32);
+        this.recordSchemaBuilder.field("text").type(SchemaType.STRING);
+        schema = 
Schema.generic(this.recordSchemaBuilder.build(SchemaType.AVRO));
+        fields = Arrays.asList(new Field("number", 0),
+            new Field("text", 1));
+        log.info("created source, schema {}", new 
String(schema.getSchemaInfo().getSchema(), StandardCharsets.UTF_8));
+    }
+
+    @Override
+    public Record<GenericRecord> read() throws Exception {
+        // slow down the production of values
+        Thread.sleep(20);
+
+        int value = count.incrementAndGet();
+        GenericRecord record = schema.newRecordBuilder()

Review comment:
       @sijie @codelipenghui unfortunately this is not exactly like my original 
test case, that reproduced my use case.
   That is to be able to push an object that implements GenericRecord.
   
   Here you are using the builder provided by Pulsar but this is mo enough for 
me, because my user would like to use an object from his own domain, just by 
implementing Pulsar GenericRecord java interface, because we will save 
resources (allocations and cycles)
   
   
   
https://github.com/apache/pulsar/pull/9481/files#diff-bbdf586ddad181a0a9dae17974b19ca5cbbce398716ec7fa5b4c45b69be58f41R66




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to