public final void start() throws IOException { initialiseOffsets(); dataFileBuffer = byteBufferFactory.build(getBufferLength()); synchronized (globalLock) { populateDataBuffer(dataFileBuffer, metricData.values()); preparePerMetricBufferSlices(); } started = true; }
@Before public void setUp() throws IOException { MockitoAnnotations.initMocks(this); when(mmvVersion.createMetricNameValidator()).thenReturn(metricNameValidator); when(mmvVersion.createInstanceDomainStore(eq(identifierSourceSet), any(PcpStringStore.class))).thenReturn(instanceDomainStore); when(mmvVersion.createMetricInfoStore(eq(identifierSourceSet), any(PcpStringStore.class))).thenReturn(metricInfoStore); when(byteBufferFactory.build(anyInt())).thenReturn(byteBuffer); pcpMmvWriter = new PcpMmvWriter(byteBufferFactory, identifierSourceSet, mmvVersion); }
@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); }