syhily commented on a change in pull request #17271: URL: https://github.com/apache/flink/pull/17271#discussion_r708313629
########## File path: flink-end-to-end-tests/flink-end-to-end-tests-pulsar/src/test/java/org/apache/flink/tests/util/pulsar/PulsarSourceKeySharedE2ECase.java ########## @@ -0,0 +1,124 @@ +/* + * 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.flink.tests.util.pulsar; + +import org.apache.flink.api.common.eventtime.WatermarkStrategy; +import org.apache.flink.connector.pulsar.source.PulsarSource; +import org.apache.flink.connector.pulsar.source.enumerator.cursor.StopCursor; +import org.apache.flink.connector.pulsar.source.enumerator.topic.TopicRange; +import org.apache.flink.connector.pulsar.source.enumerator.topic.range.FixedRangeGenerator; +import org.apache.flink.connector.pulsar.testutils.PulsarTestEnvironment; +import org.apache.flink.connector.pulsar.testutils.runtime.PulsarRuntimeOperator; +import org.apache.flink.connectors.test.common.junit.extensions.TestLoggerExtension; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; + +import org.apache.pulsar.client.api.RegexSubscriptionMode; +import org.apache.pulsar.client.api.Schema; +import org.apache.pulsar.client.api.SubscriptionType; +import org.apache.pulsar.common.util.Murmur3_32Hash; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.List; +import java.util.stream.Stream; + +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.apache.flink.connector.pulsar.source.enumerator.topic.TopicRange.RANGE_SIZE; +import static org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchema.pulsarSchema; +import static org.apache.flink.connector.pulsar.testutils.runtime.PulsarRuntime.container; +import static org.apache.flink.connector.pulsar.testutils.runtime.container.PulsarContainerRuntime.PULSAR_ADMIN_URL; +import static org.apache.flink.connector.pulsar.testutils.runtime.container.PulsarContainerRuntime.PULSAR_SERVICE_URL; +import static org.apache.pulsar.client.api.Schema.STRING; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; + +/** Pulsar E2E test for Key_Shared subscription. */ +@ExtendWith(TestLoggerExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@SuppressWarnings("java:S3577") +class PulsarSourceKeySharedE2ECase { + + /** Flink runtime. */ + @RegisterExtension + final FlinkContainerWithPulsarEnvironment flink = new FlinkContainerWithPulsarEnvironment(1, 6); + + /** Pulsar runtime. */ + @RegisterExtension + final PulsarTestEnvironment pulsar = + new PulsarTestEnvironment(container(flink.getFlinkContainer())); + + @Test + void testConsumingMessageFromTheSpecifiedHashRange() throws Exception { + // Produce test data to pulsar topic. + String key1 = randomAlphabetic(8); + String key2; + do { + key2 = randomAlphabetic(8); + } while (keyHash(key1) == keyHash(key2)); + + String topic = "pulsar-key-shared-a-" + randomAlphabetic(8); + List<String> messages1 = + Stream.generate(() -> key1 + "-" + randomAlphabetic(32)) + .limit(50) + .collect(toList()); + + String finalKey = key2; + List<String> messages2 = + Stream.generate(() -> finalKey + "-" + randomAlphabetic(32)) + .limit(50) + .collect(toList()); + + PulsarRuntimeOperator operator = pulsar.operator(); + operator.createTopic(topic, 1); + operator.sendMessages(topic, Schema.STRING, key1, messages1); + operator.sendMessages(topic, Schema.STRING, key2, messages2); + + // Create flink data stream. + int keyHash = keyHash(key2); Review comment: Nope, the zero is accepted. The hash range is between 0 and 65535. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org