1 package com.atlassian.plugin.instrumentation;
2
3 import com.atlassian.instrumentation.InstrumentRegistry;
4 import com.atlassian.instrumentation.RegistryConfiguration;
5 import org.junit.AfterClass;
6 import org.junit.BeforeClass;
7 import org.junit.Test;
8
9 import java.util.Optional;
10
11 import static com.atlassian.plugin.test.Matchers.isPresent;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.hamcrest.Matchers.notNullValue;
14 import static org.hamcrest.Matchers.startsWith;
15 import static org.hamcrest.core.Is.is;
16
17 public class TestPluginSystemInstrumentationEnabled {
18
19 private final PluginSystemInstrumentation pluginSystemInstrumentation = new PluginSystemInstrumentation();
20
21 @BeforeClass
22 public static void beforeClass() throws Exception {
23
24 System.setProperty(PluginSystemInstrumentation.getEnabledProperty(), "true");
25 }
26
27 @AfterClass
28 public static void afterClass() throws Exception {
29
30 System.setProperty(PluginSystemInstrumentation.getEnabledProperty(), "false");
31 }
32
33 @Test
34 public void instrumentationCreated() {
35 final Optional<InstrumentRegistry> instrumentRegistry = pluginSystemInstrumentation.getInstrumentRegistry();
36 assertThat(instrumentRegistry, isPresent());
37
38 final RegistryConfiguration registryConfiguration = instrumentRegistry.get().getRegistryConfiguration();
39 assertThat(registryConfiguration, notNullValue());
40 assertThat(registryConfiguration.getRegistryName(), is(PluginSystemInstrumentation.REGISTRY_NAME));
41 assertThat(registryConfiguration.isCPUCostCollected(), is(true));
42 assertThat(registryConfiguration.getRegistryHomeDirectory(), is(PluginSystemInstrumentation.REGISTRY_HOME_DIRECTORY));
43 }
44
45 @Test
46 public void pullTimerWithName() {
47 final Timer timer = pluginSystemInstrumentation.pullTimer("sometimer");
48 assertThat(timer, notNullValue());
49 assertThat(timer.getOpTimer(), isPresent());
50 assertThat(timer.getOpTimer().get().getName(), is("sometimer"));
51 }
52
53 @Test
54 public void pullSingleTimerWithName() {
55 final Timer timer = pluginSystemInstrumentation.pullSingleTimer("somesingletimer");
56 assertThat(timer, notNullValue());
57 assertThat(timer.getOpTimer(), isPresent());
58 assertThat(timer.getOpTimer().get().getName(), startsWith("somesingletimer"));
59 }
60 }