@Test(expected = IllegalStateException.class) public void ensureSetPerMetricLockIsNotAllowedWhenWriterIsStarted() throws IOException { pcpMmvWriter.start(); pcpMmvWriter.setPerMetricLock(true); }
@Test @SuppressWarnings("unchecked") public void shouldBuildAByteBufferOfTheCorrectLength() throws IOException { InstanceDomain instanceDomain = mock(InstanceDomain.class); Instance instance = mock(Instance.class); PcpMetricInfo pcpMetricInfo = mock(PcpMetricInfo.class); when(pcpMetricInfo.getTypeHandler()).thenReturn(mock(TypeHandler.class)); when(pcpMetricInfo.byteSize()).thenReturn(MOCK_PCP_METRIC_INFO_BYTE_SIZE); when(instanceDomain.getInstances()).thenReturn(singletonList(instance)); when(instanceDomain.byteSize()).thenReturn(MOCK_INSTANCE_DOMAIN_BYTE_SIZE); when(instance.byteSize()).thenReturn(MOCK_INSTANCE_BYTE_SIZE); when(metricInfoStore.byName(SOME_METRIC_NAME)).thenReturn(pcpMetricInfo); when(metricInfoStore.all()).thenReturn(singletonList(pcpMetricInfo)); when(instanceDomainStore.all()).thenReturn(singletonList(instanceDomain)); when(byteBuffer.slice()).thenReturn(mock(ByteBuffer.class)); pcpMmvWriter.addMetric(MetricName.parse(SOME_METRIC_NAME), Semantics.COUNTER, null, 1); pcpMmvWriter.setMetricHelpText(SOME_METRIC_NAME, "Short help", "Long help"); pcpMmvWriter.start(); verify(byteBufferFactory).build(EXPECTED_LENGTH); }
@Test @SuppressWarnings("unchecked") public void ensureUpdatesAreIgnoredAfterResetIsCalled() throws IOException { MetricName metricName = MetricName.parse(SOME_METRIC_NAME); TypeHandler<CustomType> customTypeTypeHandler = mock(TypeHandler.class); PcpMetricInfo pcpMetricInfo = mock(PcpMetricInfo.class); when(customTypeTypeHandler.getMetricType()).thenReturn(MmvMetricType.DOUBLE); when(metricInfoStore.byName(SOME_METRIC_NAME)).thenReturn(pcpMetricInfo); doReturn(customTypeTypeHandler).when(pcpMetricInfo).getTypeHandler(); when(byteBuffer.slice()).thenReturn(mock(ByteBuffer.class)); pcpMmvWriter.registerType(CustomType.class, customTypeTypeHandler); pcpMmvWriter.start(); pcpMmvWriter.reset(); Mockito.reset(customTypeTypeHandler); pcpMmvWriter.addMetric(metricName, Semantics.COUNTER, ONE, new CustomType()); pcpMmvWriter.updateMetric(metricName, new CustomType()); verify(customTypeTypeHandler, never()).putBytes(any(ByteBuffer.class), any(CustomType.class)); }
@Test public void ensureSetPerMetricLockIsAllowedAfterResetIsCalled() throws IOException { pcpMmvWriter.start(); pcpMmvWriter.reset(); pcpMmvWriter.setPerMetricLock(true); }
@Test public void bothMmvVersionsShouldSupportAddingAMetric() throws Exception { pcpMmvWriterV1.reset(); pcpMmvWriterV1.addMetric(MetricName.parse("v1.integer"), Semantics.COUNTER, ONE, 3); pcpMmvWriterV1.start(); pcpMmvWriterV2.reset(); pcpMmvWriterV2.addMetric(MetricName.parse("v2.integer"), Semantics.COUNTER, ONE, 3); pcpMmvWriterV2.start(); waitForReload(); assertMetric("mmv.v1.integer", is("3.000")); assertMetric("mmv.v2.integer", is("3.000")); }
@Test public void mmvVersion2ShouldSupportInstanceNamesOver63Characters() throws Exception { pcpMmvWriterV2.reset(); pcpMmvWriterV2.addMetric(MetricName.parse("v2.integer[instance_name_over_63_characters_instance_name_over_63_characters_instance]"), Semantics.COUNTER, ONE, 11); pcpMmvWriterV2.start(); waitForReload(); assertMetric("mmv.v2.integer[instance_name_over_63_characters_instance_name_over_63_characters_instance]", is("11.000")); }
@Test public void mmvVersion2ShouldSupportMetricNamesOver63Characters() throws Exception { pcpMmvWriterV2.reset(); pcpMmvWriterV2.addMetric(MetricName.parse("v2.metric.that.is.longer.than.63.characters.v2.metric.that.is.longer.than.63.characters"), Semantics.COUNTER, ONE, 10); pcpMmvWriterV2.start(); waitForReload(); assertMetric("mmv.v2.metric.that.is.longer.than.63.characters.v2.metric.that.is.longer.than.63.characters", is("10.000")); }
bridge.start();