diff --git a/src/java/org/apache/cassandra/service/AsyncProfilerService.java b/src/java/org/apache/cassandra/service/AsyncProfilerService.java index f287857e1b8..86db64da0a3 100644 --- a/src/java/org/apache/cassandra/service/AsyncProfilerService.java +++ b/src/java/org/apache/cassandra/service/AsyncProfilerService.java @@ -368,6 +368,10 @@ public void purge() @Override public String status() { + if (!ASYNC_PROFILER_ENABLED.getBoolean()) + { + return "Async Profiler is not enabled. Enable it by setting " + ASYNC_PROFILER_ENABLED.getKey() + " property to true."; + } return run(new ThrowingFunction<>() { @Override diff --git a/test/unit/org/apache/cassandra/service/AsyncProfilerServiceTest.java b/test/unit/org/apache/cassandra/service/AsyncProfilerServiceTest.java index a05b3a6108c..25f7dbdced2 100644 --- a/test/unit/org/apache/cassandra/service/AsyncProfilerServiceTest.java +++ b/test/unit/org/apache/cassandra/service/AsyncProfilerServiceTest.java @@ -264,14 +264,13 @@ public void testSecondStartNotExecuted() } @Test - public void testProfilerDisabledThrowsException() + public void testProfilerDisabledReturnsMessage() { try (WithProperties properties = new WithProperties().set(ASYNC_PROFILER_UNSAFE_MODE, true).set(ASYNC_PROFILER_ENABLED, false)) { - assertThatThrownBy(() -> { - AsyncProfilerService profiler = getProfiler(true); - profiler.status(); - }).hasMessageContaining("Async Profiler is not enabled. Enable it by setting cassandra.async_profiler.enabled property to true."); + AsyncProfilerService profiler = getProfiler(true); + String status = profiler.status(); + assertTrue(status.contains("Async Profiler is not enabled. Enable it by setting cassandra.async_profiler.enabled property to true.")); } }