diff --git a/server/src/main/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStub.java b/server/src/main/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStub.java index e7089e13..5f89438e 100644 --- a/server/src/main/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStub.java +++ b/server/src/main/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStub.java @@ -17,25 +17,18 @@ package org.apache.rocketmq.studio.instance.group; +import org.apache.rocketmq.studio.common.exception.BusinessException; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; -import java.util.List; - @Slf4j @Component public class ConsumerDiagnosticsProviderStub implements ConsumerDiagnosticsProvider { @Override public ConsumerStackTraceVO getConsumerStack(String groupName, String clientId) { - log.warn("ConsumerDiagnosticsProviderStub.getConsumerStack called - returning empty stack"); - return ConsumerStackTraceVO.builder() - .groupName(groupName) - .clientId(clientId) - .capturedAt(LocalDateTime.now()) - .threadCount(0) - .threads(List.of()) - .build(); + log.warn("ConsumerDiagnosticsProviderStub.getConsumerStack called without a real diagnostics provider. " + + "groupName={}, clientId={}", groupName, clientId); + throw new BusinessException(501, "Consumer diagnostics provider is not configured"); } } diff --git a/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStubTest.java b/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStubTest.java new file mode 100644 index 00000000..4f486440 --- /dev/null +++ b/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerDiagnosticsProviderStubTest.java @@ -0,0 +1,36 @@ +/* + * 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.rocketmq.studio.instance.group; + +import org.apache.rocketmq.studio.common.exception.BusinessException; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class ConsumerDiagnosticsProviderStubTest { + + private final ConsumerDiagnosticsProviderStub provider = new ConsumerDiagnosticsProviderStub(); + + @Test + void getConsumerStackShouldFailWhenRealProviderIsMissing() { + assertThatThrownBy(() -> provider.getConsumerStack("cg-orders", "client-1")) + .isInstanceOf(BusinessException.class) + .hasMessage("Consumer diagnostics provider is not configured") + .satisfies(ex -> assertThat(((BusinessException) ex).getCode()).isEqualTo(501)); + } +}