-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8469: New VirtualMap metric: virtual node cache size, in Mb (#8755)
Fixes: #8469 Reviewed-by: Joseph Sinclair <[email protected]> Signed-off-by: Artem Ananev <[email protected]>
- Loading branch information
1 parent
ab80cb2
commit 108dd18
Showing
5 changed files
with
294 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
210 changes: 210 additions & 0 deletions
210
...sdk/swirlds-virtualmap/src/test/java/com/swirlds/virtualmap/VirtualMapStatisticsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
/* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.swirlds.virtualmap; | ||
|
||
import static com.swirlds.common.metrics.Metric.ValueType.VALUE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.swirlds.common.metrics.Metric; | ||
import com.swirlds.common.metrics.Metrics; | ||
import com.swirlds.common.metrics.config.MetricsConfig; | ||
import com.swirlds.common.metrics.platform.DefaultMetrics; | ||
import com.swirlds.common.metrics.platform.DefaultMetricsFactory; | ||
import com.swirlds.common.metrics.platform.MetricKeyRegistry; | ||
import com.swirlds.config.api.Configuration; | ||
import com.swirlds.test.framework.config.TestConfigBuilder; | ||
import com.swirlds.virtualmap.internal.merkle.VirtualMapStatistics; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class VirtualMapStatisticsTest { | ||
|
||
private static final String LABEL = "VMST"; | ||
|
||
private VirtualMapStatistics statistics; | ||
private Metrics metrics; | ||
|
||
private Metric getMetric(final String section, final String suffix) { | ||
return getMetric(metrics, "vmap_" + section + suffix); | ||
} | ||
|
||
private Metric getMetric(final Metrics metrics, final String name) { | ||
return metrics.getMetric(VirtualMapStatistics.STAT_CATEGORY, name); | ||
} | ||
|
||
private static void assertValueSet(final Metric metric) { | ||
assertNotEquals(0.0, metric.get(VALUE)); | ||
} | ||
|
||
private static <T> void assertValueEquals(final Metric metric, final T value) { | ||
assertEquals(value, metric.get(VALUE)); | ||
} | ||
|
||
@BeforeEach | ||
void setupTest() { | ||
final Configuration configuration = new TestConfigBuilder().getOrCreateConfig(); | ||
final MetricsConfig metricsConfig = configuration.getConfigData(MetricsConfig.class); | ||
|
||
final MetricKeyRegistry registry = mock(MetricKeyRegistry.class); | ||
when(registry.register(any(), any(), any())).thenReturn(true); | ||
metrics = new DefaultMetrics( | ||
null, | ||
registry, | ||
mock(ScheduledExecutorService.class), | ||
new DefaultMetricsFactory(metricsConfig), | ||
metricsConfig); | ||
statistics = new VirtualMapStatistics(LABEL); | ||
statistics.registerMetrics(metrics); | ||
} | ||
|
||
@Test | ||
void testSetSize() { | ||
// given | ||
final Metric metric = getMetric(metrics, "vmap_size_" + LABEL); | ||
// when | ||
statistics.setSize(12345678L); | ||
// then | ||
assertValueEquals(metric, 12345678L); | ||
} | ||
|
||
@Test | ||
void testCountAddedEntities() { | ||
// given | ||
final Metric metric = getMetric("queries_", "addedEntities_" + LABEL); | ||
// when | ||
statistics.countAddedEntities(); | ||
// then | ||
assertValueSet(metric); | ||
} | ||
|
||
@Test | ||
void testCountUpdatedEntities() { | ||
// given | ||
final Metric metric = getMetric("queries_", "updatedEntities_" + LABEL); | ||
// when | ||
statistics.countUpdatedEntities(); | ||
// then | ||
assertValueSet(metric); | ||
} | ||
|
||
@Test | ||
void testCountRemovedEntities() { | ||
// given | ||
final Metric metric = getMetric("queries_", "removedEntities_" + LABEL); | ||
// when | ||
statistics.countRemovedEntities(); | ||
// then | ||
assertValueSet(metric); | ||
} | ||
|
||
@Test | ||
void testCountReadEntities() { | ||
// given | ||
final Metric metric = getMetric("queries_", "readEntities_" + LABEL); | ||
// when | ||
statistics.countReadEntities(); | ||
// then | ||
assertValueSet(metric); | ||
} | ||
|
||
@Test | ||
void testNodeCacheSize() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "nodeCacheSizeMb_" + LABEL); | ||
// when | ||
statistics.setNodeCacheSize(2345L); | ||
// then | ||
assertValueEquals(metric, 2345L); | ||
} | ||
|
||
@Test | ||
void testPipelineSize() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "pipelineSize_" + LABEL); | ||
// when | ||
statistics.setPipelineSize(23456); | ||
// then | ||
assertValueEquals(metric, 23456); | ||
} | ||
|
||
@Test | ||
void testFlushBacklogSize() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "flushBacklogSize_" + LABEL); | ||
// when | ||
statistics.recordFlushBacklogSize(3456); | ||
// then | ||
assertValueEquals(metric, 3456); | ||
} | ||
|
||
@Test | ||
void testFlushBackpressureMs() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "flushBackpressureMs_" + LABEL); | ||
// when | ||
statistics.recordFlushBackpressureMs(34567); | ||
// then | ||
assertValueSet(metric); | ||
} | ||
|
||
@Test | ||
void testFamilySizeBackpressureMs() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "familySizeBackpressureMs_" + LABEL); | ||
// when | ||
statistics.recordFamilySizeBackpressureMs(4567); | ||
// then | ||
assertValueSet(metric); | ||
} | ||
|
||
@Test | ||
void testMergeDurationMs() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "mergeDurationMs_" + LABEL); | ||
// when | ||
statistics.recordMerge(45678L); | ||
// then | ||
assertValueEquals(metric, 45678L); | ||
} | ||
|
||
@Test | ||
void testFlushCountAndDurationMs() { | ||
// given | ||
final Metric metricDurationMs = getMetric("lifecycle_", "flushDurationMs_" + LABEL); | ||
final Metric metricCount = getMetric("lifecycle_", "flushCount_" + LABEL); | ||
// when | ||
statistics.recordFlush(5678L); | ||
// then | ||
assertValueEquals(metricDurationMs, 5678L); | ||
assertValueEquals(metricCount, 1L); | ||
} | ||
|
||
@Test | ||
void testHashDurationMs() { | ||
// given | ||
final Metric metric = getMetric("lifecycle_", "hashDurationMs_" + LABEL); | ||
// when | ||
statistics.recordHash(56789L); | ||
// then | ||
assertValueEquals(metric, 56789L); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters