Skip to content

Commit 7dc7fc1

Browse files
authored
Merge pull request #197 from ChannelFinder/remove-ignorable-error-logs
Remove ignorable error logs
2 parents 211929f + bb0a15f commit 7dc7fc1

24 files changed

+83
-37
lines changed

src/main/java/org/phoebus/channelfinder/service/MetricsService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212
import java.util.Map.Entry;
1313
import java.util.concurrent.TimeUnit;
1414
import java.util.concurrent.atomic.AtomicLong;
15+
import java.util.logging.Logger;
1516
import java.util.stream.Collectors;
1617
import org.phoebus.channelfinder.repository.ChannelRepository;
1718
import org.phoebus.channelfinder.repository.PropertyRepository;
1819
import org.phoebus.channelfinder.repository.TagRepository;
1920
import org.springframework.beans.factory.annotation.Autowired;
2021
import org.springframework.beans.factory.annotation.Value;
21-
import org.springframework.context.annotation.PropertySource;
2222
import org.springframework.scheduling.annotation.Scheduled;
2323
import org.springframework.stereotype.Service;
2424
import org.springframework.util.LinkedMultiValueMap;
2525
import org.springframework.util.MultiValueMap;
2626

2727
@Service
28-
@PropertySource(value = "classpath:application.properties")
2928
public class MetricsService {
30-
3129
public static final String CF_TOTAL_CHANNEL_COUNT = "cf.total.channel.count";
3230
public static final String CF_PROPERTY_COUNT = "cf.property.count";
3331
public static final String CF_TAG_COUNT = "cf.tag.count";
@@ -60,7 +58,7 @@ public class MetricsService {
6058

6159
Map<String, List<String>> parseProperties() {
6260
if (metricProperties == null || metricProperties.isEmpty()) {
63-
return new LinkedMultiValueMap<>();
61+
return Map.of();
6462
}
6563
return Arrays.stream(metricProperties.split(";"))
6664
.map(
@@ -121,9 +119,7 @@ public static List<MultiValueMap<String, String>> generateAllMultiValueMaps(
121119
List<MultiValueMap<String, String>> allMultiValueMaps = new ArrayList<>();
122120

123121
if (properties.isEmpty()) {
124-
allMultiValueMaps.add(
125-
new LinkedMultiValueMap<>()); // Add an empty map for the case where all are null
126-
return allMultiValueMaps;
122+
return List.of();
127123
}
128124

129125
List<Entry<String, List<String>>> entries = new ArrayList<>(properties.entrySet());
@@ -211,7 +207,11 @@ private void updatePropertyMetrics() {
211207

212208
@Scheduled(fixedRateString = "${metrics.updateInterval}", timeUnit = TimeUnit.SECONDS)
213209
public void updateMetrics() {
214-
updateTagMetrics();
215-
updatePropertyMetrics();
210+
if (tagMetrics != null && !tagMetrics.isEmpty()) {
211+
updateTagMetrics();
212+
}
213+
if (propertyMetrics != null && !propertyMetrics.isEmpty()) {
214+
updatePropertyMetrics();
215+
}
216216
}
217217
}

src/test/java/org/phoebus/channelfinder/AuthorizationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
1212
import org.springframework.security.core.context.SecurityContextHolder;
1313
import org.springframework.security.test.context.support.WithMockUser;
14+
import org.springframework.test.context.ContextConfiguration;
1415
import org.springframework.test.context.TestPropertySource;
1516

1617
@WebMvcTest(AuthorizationService.class)
1718
@TestPropertySource(value = "classpath:application_test.properties")
19+
@ContextConfiguration(classes = {AuthorizationService.class})
1820
class AuthorizationIT {
1921
@Autowired AuthorizationService authorizationService;
2022

src/test/java/org/phoebus/channelfinder/ChannelControllerIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
import org.springframework.beans.factory.annotation.Autowired;
2626
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
2727
import org.springframework.security.test.context.support.WithMockUser;
28+
import org.springframework.test.context.ContextConfiguration;
2829
import org.springframework.test.context.TestPropertySource;
2930
import org.springframework.web.server.ResponseStatusException;
3031

3132
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3233
@WebMvcTest(ChannelController.class)
3334
@WithMockUser(roles = "CF-ADMINS")
3435
@TestPropertySource(value = "classpath:application_test.properties")
36+
@ContextConfiguration(
37+
classes = {ChannelController.class, ElasticConfig.class, ChannelRepository.class})
3538
class ChannelControllerIT {
3639

3740
@Autowired IChannel channelManager;

src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.phoebus.channelfinder.repository.TagRepository;
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
28+
import org.springframework.test.context.ContextConfiguration;
2829
import org.springframework.test.context.TestPropertySource;
2930
import org.springframework.util.LinkedMultiValueMap;
3031
import org.springframework.util.MultiValueMap;
@@ -33,6 +34,7 @@
3334
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3435
@WebMvcTest(ChannelRepository.class)
3536
@TestPropertySource(value = "classpath:application_test.properties")
37+
@ContextConfiguration(classes = {ChannelRepository.class, ElasticConfig.class})
3638
class ChannelRepositoryIT {
3739

3840
@Autowired ElasticConfig esService;

src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
import org.springframework.beans.factory.annotation.Autowired;
2626
import org.springframework.beans.factory.annotation.Value;
2727
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
28+
import org.springframework.test.context.ContextConfiguration;
2829
import org.springframework.test.context.TestPropertySource;
2930
import org.springframework.util.LinkedMultiValueMap;
3031
import org.springframework.util.MultiValueMap;
3132

3233
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3334
@WebMvcTest(ChannelRepository.class)
3435
@TestPropertySource(locations = "classpath:application_test.properties")
36+
@ContextConfiguration(classes = {ChannelRepository.class, ElasticConfig.class})
3537
class ChannelRepositorySearchIT {
3638
private static final Logger logger = Logger.getLogger(ChannelRepositorySearchIT.class.getName());
3739

src/test/java/org/phoebus/channelfinder/ChannelScrollControllerIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import org.phoebus.channelfinder.rest.controller.ChannelScrollController;
1717
import org.springframework.beans.factory.annotation.Autowired;
1818
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
19+
import org.springframework.test.context.ContextConfiguration;
1920
import org.springframework.test.context.TestPropertySource;
2021
import org.springframework.util.LinkedMultiValueMap;
2122
import org.springframework.util.MultiValueMap;
2223

2324
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2425
@WebMvcTest(ChannelScrollController.class)
2526
@TestPropertySource(value = "classpath:application_test.properties")
27+
@ContextConfiguration(classes = {ChannelScrollController.class, ElasticConfig.class})
2628
class ChannelScrollControllerIT {
2729

2830
@Autowired IChannelScroll channelScroll;

src/test/java/org/phoebus/channelfinder/ChannelScrollControllerSearchIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import org.phoebus.channelfinder.rest.controller.ChannelScrollController;
1919
import org.springframework.beans.factory.annotation.Autowired;
2020
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
21+
import org.springframework.test.context.ContextConfiguration;
2122
import org.springframework.test.context.TestPropertySource;
2223
import org.springframework.util.LinkedMultiValueMap;
2324
import org.springframework.util.MultiValueMap;
2425

2526
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2627
@WebMvcTest(ChannelScrollController.class)
2728
@TestPropertySource(value = "classpath:application_test.properties")
29+
@ContextConfiguration(classes = {ChannelScrollController.class, ElasticConfig.class})
2830
class ChannelScrollControllerSearchIT {
2931

3032
private static final Logger logger =

src/test/java/org/phoebus/channelfinder/ChannelValidationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import org.springframework.beans.factory.annotation.Autowired;
2323
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
2424
import org.springframework.security.test.context.support.WithMockUser;
25+
import org.springframework.test.context.ContextConfiguration;
2526
import org.springframework.test.context.TestPropertySource;
2627
import org.springframework.web.server.ResponseStatusException;
2728

2829
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2930
@WebMvcTest(ChannelController.class)
3031
@WithMockUser(roles = "CF-ADMINS")
3132
@TestPropertySource(value = "classpath:application_test.properties")
33+
@ContextConfiguration(classes = {ChannelController.class, ElasticConfig.class})
3234
class ChannelValidationIT {
3335

3436
@Autowired IChannel channelManager;

src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2626
import org.springframework.boot.test.context.SpringBootTest;
2727
import org.springframework.test.context.ActiveProfiles;
28+
import org.springframework.test.context.ContextConfiguration;
2829
import org.springframework.test.context.TestPropertySource;
2930
import org.springframework.test.web.servlet.MockMvc;
3031
import org.springframework.util.LinkedMultiValueMap;
@@ -41,6 +42,7 @@
4142
"metrics.properties=testProperty0: value0, value1; testProperty1: value0, !*",
4243
"metrics.updateInterval=1"
4344
})
45+
@ContextConfiguration(classes = {ElasticConfig.class, MetricsService.class})
4446
class MetricsServiceIT {
4547

4648
public static final String METRICS_ENDPOINT = "/actuator/metrics";
@@ -69,11 +71,6 @@ void setupAll() {
6971
ElasticConfigIT.setUp(esService);
7072
}
7173

72-
@AfterAll
73-
void tearDown() throws IOException {
74-
ElasticConfigIT.teardown(esService);
75-
}
76-
7774
@AfterEach
7875
public void cleanup() {
7976
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();

src/test/java/org/phoebus/channelfinder/MetricsServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void testGenerateAllMultiValueMaps_emptyMap() {
6767
List<MultiValueMap<String, String>> allMaps =
6868
MetricsService.generateAllMultiValueMaps(properties);
6969

70-
assertEquals(1, allMaps.size());
70+
assertEquals(0, allMaps.size());
7171
}
7272

7373
// Helper method to create a MultiValueMap for easier assertion

0 commit comments

Comments
 (0)