24
24
import org .apache .kafka .clients .consumer .KafkaConsumer ;
25
25
import org .apache .kafka .clients .producer .KafkaProducer ;
26
26
import org .apache .kafka .clients .producer .Producer ;
27
- import org .apache .kafka .clients .producer .ProducerConfig ;
28
27
import org .apache .kafka .common .Metric ;
29
28
import org .apache .kafka .common .MetricName ;
30
29
import org .apache .kafka .common .Uuid ;
42
41
import org .apache .kafka .streams .ClientInstanceIds ;
43
42
import org .apache .kafka .streams .KafkaClientSupplier ;
44
43
import org .apache .kafka .streams .KafkaStreams ;
45
- import org .apache .kafka .streams .KeyValue ;
46
44
import org .apache .kafka .streams .StreamsBuilder ;
47
45
import org .apache .kafka .streams .StreamsConfig ;
48
46
import org .apache .kafka .streams .Topology ;
@@ -167,10 +165,6 @@ public void tearDown() throws Exception {
167
165
public void shouldPushGlobalThreadMetricsToBroker (final String recordingLevel ) throws Exception {
168
166
streamsApplicationProperties = props (true );
169
167
streamsApplicationProperties .put (StreamsConfig .METRICS_RECORDING_LEVEL_CONFIG , recordingLevel );
170
- IntegrationTestUtils .produceKeyValuesSynchronously (globalStoreTopic ,
171
- List .of (KeyValue .pair ("1" , "one" ), KeyValue .pair ("2" , "two" ), KeyValue .pair ("3" , "three" )),
172
- producerProperties (),
173
- cluster .time );
174
168
final Topology topology = simpleTopology (true );
175
169
subscribeForStreamsMetrics ();
176
170
try (final KafkaStreams streams = new KafkaStreams (topology , streamsApplicationProperties )) {
@@ -449,14 +443,6 @@ private static Stream<Arguments> multiTaskParameters() {
449
443
Arguments .of (false ));
450
444
}
451
445
452
- private Properties producerProperties () {
453
- final Properties properties = new Properties ();
454
- properties .put (ProducerConfig .BOOTSTRAP_SERVERS_CONFIG , cluster .bootstrapServers ());
455
- properties .put (ProducerConfig .KEY_SERIALIZER_CLASS_CONFIG , Serdes .String ().serializer ().getClass ());
456
- properties .put (ProducerConfig .VALUE_SERIALIZER_CLASS_CONFIG , Serdes .String ().serializer ().getClass ());
457
- return properties ;
458
- }
459
-
460
446
private Properties props (final boolean stateUpdaterEnabled ) {
461
447
return props (mkObjectProperties (mkMap (mkEntry (StreamsConfig .InternalConfig .STATE_UPDATER_ENABLED , stateUpdaterEnabled ))));
462
448
}
@@ -486,7 +472,8 @@ private Topology complexTopology() {
486
472
}
487
473
488
474
private void addGlobalStore (final StreamsBuilder builder ) {
489
- builder .addGlobalStore (Stores .keyValueStoreBuilder (
475
+ builder .addGlobalStore (
476
+ Stores .keyValueStoreBuilder (
490
477
Stores .inMemoryKeyValueStore ("iq-test-store" ),
491
478
Serdes .String (),
492
479
Serdes .String ()
@@ -496,16 +483,20 @@ private void addGlobalStore(final StreamsBuilder builder) {
496
483
() -> new Processor <>() {
497
484
private KeyValueStore <String , String > store ;
498
485
486
+ // The store iterator is intentionally not closed here as it needs
487
+ // to be open during the test, so the Streams app will emit the
488
+ // org.apache.kafka.stream.state.oldest.iterator.open.since.ms metric
489
+ // that is expected. So the globalStoreIterator is a global variable
490
+ // (pun not intended), so it can be closed in the tearDown method.
499
491
@ Override
500
492
public void init (final ProcessorContext <Void , Void > context ) {
501
493
store = context .getStateStore ("iq-test-store" );
494
+ globalStoreIterator = store .all ();
502
495
}
503
496
504
497
@ Override
505
498
public void process (final Record <String , String > record ) {
506
499
store .put (record .key (), record .value ());
507
- globalStoreIterator = store .all ();
508
- globalStoreIterator .forEachRemaining (kv -> System .out .printf ("key %s value %s%n" , kv .key , kv .value ));
509
500
}
510
501
});
511
502
}
0 commit comments