Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve] Imporve checkstyle of test code. #1864

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hertzbeat.alert;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -31,7 +30,7 @@
class AlerterWorkerPoolTest {

private static final int NUMBER_OF_THREADS = 10;
private AlerterWorkerPool pool ;
private AlerterWorkerPool pool;
private AtomicInteger counter;
private CountDownLatch latch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@

package org.apache.hertzbeat.alert.controller;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Collections;
import java.util.List;
import org.apache.hertzbeat.alert.service.impl.AlertDefineServiceImpl;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
import org.apache.hertzbeat.common.entity.alerter.AlertDefineMonitorBind;
import org.apache.hertzbeat.common.entity.manager.Monitor;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.util.JsonUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -35,12 +39,6 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import java.util.Collections;
import java.util.List;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
* Test case for {@link AlertDefineController}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@

package org.apache.hertzbeat.alert.controller;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.hertzbeat.alert.service.AlertDefineService;
import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
import org.apache.hertzbeat.common.util.JsonUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -36,12 +46,6 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
* Test case for {@link AlertDefinesController}
* Test whether the data mocked at the mock is correct, and test whether the format of the returned data is correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.hertzbeat.alert.controller;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.apache.hertzbeat.alert.dto.GeneralCloudAlertReport;
import org.apache.hertzbeat.alert.dto.TenCloudAlertReport;
import org.apache.hertzbeat.alert.service.AlertService;
Expand All @@ -33,10 +36,6 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
* unit test for {@link AlertReportController }
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@

package org.apache.hertzbeat.alert.controller;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import org.apache.hertzbeat.alert.dto.AlertSummary;
import org.apache.hertzbeat.alert.service.AlertService;
import org.apache.hertzbeat.common.entity.alerter.Alert;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.Alert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -37,13 +44,6 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
* Test case for {@link AlertsController}
*/
Expand All @@ -67,7 +67,6 @@ void setUp() {
ids = LongStream.rangeClosed(1, 10).boxed().collect(Collectors.toList());
}

// @Test
// todo: fix this test
void getAlerts() throws Exception {
String sortField = "id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@

package org.apache.hertzbeat.alert.service;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.anySet;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import org.apache.hertzbeat.alert.dao.AlertDefineBindDao;
import org.apache.hertzbeat.alert.dao.AlertDefineDao;
import org.apache.hertzbeat.alert.service.impl.AlertDefineServiceImpl;
Expand All @@ -26,18 +39,14 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.*;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
* Test case for {@link AlertDefineService}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

package org.apache.hertzbeat.alert.util;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link AlertTemplateUtil}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedConstruction;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

package org.apache.hertzbeat.collector.collect.http.promethus.exporter;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

/**
*
Expand All @@ -31,35 +29,35 @@ class ExporterParserTest {

@Test
void textToMetric() {
String resp = "# HELP disk_total_bytes Total space for path\n" +
"# TYPE disk_total_bytes gauge\n" +
"disk_total_bytes{path=\"C:\\\\hertzbeat\\\\repo\\\\testpath\",} 4.29496725504E11\n" +
"# HELP go_gc_cycles_automatic_gc_cycles_total Count of completed GC cycles generated by the Go runtime.\n" +
"# TYPE go_gc_cycles_automatic_gc_cycles_total counter\n" +
"go_gc_cycles_automatic_gc_cycles_total 0\n" +
"# HELP go_gc_cycles_forced_gc_cycles_total Count of completed GC cycles forced by the application.\n" +
"# TYPE go_gc_cycles_forced_gc_cycles_total counter\n" +
"go_gc_cycles_forced_gc_cycles_total 0\n" +
"# HELP go_gc_cycles_total_gc_cycles_total Count of all completed GC cycles.\n" +
"# TYPE go_gc_cycles_total_gc_cycles_total counter\n" +
"go_gc_cycles_total_gc_cycles_total 0\n" +
"# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.\n" +
"# TYPE go_gc_duration_seconds summary\n" +
"go_gc_duration_seconds{quantile=\"0\"} 0\n" +
"go_gc_duration_seconds{quantile=\"0.25\"} 0\n" +
"go_gc_duration_seconds{quantile=\"0.5\"} 0\n" +
"go_gc_duration_seconds{quantile=\"0.75\"} 0\n" +
"go_gc_duration_seconds{quantile=\"1\"} 0\n" +
"# TYPE jvm info\n" +
"# HELP jvm VM version info\n" +
"jvm_info{runtime=\"OpenJDK Runtime Environment\",vendor=\"Azul Systems, Inc.\",version=\"11.0.13+8-LTS\"} 1.0\n" +
"# TYPE jvm_gc_collection_seconds summary\n" +
"# HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds.\n" +
"jvm_gc_collection_seconds_count{gc=\"G1 Young Generation\"} 10.0\n" +
"jvm_gc_collection_seconds_sum{gc=\"G1 Young Generation\"} 0.051\n" +
"jvm_gc_collection_seconds_count{gc=\"G1 Old Generation\"} 0.0\n" +
"jvm_gc_collection_seconds_sum{gc=\"G1 Old Generation\"} 0.0\n" +
"# EOF";
String resp = "# HELP disk_total_bytes Total space for path\n"
+ "# TYPE disk_total_bytes gauge\n"
+ "disk_total_bytes{path=\"C:\\\\hertzbeat\\\\repo\\\\testpath\",} 4.29496725504E11\n"
+ "# HELP go_gc_cycles_automatic_gc_cycles_total Count of completed GC cycles generated by the Go runtime.\n"
+ "# TYPE go_gc_cycles_automatic_gc_cycles_total counter\n"
+ "go_gc_cycles_automatic_gc_cycles_total 0\n"
+ "# HELP go_gc_cycles_forced_gc_cycles_total Count of completed GC cycles forced by the application.\n"
+ "# TYPE go_gc_cycles_forced_gc_cycles_total counter\n"
+ "go_gc_cycles_forced_gc_cycles_total 0\n"
+ "# HELP go_gc_cycles_total_gc_cycles_total Count of all completed GC cycles.\n"
+ "# TYPE go_gc_cycles_total_gc_cycles_total counter\n"
+ "go_gc_cycles_total_gc_cycles_total 0\n"
+ "# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.\n"
+ "# TYPE go_gc_duration_seconds summary\n"
+ "go_gc_duration_seconds{quantile=\"0\"} 0\n"
+ "go_gc_duration_seconds{quantile=\"0.25\"} 0\n"
+ "go_gc_duration_seconds{quantile=\"0.5\"} 0\n"
+ "go_gc_duration_seconds{quantile=\"0.75\"} 0\n"
+ "go_gc_duration_seconds{quantile=\"1\"} 0\n"
+ "# TYPE jvm info\n"
+ "# HELP jvm VM version info\n"
+ "jvm_info{runtime=\"OpenJDK Runtime Environment\",vendor=\"Azul Systems, Inc.\",version=\"11.0.13+8-LTS\"} 1.0\n"
+ "# TYPE jvm_gc_collection_seconds summary\n"
+ "# HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds.\n"
+ "jvm_gc_collection_seconds_count{gc=\"G1 Young Generation\"} 10.0\n"
+ "jvm_gc_collection_seconds_sum{gc=\"G1 Young Generation\"} 0.051\n"
+ "jvm_gc_collection_seconds_count{gc=\"G1 Old Generation\"} 0.0\n"
+ "jvm_gc_collection_seconds_sum{gc=\"G1 Old Generation\"} 0.0\n"
+ "# EOF";
ExporterParser parser = new ExporterParser();
Map<String, MetricFamily> metricFamilyMap = parser.textToMetric(resp);
assertEquals(7, metricFamilyMap.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

package org.apache.hertzbeat.collector.dispatch.unit;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.hertzbeat.collector.dispatch.unit.impl.TimeLengthConvert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test case for {@link TimeLengthConvert}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@

package org.apache.hertzbeat.collector.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hertzbeat.common.entity.job.Configmap;
import org.apache.hertzbeat.common.entity.job.Metrics;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.*;

/**
* Test case for {@link CollectUtil}
*/
Expand Down
Loading
Loading