Skip to content

Commit c47da03

Browse files
committed
Update ConsumerNameResolverTest for the sanitized name format
Yesterday's commit fdcb69b changed the default consumer-name format from "rqueue-<queue>-<bean>#<method>" to "rqueue-<queue>-<bean>_<method>" with non [A-Za-z0-9_-] characters collapsed to '_'. The existing tests still asserted the old '#' separator and broke unit_test on CI. Updates the two existing assertions and adds a new test that exercises the sanitization explicitly with a nested-class bean name (carries '$'). Assisted-By: Claude Code
1 parent 656e87e commit c47da03

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

rqueue-core/src/test/java/com/github/sonus21/rqueue/listener/ConsumerNameResolverTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void defaultsWhenAnnotationConsumerNameIsBlank() throws Exception {
3939
Method m = Sample.class.getMethod("defaultName");
4040
RqueueListener ann = m.getAnnotation(RqueueListener.class);
4141
assertEquals(
42-
"rqueue-q1-mybean#defaultName",
42+
"rqueue-q1-mybean_defaultName",
4343
ConsumerNameResolver.resolveConsumerName(ann, "mybean", "defaultName", "q1"));
4444
}
4545

@@ -55,6 +55,19 @@ void usesExplicitNameWhenSet() throws Exception {
5555
@Test
5656
void nullAnnotationFallsBackToDefault() {
5757
assertEquals(
58-
"rqueue-qX-bean#m", ConsumerNameResolver.resolveConsumerName(null, "bean", "m", "qX"));
58+
"rqueue-qX-bean_m", ConsumerNameResolver.resolveConsumerName(null, "bean", "m", "qX"));
59+
}
60+
61+
/**
62+
* NATS / JetStream durable consumer names are restricted to {@code [A-Za-z0-9_-]}. Nested-class
63+
* beans (which carry {@code $}) and the original {@code #} separator broke consumer creation,
64+
* so the resolver collapses any character outside that set to {@code _}.
65+
*/
66+
@Test
67+
void sanitizesIllegalCharactersInBeanAndMethodNames() {
68+
String resolved =
69+
ConsumerNameResolver.resolveConsumerName(
70+
null, "Outer$Inner.bean", "method.with$weird#chars", "q1");
71+
assertEquals("rqueue-q1-Outer_Inner_bean_method_with_weird_chars", resolved);
5972
}
6073
}

0 commit comments

Comments
 (0)