46
46
import java .util .concurrent .Executors ;
47
47
import java .util .concurrent .TimeUnit ;
48
48
import java .util .concurrent .atomic .AtomicInteger ;
49
+ import java .util .regex .Pattern ;
49
50
import java .util .stream .Collectors ;
50
51
import lombok .Cleanup ;
51
52
import lombok .EqualsAndHashCode ;
69
70
import org .apache .pulsar .client .api .TypedMessageBuilder ;
70
71
import org .apache .pulsar .client .api .schema .GenericRecord ;
71
72
import org .apache .pulsar .client .api .schema .SchemaDefinition ;
73
+ import org .apache .pulsar .client .impl .ConsumerImpl ;
74
+ import org .apache .pulsar .client .impl .MultiTopicsConsumerImpl ;
72
75
import org .apache .pulsar .client .impl .schema .KeyValueSchemaImpl ;
73
76
import org .apache .pulsar .client .impl .schema .ProtobufSchema ;
74
77
import org .apache .pulsar .client .impl .schema .SchemaInfoImpl ;
@@ -98,6 +101,7 @@ public class SchemaTest extends MockedPulsarServiceBaseTest {
98
101
@ BeforeMethod
99
102
@ Override
100
103
public void setup () throws Exception {
104
+ isTcpLookup = true ;
101
105
super .internalSetup ();
102
106
103
107
// Setup namespaces
@@ -106,6 +110,7 @@ public void setup() throws Exception {
106
110
.allowedClusters (Collections .singleton (CLUSTER_NAME ))
107
111
.build ();
108
112
admin .tenants ().createTenant (PUBLIC_TENANT , tenantInfo );
113
+ admin .namespaces ().createNamespace (PUBLIC_TENANT + "/my-ns" );
109
114
}
110
115
111
116
@ AfterMethod (alwaysRun = true )
@@ -130,6 +135,34 @@ public void testGetSchemaWhenCreateAutoProduceBytesProducer() throws Exception{
130
135
pulsarClient .newProducer (org .apache .pulsar .client .api .Schema .AUTO_PRODUCE_BYTES ()).topic (topic ).create ();
131
136
}
132
137
138
+ @ Test
139
+ public void testGetSchemaWithPatternTopic () throws Exception {
140
+ final String topicPrefix = "persistent://public/my-ns/test-getSchema" ;
141
+
142
+ int topicNums = 10 ;
143
+ for (int i = 0 ; i < topicNums ; i ++) {
144
+ String topic = topicPrefix + "-" + i ;
145
+ admin .topics ().createNonPartitionedTopic (topic );
146
+ }
147
+
148
+ Pattern pattern = Pattern .compile (topicPrefix + "-.*" );
149
+ @ Cleanup
150
+ Consumer <GenericRecord > consumer = pulsarClient .newConsumer (Schema .AUTO_CONSUME ())
151
+ .topicsPattern (pattern )
152
+ .subscriptionName ("sub" )
153
+ .subscriptionType (SubscriptionType .Shared )
154
+ .subscribe ();
155
+
156
+ List <ConsumerImpl <GenericRecord >> consumers =
157
+ ((MultiTopicsConsumerImpl <GenericRecord >) consumer ).getConsumers ();
158
+ Assert .assertEquals (topicNums , consumers .size ());
159
+
160
+ for (int i = 0 ; i < topicNums ; i ++) {
161
+ String topic = topicPrefix + "-" + i ;
162
+ admin .topics ().delete (topic , true );
163
+ }
164
+ }
165
+
133
166
@ Test
134
167
public void testMultiTopicSetSchemaProvider () throws Exception {
135
168
final String tenant = PUBLIC_TENANT ;
0 commit comments