@Override protected PcpMetricInfo newInstance(String name, Set<Integer> usedIds) { return new PcpMetricInfoV2(name, identifierSource.calculateId(name, usedIds), stringStore.createPcpString(name)); } }
@Override public void writeToMmv(ByteBuffer byteBuffer) { byteBuffer.position(offset); byteBuffer.putLong(getStringOffset(nameAsPcpString)); byteBuffer.putInt(getId()); byteBuffer.putInt(typeHandler.getMetricType().getIdentifier()); byteBuffer.putInt(getSemantics().getPcpValue()); byteBuffer.putInt(UnitMapping.getDimensions(getUnit(), metricName)); if (domain != null) { byteBuffer.putInt(domain.getId()); } else { byteBuffer.putInt(DEFAULT_INSTANCE_DOMAIN_ID); } // Just padding byteBuffer.putInt(0); byteBuffer.putLong(getStringOffset(shortHelpText)); byteBuffer.putLong(getStringOffset(longHelpText)); }
@Test public void writeToMmvShouldSetThePositionOfTheBufferBeforeWriting() { ByteBuffer byteBuffer = mock(ByteBuffer.class); TypeHandler<Object> typeHandler = mock(TypeHandler.class); when(typeHandler.getMetricType()).thenReturn(mock(MmvMetricType.class)); pcpMetricInfoV2.setOffset(THIS_PCP_METRIC_INFO_OFFSET); pcpMetricInfoV2.setTypeHandler(typeHandler); pcpMetricInfoV2.writeToMmv(byteBuffer); InOrder inOrder = Mockito.inOrder(byteBuffer); inOrder.verify(byteBuffer).position(THIS_PCP_METRIC_INFO_OFFSET); inOrder.verify(byteBuffer).putLong(anyLong()); }
when(semantics.getPcpValue()).thenReturn(SEMANTICS_VALUE); pcpMetricInfoV2.setTypeHandler(typeHandler); pcpMetricInfoV2.setHelpText(shortHelpPcpString, longHelpPcpString); pcpMetricInfoV2.setSemantics(semantics); pcpMetricInfoV2.setUnit(HOUR); pcpMetricInfoV2.writeToMmv(byteBuffer);
@Test public void byteSizeShouldReturnTheByteSizeOfTheMmvFormat() { assertEquals(EXPECTED_PCP_METRIC_INFO_SIZE, pcpMetricInfoV2.byteSize()); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); pcpMetricInfoV2 = new PcpMetricInfoV2("name", 1, nameAsPcpString); }
@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); } }