|
21 | 21 | import org.junit.BeforeClass;
|
22 | 22 | import org.junit.Test;
|
23 | 23 |
|
| 24 | +import java.lang.reflect.Field; |
| 25 | + |
24 | 26 | import static io.pcp.parfait.dxm.IdentifierSourceSet.DEFAULT_SET;
|
25 | 27 | import static io.pcp.parfait.dxm.MmvVersion.MMV_VERSION1;
|
26 | 28 | import static io.pcp.parfait.dxm.MmvVersion.MMV_VERSION2;
|
27 | 29 | import static org.hamcrest.MatcherAssert.assertThat;
|
28 | 30 | import static org.hamcrest.core.Is.is;
|
| 31 | +import static org.junit.Assert.assertEquals; |
29 | 32 | import static tech.units.indriya.AbstractUnit.ONE;
|
30 | 33 |
|
31 | 34 | public class PcpMmvWriterIntegrationTest {
|
@@ -79,11 +82,45 @@ public void mmvVersion2ShouldSupportInstanceNamesOver63Characters() throws Excep
|
79 | 82 | assertMetric("mmv.v2.integer[instance_name_over_63_characters_instance_name_over_63_characters_instance]", is("11.000"));
|
80 | 83 | }
|
81 | 84 |
|
| 85 | + @Test |
| 86 | + public void resetShouldClearStrings() throws Exception { |
| 87 | + pcpMmvWriterV1.reset(); |
| 88 | + assertStringsCount(pcpMmvWriterV1, 0); |
| 89 | + pcpMmvWriterV1.addMetric(MetricName.parse("v1.string"), Semantics.DISCRETE, null, "test1"); |
| 90 | + pcpMmvWriterV1.start(); |
| 91 | + |
| 92 | + pcpMmvWriterV2.reset(); |
| 93 | + assertStringsCount(pcpMmvWriterV2, 0); |
| 94 | + pcpMmvWriterV2.addMetric(MetricName.parse("v2.string"), Semantics.DISCRETE, null, "test2"); |
| 95 | + pcpMmvWriterV2.start(); |
| 96 | + |
| 97 | + waitForReload(); |
| 98 | + |
| 99 | + assertMetric("mmv.v1.string", is("\"test1\"")); |
| 100 | + assertMetric("mmv.v2.string", is("\"test2\"")); |
| 101 | + |
| 102 | + assertStringsCount(pcpMmvWriterV1, 1); |
| 103 | + assertStringsCount(pcpMmvWriterV2, 2); |
| 104 | + |
| 105 | + pcpMmvWriterV1.reset(); |
| 106 | + assertStringsCount(pcpMmvWriterV1, 0); |
| 107 | + |
| 108 | + pcpMmvWriterV2.reset(); |
| 109 | + assertStringsCount(pcpMmvWriterV2, 0); |
| 110 | + } |
| 111 | + |
82 | 112 | private void assertMetric(String metricName, Matcher<String> expectedValue) throws Exception {
|
83 | 113 | String actual = pcpClient.getMetric(metricName);
|
84 | 114 | assertThat(actual, expectedValue);
|
85 | 115 | }
|
86 | 116 |
|
| 117 | + private void assertStringsCount(PcpMmvWriter writer, int expectedCount) throws NoSuchFieldException, IllegalAccessException { |
| 118 | + Field field = PcpMmvWriter.class.getDeclaredField("stringStore"); |
| 119 | + field.setAccessible(true); |
| 120 | + PcpString.PcpStringStore stringStore = (PcpString.PcpStringStore) field.get(writer); |
| 121 | + assertEquals(expectedCount, stringStore.getStrings().size()); |
| 122 | + } |
| 123 | + |
87 | 124 | private void waitForReload() throws InterruptedException {
|
88 | 125 | Thread.sleep(1000);
|
89 | 126 | }
|
|
0 commit comments