use of com.microsoft.applicationinsights.profiler.ProfilerConfiguration in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerConfigMonitorServiceTest method pullsConfig.
@Test
void pullsConfig() throws IOException, URISyntaxException {
AtomicReference<Runnable> job = new AtomicReference<>();
ScheduledExecutorService executorService = mockScheduledExecutorService(job::set);
ServiceProfilerClientV2 serviceProfilerClient = mockServiceProfilerClient();
ServiceProfilerConfigMonitorService serviceMonitor = new ServiceProfilerConfigMonitorService(executorService, 100, serviceProfilerClient);
AtomicReference<ProfilerConfiguration> config = new AtomicReference<>();
serviceMonitor.initialize(Collections.singletonList(config::set));
assertThat(job.get()).isNotNull();
job.get().run();
Mockito.verify(serviceProfilerClient, times(1)).getSettings(any(Date.class));
assertThat(config.get()).isNotNull();
assertThat(config.get().getCollectionPlan()).isEqualTo("--single --mode immediate --immediate-profiling-duration 120 --expiration 5249157885138288517 --settings-moniker a-settings-moniker");
assertThat(config.get().getCpuTriggerConfiguration()).isEqualTo("--cpu-trigger-enabled true --cpu-threshold 80 --cpu-trigger-profilingDuration 30 --cpu-trigger-cooldown 14400");
assertThat(config.get().getDefaultConfiguration()).isEqualTo("--sampling-enabled true --sampling-rate 5 --sampling-profiling-duration 120");
assertThat(config.get().getMemoryTriggerConfiguration()).isEqualTo("--memory-trigger-enabled true --memory-threshold 20 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400");
}
use of com.microsoft.applicationinsights.profiler.ProfilerConfiguration in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerSettingsClientTest method badServiceResponseDoesNotProvideReturn.
@Test
void badServiceResponseDoesNotProvideReturn() throws IOException, URISyntaxException {
ServiceProfilerClientV2 serviceProfilerClient = Mockito.mock(ServiceProfilerClientV2.class);
Mockito.when(serviceProfilerClient.getSettings(Mockito.any())).thenReturn(Mono.just(""));
ServiceProfilerSettingsClient settingsClient = new ServiceProfilerSettingsClient(serviceProfilerClient);
Mono<ProfilerConfiguration> result = settingsClient.pullSettings();
assertThatThrownBy(result::block).isInstanceOf(Exception.class);
}
use of com.microsoft.applicationinsights.profiler.ProfilerConfiguration in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerSettingsClient method toServiceProfilerConfiguration.
private static ProfilerConfiguration toServiceProfilerConfiguration(String config) throws IOException {
Moshi moshi = new Moshi.Builder().add(Date.class, new Rfc3339DateJsonAdapter()).build();
JsonAdapter<ProfilerConfiguration> jsonAdapter = moshi.adapter(ProfilerConfiguration.class);
return jsonAdapter.fromJson(config);
}
Aggregations