Search in sources :

Example 11 with TestStatArchiveWriter

use of org.apache.geode.internal.statistics.TestStatArchiveWriter in project geode by apache.

the class StatArchiveWithConsecutiveResourceInstGenerator method setUpGenerator.

@Before
public void setUpGenerator() throws Exception {
    this.statisticTypes = new HashMap<>();
    this.allStatistics = new HashMap<>();
    this.dir = this.temporaryFolder.getRoot();
    this.archiveFileName = new File(this.dir.getAbsolutePath(), ARCHIVE_FILE_NAME).getAbsolutePath();
    this.manager = new TestStatisticsManager(1, getUniqueName(), WRITER_INITIAL_DATE_MILLIS);
    StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS - 2000).setSystemDirectoryPath(TEST_NAME).setProductDescription(TEST_NAME).build();
    this.writer = new TestStatArchiveWriter(archiveDescriptor);
    this.sampler = new TestStatisticsSampler(manager);
    this.sampleCollector = new SampleCollector(sampler);
    this.sampleCollector.addSampleHandler(this.writer);
}
Also used : TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) File(java.io.File) Before(org.junit.Before)

Example 12 with TestStatArchiveWriter

use of org.apache.geode.internal.statistics.TestStatArchiveWriter in project geode by apache.

the class StatArchiveWriterReaderIntegrationTest method testDestroyUnallocatedStatistics.

/**
   * Control which helps verify fix for bug #45377.
   */
@Test
public void testDestroyUnallocatedStatistics() throws Exception {
    final StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS - 2000).setSystemDirectoryPath(this.testName.getMethodName()).setProductDescription(getClass().getSimpleName()).build();
    final StatArchiveWriter writer = new TestStatArchiveWriter(archiveDescriptor);
    final StatisticsType statsType = createDummyStatisticsType();
    final ResourceType rt = new ResourceType(0, statsType);
    final Statistics statistics = mock(Statistics.class);
    final ResourceInstance ri = new ResourceInstance(0, statistics, rt);
    writer.sampled(WRITER_INITIAL_DATE_MILLIS + 1000, Collections.singletonList(ri));
    writer.destroyedResourceInstance(ri);
    writer.close();
    // Verify StatArchiveReader.update returns cleanly, without throwing an exception
    final StatArchiveReader reader = new StatArchiveReader(new File[] { new File(this.archiveFileName) }, null, false);
    reader.update();
    reader.close();
}
Also used : TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) StatisticsType(org.apache.geode.StatisticsType) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) Statistics(org.apache.geode.Statistics) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with TestStatArchiveWriter

use of org.apache.geode.internal.statistics.TestStatArchiveWriter in project geode by apache.

the class StatArchiveWriterReaderIntegrationTest method testDoubleCounterOneSample.

@Test
public void testDoubleCounterOneSample() throws Exception {
    final TestStatisticsManager manager = new TestStatisticsManager(1, getUniqueName(), WRITER_INITIAL_DATE_MILLIS);
    final TestStatisticsSampler sampler = new TestStatisticsSampler(manager);
    final SampleCollector sampleCollector = new SampleCollector(sampler);
    final StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS).setSystemDirectoryPath(this.testName.getMethodName()).setProductDescription(getClass().getSimpleName()).build();
    final StatArchiveWriter writer = new TestStatArchiveWriter(archiveDescriptor);
    sampleCollector.addSampleHandler(writer);
    final StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { manager.createDoubleCounter("long_double_1", "d1", "u1") };
    final StatisticsType ST1 = manager.createType("ST1", "ST1", statsST1);
    final Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1", 1);
    final double value = 32317.716467;
    incDouble(st1_1, "long_double_1", value);
    final long sampleIncNanos = NANOS_PER_MILLI * 1000;
    final long sampleTimeNanos = WRITER_PREVIOUS_TIMESTAMP_NANOS + sampleIncNanos;
    sampleCollector.sample(sampleTimeNanos);
    writer.close();
    final StatisticDescriptor[] sds = ST1.getStatistics();
    for (int i = 0; i < sds.length; i++) {
        assertEquals(value, st1_1.get(sds[i].getName()));
    }
    final StatArchiveReader reader = new StatArchiveReader(new File[] { new File(this.archiveFileName) }, null, false);
    // compare all resourceInst values against what was printed above
    final List resources = reader.getResourceInstList();
    assertNotNull(resources);
    assertEquals(1, resources.size());
    final StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) resources.get(0);
    assertNotNull(ri);
    final String statsName = ri.getName();
    assertNotNull(statsName);
    assertEquals("st1_1", statsName);
    assertEquals("ST1", ri.getType().getName());
    final StatValue[] statValues = ri.getStatValues();
    assertNotNull(statValues);
    assertEquals(1, statValues.length);
    final String statName = ri.getType().getStats()[0].getName();
    assertNotNull(statName);
    assertEquals("long_double_1", statName);
    assertEquals(statName, statValues[0].getDescriptor().getName());
    assertEquals(1, statValues[0].getSnapshotsSize());
    assertEquals(value, statValues[0].getSnapshotsMostRecent(), 0.01);
    final long[] timeStampsMillis = statValues[0].getRawAbsoluteTimeStamps();
    assertNotNull(timeStampsMillis);
    assertEquals(1, timeStampsMillis.length);
    final long initPreviousTimeStampMillis = NanoTimer.nanosToMillis(WRITER_PREVIOUS_TIMESTAMP_NANOS);
    final long timeStampMillis = NanoTimer.nanosToMillis(sampleTimeNanos);
    final long deltaMillis = timeStampMillis - initPreviousTimeStampMillis;
    assertEquals(NanoTimer.nanosToMillis(sampleIncNanos), deltaMillis);
    final long expectedTimeStampMillis = deltaMillis + WRITER_INITIAL_DATE_MILLIS;
    assertEquals(expectedTimeStampMillis, timeStampsMillis[0]);
    final double[] snapshots = statValues[0].getRawSnapshots();
    assertNotNull(snapshots);
    assertEquals(1, snapshots.length);
    assertEquals(value, snapshots[0], 0.01);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) Statistics(org.apache.geode.Statistics) StatValue(org.apache.geode.internal.statistics.StatArchiveReader.StatValue) StatisticDescriptor(org.apache.geode.StatisticDescriptor) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) List(java.util.List) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)13 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)12 Test (org.junit.Test)12 File (java.io.File)10 Statistics (org.apache.geode.Statistics)10 StatisticsType (org.apache.geode.StatisticsType)10 List (java.util.List)8 StatisticDescriptor (org.apache.geode.StatisticDescriptor)8 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)8 Iterator (java.util.Iterator)2 Before (org.junit.Before)1