PcpValueInfo(MetricName metricName, PcpMetricInfo metricInfo, Instance instance, Object initialValue, PcpStringStore stringStore) { this.metricName = metricName; this.metricInfo = metricInfo; this.instance = instance; this.initialValue = initialValue; if (metricInfo.getTypeHandler().requiresLargeStorage()) { this.largeValue = stringStore.createPcpString(initialValue.toString()); } else { this.largeValue = null; } }
@Test public void instanceStoreShouldCreateANewInstance() { IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); IdentifierSource identifierSource = mock(IdentifierSource.class); InstanceDomain instanceDomain = mock(InstanceDomain.class); PcpStringStore stringStore = mock(PcpStringStore.class); PcpString pcpString = mock(PcpString.class); when(identifierSourceSet.instanceSource(INSTANCE_NAME)).thenReturn(identifierSource); when(identifierSource.calculateId(eq(INSTANCE_NAME), ArgumentMatchers.<Integer>anySet())).thenReturn(123); when(stringStore.createPcpString(INSTANCE_NAME)).thenReturn(pcpString); InstanceV2.InstanceStoreV2 instanceStore = new InstanceV2.InstanceStoreV2(identifierSourceSet, INSTANCE_NAME, instanceDomain, stringStore); Instance actual = instanceStore.byName(INSTANCE_NAME); InstanceV2 expected = new InstanceV2(instanceDomain, INSTANCE_NAME, 123, pcpString); assertReflectionEquals(expected, actual); }
@Test public void metricInfoStoreShouldCreateANewPcpMetricInfoV2() { IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); PcpStringStore stringStore = mock(PcpStringStore.class); PcpString pcpString = mock(PcpString.class); IdentifierSource identifierSource = mock(IdentifierSource.class); when(identifierSourceSet.metricSource()).thenReturn(identifierSource); when(identifierSource.calculateId(eq("my.metric"), ArgumentMatchers.<Integer>anySet())).thenReturn(123); when(stringStore.createPcpString("my.metric")).thenReturn(pcpString); MetricInfoStoreV2 metricInfoStoreV2 = new MetricInfoStoreV2(identifierSourceSet, stringStore); PcpMetricInfo actual = metricInfoStoreV2.byName("my.metric"); PcpMetricInfoV2 expected = new PcpMetricInfoV2("my.metric", 123, pcpString); assertReflectionEquals(expected, actual); } }
@Override public final void setInstanceDomainHelpText(String instanceDomain, String shortHelpText, String longHelpText) { InstanceDomain domain = getInstanceDomain(instanceDomain); domain.setHelpText(stringStore.createPcpString(shortHelpText), stringStore.createPcpString(longHelpText)); }
@Test public void pcpStringStore_createNewPcpString_doesNotCreateANewStringIfNullIsGiven() { PcpStringStore pcpStringStore = new PcpStringStore(); pcpStringStore.createPcpString(null); assertThat(pcpStringStore.getStrings(), emptyCollectionOf(PcpString.class)); }
@Override protected PcpMetricInfo newInstance(String name, Set<Integer> usedIds) { return new PcpMetricInfoV2(name, identifierSource.calculateId(name, usedIds), stringStore.createPcpString(name)); } }
@Override public final void setMetricHelpText(String metricName, String shortHelpText, String longHelpText) { PcpMetricInfo info = getMetricInfo(metricName); if (!info.hasHelpText()) { info.setHelpText(stringStore.createPcpString(shortHelpText), stringStore.createPcpString(longHelpText)); } }
@Override protected Instance newInstance(String name, Set<Integer> usedIds) { return new InstanceV2(instanceDomain, name, identifierSource.calculateId(name, usedIds), stringStore.createPcpString(name)); } }
@Test public void pcpStringStore_createNewPcpString_createsAndStoresAPcpString() { PcpStringStore pcpStringStore = new PcpStringStore(); pcpStringStore.createPcpString(MY_STRING); PcpString expected = new PcpString(MY_STRING); assertThat(pcpStringStore.getStrings(), CoreMatchers.<PcpString>hasItem(reflectivelyEqualing(expected))); }