-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from zalintyre/feature/flag-disable-agent
Feature/flag disable agent
- Loading branch information
Showing
3 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
agent/src/test/java/io/pyroscope/javaagent/PyroscopeAgentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.pyroscope.javaagent; | ||
|
||
import io.pyroscope.javaagent.api.Logger; | ||
import io.pyroscope.javaagent.api.ProfilingScheduler; | ||
import io.pyroscope.javaagent.config.Config; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class PyroscopeAgentTest { | ||
|
||
private Config configAgentEnabled; | ||
private Config configAgentDisabled; | ||
private PyroscopeAgent.Options optionsAgentEnabled; | ||
private PyroscopeAgent.Options optionsAgentDisabled; | ||
|
||
@Mock | ||
private Logger logger; | ||
|
||
@Mock | ||
private ProfilingScheduler profilingScheduler; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
configAgentEnabled = new Config.Builder() | ||
.setAgentEnabled(true) | ||
.build(); | ||
optionsAgentEnabled = new PyroscopeAgent.Options.Builder(configAgentEnabled) | ||
.setScheduler(profilingScheduler) | ||
.setLogger(logger) | ||
.build(); | ||
|
||
configAgentDisabled = new Config.Builder() | ||
.setAgentEnabled(false) | ||
.build(); | ||
optionsAgentDisabled = new PyroscopeAgent.Options.Builder(configAgentDisabled) | ||
.setScheduler(profilingScheduler) | ||
.setLogger(logger) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void startupTestWithEnabledAgent() { | ||
PyroscopeAgent.start(optionsAgentEnabled); | ||
|
||
verify(profilingScheduler, times(1)).start(any()); | ||
} | ||
|
||
@Test | ||
void startupTestWithDisabledAgent() { | ||
PyroscopeAgent.start(optionsAgentDisabled); | ||
|
||
verify(profilingScheduler, never()).start(any()); | ||
} | ||
} |