Update metrics singularly
This work is preparatory to avoid loading all the metrics at startup.
Updating a metric at a time will allow later on to inizialize
metrics only when collected and avoid defaulting them to 0.
Bug: Issue 16236
Change-Id: I0f58cac3604c0011938f25d712f03ab274048bff
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCache.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCache.java
index a08f845..b3a0fc8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCache.java
@@ -83,9 +83,15 @@
return metrics;
}
- public void setMetrics(Map<String, Long> metrics, String projectName) {
- this.collectedAt.put(projectName, clock.millis());
- this.metrics = metrics;
+ public void setMetrics(Map<GitRepoMetric, Long> newMetrics, String projectName) {
+ newMetrics.forEach(
+ (repoMetric, value) -> {
+ logger.atFine().log(
+ String.format(
+ "Collected %s for project %s: %d", repoMetric.getName(), projectName, value));
+ metrics.put(getMetricName(repoMetric.getName(), projectName), value);
+ });
+ collectedAt.put(projectName, clock.millis());
}
public List<GitRepoMetric> getMetricsNames() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/UpdateGitMetricsTask.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/UpdateGitMetricsTask.java
index a1acb24..7bdfb95 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/UpdateGitMetricsTask.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/UpdateGitMetricsTask.java
@@ -20,12 +20,11 @@
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
-import com.googlesource.gerrit.plugins.gitrepometrics.collectors.MetricsCollector;
+import com.googlesource.gerrit.plugins.gitrepometrics.collectors.GitRepoMetric;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Repository;
@@ -64,24 +63,13 @@
? ((DelegateRepository) repository).delegate()
: repository;
- Iterable<MetricsCollector> iterable = () -> gitRepoMetricsCache.getCollectors().iterator();
- HashMap<String, Long> newMetrics =
- StreamSupport.stream(iterable.spliterator(), false)
- .map(
- metricsCollector ->
- metricsCollector.collect((FileRepository) unwrappedRepo, projectName))
- .reduce(
- new HashMap<>(),
- (accumulator, latestMetrics) -> {
- HashMap<String, Long> newVal = new HashMap<>();
- newVal.putAll(accumulator);
- newVal.putAll(latestMetrics);
- return newVal;
- });
-
- logger.atInfo().log(
- "Here all the metrics for %s - %s", projectNameKey.get(), getStringFromMap(newMetrics));
- gitRepoMetricsCache.setMetrics(newMetrics, projectName);
+ gitRepoMetricsCache.getCollectors().stream()
+ .forEach(
+ metricsCollector -> {
+ HashMap<GitRepoMetric, Long> metrics =
+ metricsCollector.collect((FileRepository) unwrappedRepo, projectName);
+ gitRepoMetricsCache.setMetrics(metrics, projectName);
+ });
} catch (RepositoryNotFoundException e) {
logger.atSevere().withCause(e).log("Cannot find repository for %s", projectName);
} catch (IOException e) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollector.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollector.java
index 87e2b0e..2142830 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollector.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollector.java
@@ -26,30 +26,32 @@
public class FSMetricsCollector implements MetricsCollector {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- public static String numberOfKeepFiles = "numberOfKeepFiles";
- public static String numberOfEmptyDirectories = "numberOfEmptyDirectories";
- public static String numberOfDirectories = "numberOfDirectories";
- public static String numberOfFiles = "numberOfFiles";
+ protected static final GitRepoMetric numberOfKeepFiles =
+ new GitRepoMetric("numberOfKeepFiles", "Number of keep files on filesystem", "Count");
+ protected static final GitRepoMetric numberOfEmptyDirectories =
+ new GitRepoMetric(
+ "numberOfEmptyDirectories", "Number of empty directories on filesystem", "Count");
+ protected static final GitRepoMetric numberOfDirectories =
+ new GitRepoMetric("numberOfDirectories", "Number of directories on filesystem", "Count");
+ protected static final GitRepoMetric numberOfFiles =
+ new GitRepoMetric("numberOfFiles", "Number of directories on filesystem", "Count");
+
+ private static final ImmutableList<GitRepoMetric> availableMetrics =
+ ImmutableList.of(
+ numberOfKeepFiles, numberOfEmptyDirectories, numberOfFiles, numberOfDirectories);
@Override
- public HashMap<String, Long> collect(FileRepository repository, String projectName) {
- HashMap<String, Long> metrics = new HashMap<>();
-
+ public HashMap<GitRepoMetric, Long> collect(FileRepository repository, String projectName) {
+ HashMap<GitRepoMetric, Long> metrics = new HashMap<>();
HashMap<String, AtomicInteger> partialMetrics =
filesAndDirectoriesCount(repository, projectName);
- putMetric(
- projectName,
- metrics,
+
+ metrics.put(
numberOfEmptyDirectories,
- partialMetrics.get(numberOfEmptyDirectories).longValue());
- putMetric(
- projectName,
- metrics,
- numberOfDirectories,
- partialMetrics.get(numberOfDirectories).longValue());
- putMetric(projectName, metrics, numberOfFiles, partialMetrics.get(numberOfFiles).longValue());
- putMetric(
- projectName, metrics, numberOfKeepFiles, partialMetrics.get(numberOfKeepFiles).longValue());
+ partialMetrics.get(numberOfEmptyDirectories.getName()).longValue());
+ metrics.put(numberOfDirectories, partialMetrics.get(numberOfDirectories.getName()).longValue());
+ metrics.put(numberOfFiles, partialMetrics.get(numberOfFiles.getName()).longValue());
+ metrics.put(numberOfKeepFiles, partialMetrics.get(numberOfKeepFiles.getName()).longValue());
return metrics;
}
@@ -59,10 +61,10 @@
HashMap<String, AtomicInteger> counter =
new HashMap<String, AtomicInteger>() {
{
- put(numberOfFiles, new AtomicInteger(0));
- put(numberOfDirectories, new AtomicInteger(0));
- put(numberOfEmptyDirectories, new AtomicInteger(0));
- put(numberOfKeepFiles, new AtomicInteger(0));
+ put(numberOfFiles.getName(), new AtomicInteger(0));
+ put(numberOfDirectories.getName(), new AtomicInteger(0));
+ put(numberOfEmptyDirectories.getName(), new AtomicInteger(0));
+ put(numberOfKeepFiles.getName(), new AtomicInteger(0));
}
};
try {
@@ -71,16 +73,22 @@
.forEach(
path -> {
if (path.toFile().isFile()) {
- counter.get(numberOfFiles).updateAndGet(metricCounter -> metricCounter + 1);
+ counter
+ .get(numberOfFiles.getName())
+ .updateAndGet(metricCounter -> metricCounter + 1);
if (path.toFile().getName().endsWith(".keep")) {
- counter.get(numberOfKeepFiles).updateAndGet(metricCounter -> metricCounter + 1);
+ counter
+ .get(numberOfKeepFiles.getName())
+ .updateAndGet(metricCounter -> metricCounter + 1);
}
}
if (path.toFile().isDirectory()) {
- counter.get(numberOfDirectories).updateAndGet(metricCounter -> metricCounter + 1);
+ counter
+ .get(numberOfDirectories.getName())
+ .updateAndGet(metricCounter -> metricCounter + 1);
if (Objects.requireNonNull(path.toFile().listFiles()).length == 0) {
counter
- .get(numberOfEmptyDirectories)
+ .get(numberOfEmptyDirectories.getName())
.updateAndGet(metricCounter -> metricCounter + 1);
}
}
@@ -99,11 +107,6 @@
@Override
public ImmutableList<GitRepoMetric> availableMetrics() {
- return ImmutableList.of(
- new GitRepoMetric(numberOfKeepFiles, "Number of keep files on filesystem", "Count"),
- new GitRepoMetric(
- numberOfEmptyDirectories, "Number of empty directories on filesystem", "Count"),
- new GitRepoMetric(numberOfDirectories, "Number of directories on filesystem", "Count"),
- new GitRepoMetric(numberOfFiles, "Number of directories on filesystem", "Count"));
+ return availableMetrics;
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitRepoMetric.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitRepoMetric.java
index b016fbc..af75c9d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitRepoMetric.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitRepoMetric.java
@@ -14,6 +14,8 @@
package com.googlesource.gerrit.plugins.gitrepometrics.collectors;
+import java.util.Objects;
+
public class GitRepoMetric {
private final String name;
private final String description;
@@ -36,4 +38,19 @@
public String getDescription() {
return description;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ GitRepoMetric that = (GitRepoMetric) o;
+ return Objects.equals(name, that.name)
+ && Objects.equals(unit, that.unit)
+ && Objects.equals(description, that.description);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, description, unit);
+ }
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitStatsMetricsCollector.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitStatsMetricsCollector.java
index bb9d9cd..6e65fb5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitStatsMetricsCollector.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/GitStatsMetricsCollector.java
@@ -24,28 +24,47 @@
public class GitStatsMetricsCollector implements MetricsCollector {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- public static String numberOfPackedObjects = "numberOfPackedObjects";
- public static String numberOfPackFiles = "numberOfPackFiles";
- public static String numberOfLooseObjects = "numberOfLooseObjects";
- public static String numberOfLooseRefs = "numberOfLooseRefs";
- public static String numberOfPackedRefs = "numberOfPackedRefs";
- public static String sizeOfLooseObjects = "sizeOfLooseObjects";
- public static String sizeOfPackedObjects = "sizeOfPackedObjects";
- public static String numberOfBitmaps = "numberOfBitmaps";
+ public static final GitRepoMetric numberOfPackedObjects =
+ new GitRepoMetric("numberOfPackedObjects", "Number of packed objects", "Count");
+ public static final GitRepoMetric numberOfPackFiles =
+ new GitRepoMetric("numberOfPackFiles", "Number of pack files", "Count");
+ public static final GitRepoMetric numberOfLooseObjects =
+ new GitRepoMetric("numberOfLooseObjects", "Number of loose objects", "Count");
+ public static final GitRepoMetric numberOfLooseRefs =
+ new GitRepoMetric("numberOfLooseRefs", "Number of loose refs", "Count");
+ public static final GitRepoMetric numberOfPackedRefs =
+ new GitRepoMetric("numberOfPackedRefs", "Number of packed refs", "Count");
+ public static final GitRepoMetric sizeOfLooseObjects =
+ new GitRepoMetric("sizeOfLooseObjects", "Size of loose objects", "Count");
+ public static final GitRepoMetric sizeOfPackedObjects =
+ new GitRepoMetric("sizeOfPackedObjects", "Size of packed objects", "Count");
+ public static final GitRepoMetric numberOfBitmaps =
+ new GitRepoMetric("numberOfBitmaps", "Number of bitmaps", "Count");
+
+ private static final ImmutableList<GitRepoMetric> availableMetrics =
+ ImmutableList.of(
+ numberOfPackedObjects,
+ numberOfPackFiles,
+ numberOfLooseObjects,
+ numberOfLooseRefs,
+ numberOfPackedRefs,
+ sizeOfLooseObjects,
+ sizeOfPackedObjects,
+ numberOfBitmaps);
@Override
- public HashMap<String, Long> collect(FileRepository repository, String projectName) {
- HashMap<String, Long> metrics = new HashMap<>(availableMetrics().size());
+ public HashMap<GitRepoMetric, Long> collect(FileRepository repository, String projectName) {
+ HashMap<GitRepoMetric, Long> metrics = new HashMap<>(availableMetrics().size());
try {
GC.RepoStatistics statistics = new GC(repository).getStatistics();
- putMetric(projectName, metrics, numberOfPackedObjects, statistics.numberOfPackedObjects);
- putMetric(projectName, metrics, numberOfPackFiles, statistics.numberOfPackFiles);
- putMetric(projectName, metrics, numberOfLooseObjects, statistics.numberOfLooseObjects);
- putMetric(projectName, metrics, numberOfLooseRefs, statistics.numberOfLooseRefs);
- putMetric(projectName, metrics, numberOfPackedRefs, statistics.numberOfPackedRefs);
- putMetric(projectName, metrics, sizeOfLooseObjects, statistics.sizeOfLooseObjects);
- putMetric(projectName, metrics, sizeOfPackedObjects, statistics.sizeOfPackedObjects);
- putMetric(projectName, metrics, numberOfBitmaps, statistics.numberOfBitmaps);
+ metrics.put(numberOfPackedObjects, statistics.numberOfPackedObjects);
+ metrics.put(numberOfPackFiles, statistics.numberOfPackFiles);
+ metrics.put(numberOfLooseObjects, statistics.numberOfLooseObjects);
+ metrics.put(numberOfLooseRefs, statistics.numberOfLooseRefs);
+ metrics.put(numberOfPackedRefs, statistics.numberOfPackedRefs);
+ metrics.put(sizeOfLooseObjects, statistics.sizeOfLooseObjects);
+ metrics.put(sizeOfPackedObjects, statistics.sizeOfPackedObjects);
+ metrics.put(numberOfBitmaps, statistics.numberOfBitmaps);
logger.atInfo().log("New Git Statistics metrics collected: %s", statistics.toString());
} catch (IOException e) {
logger.atSevere().log("Something went wrong: %s", e.getMessage());
@@ -55,15 +74,7 @@
@Override
public ImmutableList<GitRepoMetric> availableMetrics() {
- return ImmutableList.of(
- new GitRepoMetric(numberOfPackedObjects, "Number of packed objects", "Count"),
- new GitRepoMetric(numberOfPackFiles, "Number of pack files", "Count"),
- new GitRepoMetric(numberOfLooseObjects, "Number of loose objects", "Count"),
- new GitRepoMetric(numberOfLooseRefs, "Number of loose refs", "Count"),
- new GitRepoMetric(numberOfPackedRefs, "Number of packed refs", "Count"),
- new GitRepoMetric(sizeOfLooseObjects, "Size of loose objects", "Count"),
- new GitRepoMetric(sizeOfPackedObjects, "Size of packed objects", "Count"),
- new GitRepoMetric(numberOfBitmaps, "Number of bitmaps", "Count"));
+ return availableMetrics;
}
@Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/MetricsCollector.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/MetricsCollector.java
index bfe06f4..b4114f5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/MetricsCollector.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/MetricsCollector.java
@@ -14,8 +14,6 @@
package com.googlesource.gerrit.plugins.gitrepometrics.collectors;
-import static com.googlesource.gerrit.plugins.gitrepometrics.GitRepoMetricsCache.getMetricName;
-
import com.google.common.collect.ImmutableList;
import java.util.HashMap;
import org.eclipse.jgit.internal.storage.file.FileRepository;
@@ -28,10 +26,10 @@
*
* @param projectName to collect metrics for
* @param repository {@link FileRepository} to collect metrics from
- * @return {@code HashMap<String, Long>} where the key is the metric name and the value is the
- * corresponding metric value collected.
+ * @return {@code HashMap<GitRepoMetric, Long>} where the key is the {@link GitRepoMetric} and the
+ * value is the corresponding metric value collected.
*/
- HashMap<String, Long> collect(FileRepository repository, String projectName);
+ HashMap<GitRepoMetric, Long> collect(FileRepository repository, String projectName);
/**
* Returns the name of the metric collector.
@@ -47,9 +45,4 @@
* metric collector implementation.
*/
ImmutableList<GitRepoMetric> availableMetrics();
-
- default void putMetric(
- String projectName, HashMap<String, Long> metrics, String metricName, long value) {
- metrics.put(getMetricName(metricName, projectName), value);
- }
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricsCollector.java b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricsCollector.java
index c0148c6..eee6274 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricsCollector.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricsCollector.java
@@ -23,9 +23,14 @@
import org.eclipse.jgit.internal.storage.file.FileRepository;
class FakeMetricsCollector implements MetricsCollector {
+ public static final GitRepoMetric fakeMetric1 =
+ new GitRepoMetric("fake-metric-1", "Fake metric 1", "Count");
+ public static final GitRepoMetric fakeMetric2 =
+ new GitRepoMetric("fake-metric-2", "Fake metric 2", "Count");
+
@Override
- public HashMap<String, Long> collect(FileRepository repository, String projectName) {
- return Maps.newHashMap(ImmutableMap.of("fake-metrics-1", 1L, "fake-metrics-2", 2L));
+ public HashMap<GitRepoMetric, Long> collect(FileRepository repository, String projectName) {
+ return Maps.newHashMap(ImmutableMap.of(fakeMetric1, 1L, fakeMetric2, 2L));
}
@Override
@@ -35,8 +40,6 @@
@Override
public ImmutableList<GitRepoMetric> availableMetrics() {
- return ImmutableList.of(
- new GitRepoMetric("fake-metric-1", "Fake metric 1", "Count"),
- new GitRepoMetric("fake-metric-2", "Fake metric 2", "Count"));
+ return ImmutableList.of(fakeMetric1, fakeMetric2);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheTest.java b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheTest.java
index e379813..e7fd9eb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheTest.java
@@ -18,17 +18,18 @@
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
-import com.google.common.collect.ImmutableMap;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.metrics.CallbackMetric0;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.DisabledMetricMaker;
+import com.googlesource.gerrit.plugins.gitrepometrics.collectors.GitRepoMetric;
import com.googlesource.gerrit.plugins.gitrepometrics.collectors.MetricsCollector;
import java.io.IOException;
import java.time.Clock;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
+import java.util.HashMap;
import org.junit.Before;
import org.junit.Test;
@@ -47,7 +48,7 @@
configSetupUtils = new ConfigSetupUtils(Collections.singletonList(enabledRepo));
fakeStatsCollector = new FakeMetricsCollector();
- ds = new DynamicSet<>();
+ ds = new DynamicSet<MetricsCollector>();
ds.add("git-repo-metrics", fakeStatsCollector);
}
@@ -118,7 +119,13 @@
new GitRepoMetricsCache(
ds, new FakeMetricMaker(), new MetricRegistry(), gitRepoMetricsConfig);
- gitRepoMetricsCache.setMetrics(ImmutableMap.of("anyMetric", 0L), enabledRepo);
+ gitRepoMetricsCache.setMetrics(
+ new HashMap<GitRepoMetric, Long>() {
+ {
+ put(new GitRepoMetric("anyMetric", "anyMetricDescription", "Count"), 0L);
+ }
+ },
+ enabledRepo);
assertThat(gitRepoMetricsCache.shouldCollectStats(enabledRepo)).isTrue();
}
@@ -132,7 +139,13 @@
new GitRepoMetricsCache(
ds, new FakeMetricMaker(), new MetricRegistry(), gitRepoMetricsConfig);
- gitRepoMetricsCache.setMetrics(ImmutableMap.of("anyMetric", 0L), enabledRepo);
+ gitRepoMetricsCache.setMetrics(
+ new HashMap<GitRepoMetric, Long>() {
+ {
+ put(new GitRepoMetric("anyMetric", "anyMetricDescription", "Count"), 0L);
+ }
+ },
+ enabledRepo);
assertThat(gitRepoMetricsCache.shouldCollectStats(enabledRepo)).isFalse();
}
@@ -151,7 +164,13 @@
Clock.fixed(
Instant.now().minus(2, ChronoUnit.SECONDS), Clock.systemDefaultZone().getZone()));
- gitRepoMetricsCache.setMetrics(ImmutableMap.of("anyMetric", 0L), enabledRepo);
+ gitRepoMetricsCache.setMetrics(
+ new HashMap<GitRepoMetric, Long>() {
+ {
+ put(new GitRepoMetric("anyMetric", "anyMetricDescription", "Count"), 0L);
+ }
+ },
+ enabledRepo);
assertThat(gitRepoMetricsCache.shouldCollectStats(enabledRepo)).isTrue();
}
@@ -167,7 +186,13 @@
long currentTimeStamp = System.currentTimeMillis();
- gitRepoMetricsCache.setMetrics(ImmutableMap.of("anyMetric", 0L), enabledRepo);
+ gitRepoMetricsCache.setMetrics(
+ new HashMap<GitRepoMetric, Long>() {
+ {
+ put(new GitRepoMetric("anyMetric", "anyMetricDescription", "Count"), 0L);
+ }
+ },
+ enabledRepo);
assertThat(gitRepoMetricsCache.getCollectedAt().get(enabledRepo)).isAtLeast(currentTimeStamp);
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollectorTest.java b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollectorTest.java
index f330af3..92fc552 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollectorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/FSMetricsCollectorTest.java
@@ -43,17 +43,17 @@
File objectDirectory = repository.getObjectsDirectory();
Files.createFile(new File(objectDirectory, "pack/keep1.keep").toPath());
- HashMap<String, Long> metrics = new FSMetricsCollector().collect(repository, "testRepo");
-
+ HashMap<GitRepoMetric, Long> metrics = new FSMetricsCollector().collect(repository, "testRepo");
// This is the FS structure, from the "objects" directory, metrics are collected from:
// .
// ├── info
// └── pack
// └── keep1.keep
- assertThat(metrics.get("numberofkeepfiles_testrepo")).isEqualTo(1); // keep1.keep
- assertThat(metrics.get("numberoffiles_testrepo")).isEqualTo(1); // keep1.keep
- assertThat(metrics.get("numberofdirectories_testrepo")).isEqualTo(3); // info, pack and .
- assertThat(metrics.get("numberofemptydirectories_testrepo")).isEqualTo(1); // info
+ assertThat(metrics.get(FSMetricsCollector.numberOfKeepFiles)).isEqualTo(1); // keep1.keep
+ assertThat(metrics.get(FSMetricsCollector.numberOfFiles)).isEqualTo(1); // keep1.keep
+ assertThat(metrics.get(FSMetricsCollector.numberOfDirectories))
+ .isEqualTo(3); // info, pack and .
+ assertThat(metrics.get(FSMetricsCollector.numberOfEmptyDirectories)).isEqualTo(1); // info
}
private FileRepository createRepository(String repoName) throws Exception {