crabka-client-streams 0.3.2

KIP-1071 Kafka Streams rebalance-protocol client for Apache Kafka in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//! `GroupTopics` + `application_id` → the byte-exact `StreamsGroupHeartbeat`
//! wire `Topology`. Every ordering rule here matches the JVM 4.x client.

use crabka_protocol::owned::common::streams_group_heartbeat_request::key_value::KeyValue;
use crabka_protocol::owned::common::streams_group_heartbeat_request::topic_info::TopicInfo;
use crabka_protocol::owned::streams_group_heartbeat_request::{
    CopartitionGroup, Subtopology, Topology,
};
use serde::Serialize;

use super::grouping::GroupTopics;

/// `replication_factor` the JVM client sends for every internal topic: `-1`
/// means "use the broker's `replication.factor` default" (KIP-1071 / the
/// `StreamsGroupHeartbeat` `TopicInfo` convention).
const INTERNAL_TOPIC_DEFAULT_RF: i16 = -1;

/// Topic configs the JVM 4.x client attaches to a **repartition** topic, sorted
/// by key (the wire array order the fixture pins).
fn repartition_topic_configs() -> Vec<KeyValue> {
    topic_configs([
        ("cleanup.policy", "delete"),
        ("message.timestamp.type", "CreateTime"),
        ("retention.ms", "-1"),
        ("segment.bytes", "52428800"),
    ])
}

/// Topic configs the JVM 4.x client attaches to a key/value-store **changelog**
/// topic, sorted by key.
fn changelog_topic_configs() -> Vec<KeyValue> {
    topic_configs([
        ("cleanup.policy", "compact"),
        ("message.timestamp.type", "CreateTime"),
    ])
}

/// Topic configs the JVM 4.x client attaches to a **windowed-store changelog**
/// topic: `compact,delete` policy + `retention.ms` to ensure expired windows are
/// actually purged. Keys are in sorted order (same rule as repartition configs).
fn windowed_changelog_topic_configs(retention_ms: i64) -> Vec<KeyValue> {
    vec![
        KeyValue {
            key: "cleanup.policy".into(),
            value: "compact,delete".into(),
            ..Default::default()
        },
        KeyValue {
            key: "message.timestamp.type".into(),
            value: "CreateTime".into(),
            ..Default::default()
        },
        KeyValue {
            key: "retention.ms".into(),
            value: retention_ms.to_string(),
            ..Default::default()
        },
    ]
}

/// Topic configs the JVM 4.x client attaches to a **join-window-store changelog**
/// topic: `delete`-only policy + `retention.ms`. Join window stores use
/// `retainDuplicates=true`, which prohibits compaction.
fn join_window_changelog_topic_configs(retention_ms: i64) -> Vec<KeyValue> {
    vec![
        KeyValue {
            key: "cleanup.policy".into(),
            value: "delete".into(),
            ..Default::default()
        },
        KeyValue {
            key: "message.timestamp.type".into(),
            value: "CreateTime".into(),
            ..Default::default()
        },
        KeyValue {
            key: "retention.ms".into(),
            value: retention_ms.to_string(),
            ..Default::default()
        },
    ]
}

/// Build the `KeyValue` config array from `(key, value)` pairs (already in
/// sorted order at the call site).
fn topic_configs<const N: usize>(pairs: [(&str, &str); N]) -> Vec<KeyValue> {
    pairs
        .into_iter()
        .map(|(key, value)| KeyValue {
            key: key.to_string(),
            value: value.to_string(),
            ..Default::default()
        })
        .collect()
}

/// Build the wire `Topology` (epoch 0, sorted subtopologies + topic arrays).
pub(crate) fn to_wire(groups: &[GroupTopics], application_id: &str) -> Topology {
    let mut subtopologies: Vec<Subtopology> = groups
        .iter()
        .map(|g| subtopology(g, application_id))
        .collect();
    subtopologies.sort_by(|a, b| a.subtopology_id.cmp(&b.subtopology_id));
    Topology {
        epoch: 0,
        subtopologies,
        ..Default::default()
    }
}

fn subtopology(g: &GroupTopics, app: &str) -> Subtopology {
    let mut source_topics = g.source_topics.clone();
    source_topics.sort();
    let mut repartition_sink_topics = g.repartition_sink_topics.clone();
    repartition_sink_topics.sort();

    let mut repartition_source_topics: Vec<TopicInfo> = g
        .repartition_source_topics
        .iter()
        .map(|name| TopicInfo {
            name: name.clone(),
            partitions: 0,
            replication_factor: INTERNAL_TOPIC_DEFAULT_RF,
            topic_configs: repartition_topic_configs(),
            ..Default::default()
        })
        .collect();
    repartition_source_topics.sort_by(|a, b| a.name.cmp(&b.name));

    // The sorted repartition-topic *names*, in the same order as the TopicInfo
    // array above — copartition indices must point into these sorted arrays.
    let repartition_names: Vec<String> = repartition_source_topics
        .iter()
        .map(|t| t.name.clone())
        .collect();
    let copartition_groups = g
        .copartition_groups
        .iter()
        .map(|members| copartition_group(&source_topics, &repartition_names, members))
        .collect();

    let mut state_changelog_topics: Vec<TopicInfo> = g
        .changelog_stores
        .iter()
        .map(|(store, changelog_override, changelog_kind)| TopicInfo {
            // `REUSE_KTABLE_SOURCE_TOPICS`: when the store reuses its source
            // topic as the changelog, the override carries that topic name;
            // otherwise the JVM-default `<app>-<store>-changelog`.
            name: changelog_override
                .clone()
                .unwrap_or_else(|| format!("{app}-{store}-changelog")),
            partitions: 0,
            replication_factor: INTERNAL_TOPIC_DEFAULT_RF,
            topic_configs: match changelog_kind {
                crate::topology::node::ChangelogKind::Kv => changelog_topic_configs(),
                crate::topology::node::ChangelogKind::AggWindow { retention_ms } => {
                    windowed_changelog_topic_configs(*retention_ms)
                }
                crate::topology::node::ChangelogKind::JoinWindow { retention_ms } => {
                    join_window_changelog_topic_configs(*retention_ms)
                }
            },
            ..Default::default()
        })
        .collect();
    state_changelog_topics.sort_by(|a, b| a.name.cmp(&b.name));

    Subtopology {
        subtopology_id: g.id.clone(),
        source_topics,
        source_topic_regex: Vec::new(),
        state_changelog_topics,
        repartition_sink_topics,
        repartition_source_topics,
        copartition_groups,
        ..Default::default()
    }
}

// ──────────────────────────────────────────────────────────────────────────────
// Serializable view of the wire `Topology`
// ──────────────────────────────────────────────────────────────────────────────

/// A serde-serializable view of the `StreamsGroupHeartbeat` wire `Topology`,
/// used to assert byte-exact interop against captured JVM fixtures.
///
/// The protocol `Topology` is auto-generated (and carries `unknown_tagged_fields`
/// that the JVM JSON fixtures omit), so we project it onto these flat structs
/// whose `serde(rename_all)`-free `snake_case` field names match the captured
/// fixture shape exactly. Field *order* is irrelevant — fixtures are compared as
/// `serde_json::Value` (a key-sorted map), and topic/subtopology array order is
/// already fixed by [`BuiltTopology::to_wire`](crate::topology::BuiltTopology::to_wire).
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct WireTopology {
    pub epoch: i32,
    pub subtopologies: Vec<WireSubtopology>,
}

/// One subtopology in a [`WireTopology`] (fixture-shaped).
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct WireSubtopology {
    pub subtopology_id: String,
    pub source_topics: Vec<String>,
    pub source_topic_regex: Vec<String>,
    pub repartition_sink_topics: Vec<String>,
    pub repartition_source_topics: Vec<WireTopicInfo>,
    pub state_changelog_topics: Vec<WireTopicInfo>,
    pub copartition_groups: Vec<WireCopartitionGroup>,
}

/// An internal-topic descriptor (repartition source / state changelog).
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct WireTopicInfo {
    pub name: String,
    pub partitions: i32,
    pub replication_factor: i16,
    pub topic_configs: Vec<WireKeyValue>,
}

/// A topic-config key/value pair.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct WireKeyValue {
    pub key: String,
    pub value: String,
}

/// A copartition group: `int16` indices into the sorted source / repartition
/// arrays.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct WireCopartitionGroup {
    pub source_topics: Vec<i16>,
    pub source_topic_regex: Vec<i16>,
    pub repartition_source_topics: Vec<i16>,
}

impl From<&Topology> for WireTopology {
    fn from(t: &Topology) -> Self {
        WireTopology {
            epoch: t.epoch,
            subtopologies: t.subtopologies.iter().map(WireSubtopology::from).collect(),
        }
    }
}

impl From<&Subtopology> for WireSubtopology {
    fn from(s: &Subtopology) -> Self {
        WireSubtopology {
            subtopology_id: s.subtopology_id.clone(),
            source_topics: s.source_topics.clone(),
            source_topic_regex: s.source_topic_regex.clone(),
            repartition_sink_topics: s.repartition_sink_topics.clone(),
            repartition_source_topics: s
                .repartition_source_topics
                .iter()
                .map(WireTopicInfo::from)
                .collect(),
            state_changelog_topics: s
                .state_changelog_topics
                .iter()
                .map(WireTopicInfo::from)
                .collect(),
            copartition_groups: s
                .copartition_groups
                .iter()
                .map(WireCopartitionGroup::from)
                .collect(),
        }
    }
}

impl From<&TopicInfo> for WireTopicInfo {
    fn from(t: &TopicInfo) -> Self {
        WireTopicInfo {
            name: t.name.clone(),
            partitions: t.partitions,
            replication_factor: t.replication_factor,
            topic_configs: t
                .topic_configs
                .iter()
                .map(|kv| WireKeyValue {
                    key: kv.key.clone(),
                    value: kv.value.clone(),
                })
                .collect(),
        }
    }
}

impl From<&CopartitionGroup> for WireCopartitionGroup {
    fn from(c: &CopartitionGroup) -> Self {
        WireCopartitionGroup {
            source_topics: c.source_topics.clone(),
            source_topic_regex: c.source_topic_regex.clone(),
            repartition_source_topics: c.repartition_source_topics.clone(),
        }
    }
}

/// Encode a copartition group as `int16` indices into the sorted `sources` /
/// `repartition` arrays. The `subtopology()` builder calls this once per declared
/// copartition group, passing the same sorted source/repartition arrays it emits
/// for the wire `source_topics` / `repartition_source_topics` fields.
pub(crate) fn copartition_group(
    sources: &[String],
    repartition: &[String],
    members: &[String],
) -> CopartitionGroup {
    let mut source_topics = Vec::new();
    let mut repartition_source_topics = Vec::new();
    for m in members {
        if let Some(i) = sources.iter().position(|s| s == m) {
            source_topics.push(i16::try_from(i).unwrap_or(i16::MAX));
        } else if let Some(i) = repartition.iter().position(|s| s == m) {
            repartition_source_topics.push(i16::try_from(i).unwrap_or(i16::MAX));
        }
    }
    source_topics.sort_unstable();
    repartition_source_topics.sort_unstable();
    CopartitionGroup {
        source_topics,
        source_topic_regex: Vec::new(),
        repartition_source_topics,
        ..Default::default()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::topology::grouping::GroupTopics;
    use crate::topology::node::ChangelogKind;
    use assert2::check;

    #[test]
    fn wire_topology_serializes_to_fixture_shape_with_topic_info() {
        use crabka_protocol::owned::common::streams_group_heartbeat_request::key_value::KeyValue;
        // A subtopology whose changelog topic carries a config: exercises the
        // TopicInfo + KeyValue serde projection the stateless fixture omits.
        let proto = Topology {
            epoch: 0,
            subtopologies: vec![Subtopology {
                subtopology_id: "0".into(),
                source_topics: vec!["in".into()],
                state_changelog_topics: vec![TopicInfo {
                    name: "app-store-changelog".into(),
                    partitions: 0,
                    replication_factor: -1,
                    topic_configs: vec![KeyValue {
                        key: "cleanup.policy".into(),
                        value: "compact".into(),
                        ..Default::default()
                    }],
                    ..Default::default()
                }],
                ..Default::default()
            }],
            ..Default::default()
        };
        let view = WireTopology::from(&proto);
        let json = serde_json::to_value(&view).unwrap();
        // No `unknown_tagged_fields` leaks into the JSON, and the nested config
        // maps to `{key, value}`.
        check!(
            json["subtopologies"][0]["state_changelog_topics"][0]["name"] == "app-store-changelog"
        );
        check!(json["subtopologies"][0]["state_changelog_topics"][0]["replication_factor"] == -1);
        check!(
            json["subtopologies"][0]["state_changelog_topics"][0]["topic_configs"][0]["key"]
                == "cleanup.policy"
        );
        check!(
            json["subtopologies"][0]
                .get("unknown_tagged_fields")
                .is_none()
        );
        check!(
            json["subtopologies"][0]["state_changelog_topics"][0]
                .get("unknown_tagged_fields")
                .is_none()
        );
    }

    #[test]
    fn wire_copartition_group_projects_indices() {
        let proto = CopartitionGroup {
            source_topics: vec![0, 2],
            source_topic_regex: Vec::new(),
            repartition_source_topics: vec![1],
            ..Default::default()
        };
        let view = WireCopartitionGroup::from(&proto);
        check!(view.source_topics == vec![0i16, 2i16]);
        check!(view.repartition_source_topics == vec![1i16]);
        let json = serde_json::to_value(&view).unwrap();
        check!(json.get("unknown_tagged_fields").is_none());
    }

    #[test]
    fn epoch_is_zero_and_source_topics_sorted() {
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["b".into(), "a".into()],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "app");
        check!(topo.epoch == 0);
        check!(topo.subtopologies[0].source_topics == vec!["a".to_string(), "b".to_string()]);
        check!(topo.subtopologies[0].source_topic_regex.is_empty());
    }

    #[test]
    fn subtopologies_sort_by_id_as_string_not_numeric() {
        let groups = vec![
            GroupTopics {
                id: "2".into(),
                source_topics: vec!["x".into()],
                ..Default::default()
            },
            GroupTopics {
                id: "10".into(),
                source_topics: vec!["x".into()],
                ..Default::default()
            },
            GroupTopics {
                id: "1".into(),
                source_topics: vec!["x".into()],
                ..Default::default()
            },
        ];
        let topo = to_wire(&groups, "app");
        let ids: Vec<&str> = topo
            .subtopologies
            .iter()
            .map(|s| s.subtopology_id.as_str())
            .collect();
        check!(ids == vec!["1", "10", "2"]);
    }

    #[test]
    fn changelog_topics_named_zero_partitions_default_rf_and_configs() {
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["in".into()],
            changelog_stores: vec![("store".into(), None, ChangelogKind::Kv)],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "my-app");
        let cl = &topo.subtopologies[0].state_changelog_topics;
        check!(cl.len() == 1);
        check!(cl[0].name == "my-app-store-changelog");
        check!(cl[0].partitions == 0);
        // JVM-faithful internal-topic encoding: RF = -1 (broker default) and the
        // sorted KV-store changelog configs.
        check!(cl[0].replication_factor == -1);
        let configs: Vec<(&str, &str)> = cl[0]
            .topic_configs
            .iter()
            .map(|kv| (kv.key.as_str(), kv.value.as_str()))
            .collect();
        check!(
            configs
                == vec![
                    ("cleanup.policy", "compact"),
                    ("message.timestamp.type", "CreateTime"),
                ]
        );
    }

    #[test]
    fn changelog_override_uses_source_topic_name_verbatim() {
        // REUSE_KTABLE_SOURCE_TOPICS: the override makes the changelog topic the
        // source topic ("in"), not "my-app-store-changelog". Configs/RF stay the
        // standard KV-store changelog configs.
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["in".into()],
            changelog_stores: vec![("store".into(), Some("in".into()), ChangelogKind::Kv)],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "my-app");
        let cl = &topo.subtopologies[0].state_changelog_topics;
        check!(cl.len() == 1);
        check!(cl[0].name == "in");
        check!(cl[0].replication_factor == -1);
        let configs: Vec<(&str, &str)> = cl[0]
            .topic_configs
            .iter()
            .map(|kv| (kv.key.as_str(), kv.value.as_str()))
            .collect();
        check!(
            configs
                == vec![
                    ("cleanup.policy", "compact"),
                    ("message.timestamp.type", "CreateTime"),
                ]
        );
    }

    #[test]
    fn repartition_source_topics_carry_default_rf_and_sorted_configs() {
        let groups = vec![GroupTopics {
            id: "1".into(),
            repartition_source_topics: vec!["my-app-store-repartition".into()],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "my-app");
        let rp = &topo.subtopologies[0].repartition_source_topics;
        check!(rp.len() == 1);
        check!(rp[0].name == "my-app-store-repartition");
        check!(rp[0].partitions == 0);
        check!(rp[0].replication_factor == -1);
        let configs: Vec<(&str, &str)> = rp[0]
            .topic_configs
            .iter()
            .map(|kv| (kv.key.as_str(), kv.value.as_str()))
            .collect();
        check!(
            configs
                == vec![
                    ("cleanup.policy", "delete"),
                    ("message.timestamp.type", "CreateTime"),
                    ("retention.ms", "-1"),
                    ("segment.bytes", "52428800"),
                ]
        );
    }

    #[test]
    fn copartition_indices_point_into_sorted_arrays() {
        let sources = vec!["a".to_string(), "b".to_string(), "c".to_string()];
        let repartition: Vec<String> = vec![];
        let cg = copartition_group(&sources, &repartition, &["c".into(), "a".into()]);
        check!(cg.source_topics == vec![0i16, 2i16]);
        check!(cg.repartition_source_topics.is_empty());
        check!(cg.source_topic_regex.is_empty());
    }

    #[test]
    fn copartition_indices_into_repartition_array() {
        let sources = vec!["a".to_string()];
        let repartition = vec!["rp0".to_string(), "rp1".to_string()];
        let cg = copartition_group(&sources, &repartition, &["rp1".into(), "a".into()]);
        check!(cg.source_topics == vec![0i16]);
        check!(cg.repartition_source_topics == vec![1i16]);
    }

    #[test]
    fn windowed_store_changelog_config_is_compact_delete_with_retention() {
        // size=60_000ms, grace=0ms → retention = 60_000 + 0 + 86_400_000 = 86_460_000
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["in".into()],
            changelog_stores: vec![(
                "w".into(),
                None,
                ChangelogKind::AggWindow {
                    retention_ms: 86_460_000,
                },
            )],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "app");
        let cl = &topo.subtopologies[0].state_changelog_topics;
        check!(cl.len() == 1);
        check!(cl[0].name == "app-w-changelog");
        check!(cl[0].partitions == 0);
        check!(cl[0].replication_factor == -1);
        let configs: Vec<(&str, &str)> = cl[0]
            .topic_configs
            .iter()
            .map(|kv| (kv.key.as_str(), kv.value.as_str()))
            .collect();
        check!(
            configs
                == vec![
                    ("cleanup.policy", "compact,delete"),
                    ("message.timestamp.type", "CreateTime"),
                    ("retention.ms", "86460000"),
                ]
        );
    }

    #[test]
    fn kv_store_changelog_config_unchanged_after_windowed_change() {
        // KV store must still use compact-only config (golden frames must stay byte-identical)
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["in".into()],
            changelog_stores: vec![("store".into(), None, ChangelogKind::Kv)],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "my-app");
        let cl = &topo.subtopologies[0].state_changelog_topics;
        check!(cl.len() == 1);
        let configs: Vec<(&str, &str)> = cl[0]
            .topic_configs
            .iter()
            .map(|kv| (kv.key.as_str(), kv.value.as_str()))
            .collect();
        check!(
            configs
                == vec![
                    ("cleanup.policy", "compact"),
                    ("message.timestamp.type", "CreateTime"),
                ]
        );
    }

    #[test]
    fn copartition_unknown_member_is_silently_skipped() {
        let sources = vec!["a".to_string()];
        let repartition: Vec<String> = vec![];
        let cg = copartition_group(&sources, &repartition, &["unknown".into()]);
        check!(cg.source_topics.is_empty());
        check!(cg.repartition_source_topics.is_empty());
    }

    #[test]
    fn join_window_changelog_is_delete_only_with_retention() {
        use crate::topology::node::ChangelogKind;
        // before=60_000ms, after=60_000ms, grace=0ms → retention = 60_000 + 60_000 + 0 + 86_400_000 = 86_520_000
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["in".into()],
            changelog_stores: vec![(
                "j".into(),
                None,
                ChangelogKind::JoinWindow {
                    retention_ms: 86_520_000,
                },
            )],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "app");
        let cl = &topo.subtopologies[0].state_changelog_topics[0];
        assert_eq!(cl.name, "app-j-changelog");
        assert_eq!(cl.topic_configs[0].key, "cleanup.policy");
        assert_eq!(cl.topic_configs[0].value, "delete"); // NOT compact,delete
        assert_eq!(cl.topic_configs[1].key, "message.timestamp.type");
        assert_eq!(cl.topic_configs[2].key, "retention.ms");
        assert_eq!(cl.topic_configs[2].value, "86520000");
    }

    #[test]
    fn repartition_sink_and_source_topics_included_in_wire() {
        let groups = vec![GroupTopics {
            id: "0".into(),
            source_topics: vec!["in".into()],
            repartition_sink_topics: vec!["rp".into()],
            repartition_source_topics: vec!["rp".into()],
            ..Default::default()
        }];
        let topo = to_wire(&groups, "app");
        let st = &topo.subtopologies[0];
        check!(st.repartition_sink_topics == vec!["rp".to_string()]);
        check!(st.repartition_source_topics.len() == 1);
        check!(st.repartition_source_topics[0].name == "rp");
    }
}