|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.microsoft.applicationinsights.smoketest; |
| 5 | + |
| 6 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11; |
| 7 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9; |
| 8 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17; |
| 9 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17_OPENJ9; |
| 10 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21; |
| 11 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21_OPENJ9; |
| 12 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_23; |
| 13 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_23_OPENJ9; |
| 14 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8; |
| 15 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9; |
| 16 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8; |
| 17 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; |
| 18 | +import static java.util.concurrent.TimeUnit.NANOSECONDS; |
| 19 | +import static java.util.concurrent.TimeUnit.SECONDS; |
| 20 | +import static org.assertj.core.api.Assertions.assertThat; |
| 21 | + |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 24 | + |
| 25 | +@UseAgent("applicationinsights4.json") |
| 26 | +abstract class SamplingOverrides4Test { |
| 27 | + |
| 28 | + @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); |
| 29 | + |
| 30 | + @Test |
| 31 | + @TargetUri(value = "/health-check", callCount = 100) |
| 32 | + void testSampling() throws Exception { |
| 33 | + // super super low chance that number of sampled requests is less than 25 |
| 34 | + long start = System.nanoTime(); |
| 35 | + while (testing.mockedIngestion.getCountForType("RequestData") < 25 |
| 36 | + && NANOSECONDS.toSeconds(System.nanoTime() - start) < 10) {} |
| 37 | + // wait ten more seconds to before checking that we didn't receive too many |
| 38 | + Thread.sleep(SECONDS.toMillis(10)); |
| 39 | + int requestCount = testing.mockedIngestion.getCountForType("RequestData"); |
| 40 | + int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData"); |
| 41 | + int logCount = testing.mockedIngestion.getCountForType("MessageData"); |
| 42 | + // super super low chance that number of sampled requests/dependencies/traces |
| 43 | + // is less than 25 or greater than 75 |
| 44 | + assertThat(requestCount).isGreaterThanOrEqualTo(25); |
| 45 | + assertThat(requestCount).isLessThanOrEqualTo(75); |
| 46 | + // super super low chance that number of sampled dependencies/traces |
| 47 | + // is less than 2 or greater than 20 |
| 48 | + assertThat(dependencyCount).isGreaterThanOrEqualTo(2); |
| 49 | + assertThat(dependencyCount).isLessThanOrEqualTo(20); |
| 50 | + assertThat(logCount).isGreaterThanOrEqualTo(2); |
| 51 | + assertThat(logCount).isLessThanOrEqualTo(20); |
| 52 | + |
| 53 | + testing |
| 54 | + .mockedIngestion |
| 55 | + .getItemsEnvelopeDataType("RequestData") |
| 56 | + .forEach( |
| 57 | + item -> { |
| 58 | + assertThat(item.getSampleRate()).isEqualTo(2); |
| 59 | + }); |
| 60 | + testing |
| 61 | + .mockedIngestion |
| 62 | + .getItemsEnvelopeDataType("RemoteDependencyData") |
| 63 | + .forEach( |
| 64 | + item -> { |
| 65 | + assertThat(item.getSampleRate()).isEqualTo(10); |
| 66 | + }); |
| 67 | + testing |
| 68 | + .mockedIngestion |
| 69 | + .getItemsEnvelopeDataType("MessageData") |
| 70 | + .forEach( |
| 71 | + item -> { |
| 72 | + assertThat(item.getSampleRate()).isEqualTo(10); |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + @Environment(TOMCAT_8_JAVA_8) |
| 77 | + static class Tomcat8Java8Test extends SamplingOverrides4Test {} |
| 78 | + |
| 79 | + @Environment(TOMCAT_8_JAVA_8_OPENJ9) |
| 80 | + static class Tomcat8Java8OpenJ9Test extends SamplingOverrides4Test {} |
| 81 | + |
| 82 | + @Environment(TOMCAT_8_JAVA_11) |
| 83 | + static class Tomcat8Java11Test extends SamplingOverrides4Test {} |
| 84 | + |
| 85 | + @Environment(TOMCAT_8_JAVA_11_OPENJ9) |
| 86 | + static class Tomcat8Java11OpenJ9Test extends SamplingOverrides4Test {} |
| 87 | + |
| 88 | + @Environment(TOMCAT_8_JAVA_17) |
| 89 | + static class Tomcat8Java17Test extends SamplingOverrides4Test {} |
| 90 | + |
| 91 | + @Environment(TOMCAT_8_JAVA_17_OPENJ9) |
| 92 | + static class Tomcat8Java17OpenJ9Test extends SamplingOverrides4Test {} |
| 93 | + |
| 94 | + @Environment(TOMCAT_8_JAVA_21) |
| 95 | + static class Tomcat8Java21Test extends SamplingOverrides4Test {} |
| 96 | + |
| 97 | + @Environment(TOMCAT_8_JAVA_21_OPENJ9) |
| 98 | + static class Tomcat8Java21OpenJ9Test extends SamplingOverrides4Test {} |
| 99 | + |
| 100 | + @Environment(TOMCAT_8_JAVA_23) |
| 101 | + static class Tomcat8Java23Test extends SamplingOverrides4Test {} |
| 102 | + |
| 103 | + @Environment(TOMCAT_8_JAVA_23_OPENJ9) |
| 104 | + static class Tomcat8Java23OpenJ9Test extends SamplingOverrides4Test {} |
| 105 | + |
| 106 | + @Environment(WILDFLY_13_JAVA_8) |
| 107 | + static class Wildfly13Java8Test extends SamplingOverrides4Test {} |
| 108 | + |
| 109 | + @Environment(WILDFLY_13_JAVA_8_OPENJ9) |
| 110 | + static class Wildfly13Java8OpenJ9Test extends SamplingOverrides4Test {} |
| 111 | +} |
0 commit comments