This is an automated email from the ASF dual-hosted git repository.
guoyp pushed a commit to branch griffin-2.0.0-dev
in repository https://gitbox.apache.org/repos/asf/griffin.git
The following commit(s) were added to refs/heads/griffin-2.0.0-dev by this push:
new 4c07dc05 add metric test (#663)
4c07dc05 is described below
commit 4c07dc05c4514c5a5acee001836094f20a0015d9
Author: William Guo <[email protected]>
AuthorDate: Wed Sep 4 19:07:34 2024 +0800
add metric test (#663)
---
.../apache/griffin/metric/model/MetricTest.java | 95 ++++++++++++++++++++++
pom.xml | 48 ++++++++++-
2 files changed, 140 insertions(+), 3 deletions(-)
diff --git
a/griffin-metric/src/test/java/org/apache/griffin/metric/model/MetricTest.java
b/griffin-metric/src/test/java/org/apache/griffin/metric/model/MetricTest.java
new file mode 100644
index 00000000..8dfac23c
--- /dev/null
+++
b/griffin-metric/src/test/java/org/apache/griffin/metric/model/MetricTest.java
@@ -0,0 +1,95 @@
+package org.apache.griffin.metric.model;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class MetricTest {
+
+ private MetricD metricD;
+ private MetricV metricV1;
+ private MetricV metricV2;
+ private Tags tags;
+
+ @BeforeEach
+ public void setUp() {
+ // Initialize MetricD
+ metricD = MetricD.builder()
+ .metricId(1L)
+ .metricName("Metric A")
+ .owner("Owner A")
+ .description("Description A")
+ .build();
+
+ // Initialize MetricV
+ metricV1 = MetricV.builder()
+ .metricId(1L)
+ .value(100.5)
+ .tags(Tags.builder()
+ .metricId(1L)
+ .metricTags(createSampleTags())
+ .build())
+ .build();
+
+ metricV2 = MetricV.builder()
+ .metricId(1L)
+ .value(200.75)
+ .tags(Tags.builder()
+ .metricId(1L)
+ .metricTags(createSampleTags())
+ .build())
+ .build();
+
+ // Initialize Tags
+ tags = Tags.builder()
+ .metricId(1L)
+ .metricTags(createSampleTags())
+ .build();
+ }
+
+ @Test
+ public void testCreateMetricD() {
+ assertNotNull(metricD);
+ assertEquals(1L, metricD.getMetricId());
+ assertEquals("Metric A", metricD.getMetricName());
+ assertEquals("Owner A", metricD.getOwner());
+ assertEquals("Description A", metricD.getDescription());
+ }
+
+ @Test
+ public void testIngestMetricV() {
+ List<MetricV> metricVs = new ArrayList<>();
+ metricVs.add(metricV1);
+ metricVs.add(metricV2);
+
+ assertEquals(2, metricVs.size());
+ assertTrue(metricVs.contains(metricV1));
+ assertTrue(metricVs.contains(metricV2));
+ }
+
+ @Test
+ public void testFetchMetricDWithTags() {
+ // Mock fetch logic here. This would typically involve querying a
database or service.
+ MetricD fetchedMetricD = metricD; // Simulate fetching
+ Tags fetchedTags = tags; // Simulate fetching tags
+
+ assertNotNull(fetchedMetricD);
+ assertEquals(1L, fetchedMetricD.getMetricId());
+
+ assertNotNull(fetchedTags);
+ assertEquals(1L, fetchedTags.getMetricId());
+ assertEquals(2, fetchedTags.getMetricTags().size());
+ }
+
+ private List<MetricTag> createSampleTags() {
+ List<MetricTag> tags = new ArrayList<>();
+ tags.add(new MetricTag(1L, "key1", "value1"));
+ tags.add(new MetricTag(2L, "key2", "value2"));
+ return tags;
+ }
+}
+
diff --git a/pom.xml b/pom.xml
index 1e4b1ea1..97e5057c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -189,12 +189,54 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.11.0</version>
+ <version>${maven-compiler-plugin.version}</version>
<configuration>
- <source>${maven.compiler.source}</source>
- <target>${maven.compiler.target}</target>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ <testSource>${java.version}</testSource>
+ <testTarget>${java.version}</testTarget>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>${maven-release-plugin.version}</version>
+ <configuration>
+ <tagNameFormat>@{project.version}</tagNameFormat>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>${maven-assembly-plugin.version}</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${maven-javadoc-plugin.version}</version>
+ <configuration>
+ <quiet>true</quiet>
+ <source>8</source>
+ <failOnError>false</failOnError>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>${maven-dependency-plugin.version}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>${maven-shade-plugin.version}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>${maven-jar-plugin.version}</version>
+ </plugin>
<!-- Surefire runs all Java tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>