55import com .newrelic .agent .RPMServiceManager ;
66import com .newrelic .agent .ThreadService ;
77import com .newrelic .agent .config .AgentConfig ;
8- import com .newrelic .agent .config .ConfigService ;
98import com .newrelic .agent .config .JfrConfig ;
9+ import com .newrelic .agent .config .ServerlessConfig ;
1010import com .newrelic .agent .service .ServiceFactory ;
11- import com .newrelic .agent .service .ServiceManager ;
12- import com .newrelic .agent .service .ServiceManagerImpl ;
1311import com .newrelic .jfr .ThreadNameNormalizer ;
1412import com .newrelic .jfr .daemon .DaemonConfig ;
1513import com .newrelic .jfr .daemon .JfrRecorderException ;
1816import org .junit .Test ;
1917import org .junit .experimental .categories .Category ;
2018import org .mockito .Mock ;
21- import org .mockito .MockedStatic ;
2219import org .mockito .MockitoAnnotations ;
2320
2421import static com .newrelic .agent .config .AgentConfigImpl .DEFAULT_EVENT_INGEST_URI ;
3027import static org .mockito .Mockito .any ;
3128import static org .mockito .Mockito .eq ;
3229import static org .mockito .Mockito .mock ;
33- import static org .mockito .Mockito .mockStatic ;
3430import static org .mockito .Mockito .spy ;
3531import static org .mockito .Mockito .timeout ;
3632import static org .mockito .Mockito .times ;
@@ -45,6 +41,9 @@ public class JfrServiceTest {
4541 @ Mock
4642 AgentConfig agentConfig ;
4743
44+ @ Mock
45+ ServerlessConfig serverlessConfig ;
46+
4847 @ Before
4948 public void before () {
5049 MockitoAnnotations .openMocks (this );
@@ -62,6 +61,8 @@ public void before() {
6261 when (agentConfig .getProxyScheme ()).thenReturn ("http" );
6362 when (agentConfig .getValue (eq (ThreadService .NAME_PATTERN_CFG_KEY ), any (String .class )))
6463 .thenReturn (ThreadNameNormalizer .DEFAULT_PATTERN );
64+ when (agentConfig .getServerlessConfig ()).thenReturn (serverlessConfig );
65+ when (serverlessConfig .isEnabled ()).thenReturn (false );
6566 }
6667
6768 @ Test
@@ -126,6 +127,20 @@ public void jfrLoopDoesNotStartWhenIsEnabledIsTrueAndHighSecurityIsTrue() throws
126127 verify (spyJfr , times (0 )).startJfrLoop ();
127128 }
128129
130+ @ Test
131+ public void jfrLoopDoesNotStartWhenIsEnabledIsTrueAndServerlessModeIsTrue () throws JfrRecorderException {
132+ JfrService jfrService = new JfrService (jfrConfig , agentConfig );
133+ JfrService spyJfr = spy (jfrService );
134+ when (serverlessConfig .isEnabled ()).thenReturn (true );
135+ when (jfrConfig .isEnabled ()).thenReturn (true );
136+ when (spyJfr .coreApisExist ()).thenReturn (true );
137+
138+ spyJfr .doStart ();
139+
140+ assertFalse (spyJfr .isEnabled ());
141+ verify (spyJfr , times (0 )).startJfrLoop ();
142+ }
143+
129144 @ Category ( IBMJ9IncompatibleTest .class )
130145 @ Test
131146 public void jfrLoopDoesStart () {
0 commit comments