Skip to content
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 @@ -12,22 +12,20 @@
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.phoebus.channelfinder.repository.ChannelRepository;
import org.phoebus.channelfinder.repository.PropertyRepository;
import org.phoebus.channelfinder.repository.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

@Service
@PropertySource(value = "classpath:application.properties")
public class MetricsService {

public static final String CF_TOTAL_CHANNEL_COUNT = "cf.total.channel.count";
public static final String CF_PROPERTY_COUNT = "cf.property.count";
public static final String CF_TAG_COUNT = "cf.tag.count";
Expand Down Expand Up @@ -60,7 +58,7 @@ public class MetricsService {

Map<String, List<String>> parseProperties() {
if (metricProperties == null || metricProperties.isEmpty()) {
return new LinkedMultiValueMap<>();
return Map.of();
}
return Arrays.stream(metricProperties.split(";"))
.map(
Expand Down Expand Up @@ -121,9 +119,7 @@ public static List<MultiValueMap<String, String>> generateAllMultiValueMaps(
List<MultiValueMap<String, String>> allMultiValueMaps = new ArrayList<>();

if (properties.isEmpty()) {
allMultiValueMaps.add(
new LinkedMultiValueMap<>()); // Add an empty map for the case where all are null
return allMultiValueMaps;
return List.of();
}

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

@Scheduled(fixedRateString = "${metrics.updateInterval}", timeUnit = TimeUnit.SECONDS)
public void updateMetrics() {
updateTagMetrics();
updatePropertyMetrics();
if (tagMetrics != null && !tagMetrics.isEmpty()) {
updateTagMetrics();
}
if (propertyMetrics != null && !propertyMetrics.isEmpty()) {
updatePropertyMetrics();
}
}
}
2 changes: 2 additions & 0 deletions src/test/java/org/phoebus/channelfinder/AuthorizationIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;

@WebMvcTest(AuthorizationService.class)
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {AuthorizationService.class})
class AuthorizationIT {
@Autowired AuthorizationService authorizationService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.server.ResponseStatusException;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(ChannelController.class)
@WithMockUser(roles = "CF-ADMINS")
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(
classes = {ChannelController.class, ElasticConfig.class, ChannelRepository.class})
class ChannelControllerIT {

@Autowired IChannel channelManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.phoebus.channelfinder.repository.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -33,6 +34,7 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(ChannelRepository.class)
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {ChannelRepository.class, ElasticConfig.class})
class ChannelRepositoryIT {

@Autowired ElasticConfig esService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

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

Expand Down Expand Up @@ -80,7 +82,7 @@
searchParameters.add("~name", channelNames.get(0));
SearchResult result = channelRepository.search(searchParameters);
long countResult = channelRepository.count(searchParameters);
Assertions.assertEquals(1, result.count());

Check failure on line 85 in src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

ChannelRepositorySearchIT.searchTest

expected: <1> but was: <0>
Raw output
org.opentest4j.AssertionFailedError: expected: <1> but was: <0>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:166)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:161)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:632)
	at org.phoebus.channelfinder.ChannelRepositorySearchIT.searchTest(ChannelRepositorySearchIT.java:85)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Assertions.assertEquals(1, result.channels().size());
Assertions.assertEquals(1, countResult);
Assertions.assertEquals(result.channels().get(0).getName(), channelNames.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import org.phoebus.channelfinder.rest.controller.ChannelScrollController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(ChannelScrollController.class)
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {ChannelScrollController.class, ElasticConfig.class})
class ChannelScrollControllerIT {

@Autowired IChannelScroll channelScroll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import org.phoebus.channelfinder.rest.controller.ChannelScrollController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(ChannelScrollController.class)
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {ChannelScrollController.class, ElasticConfig.class})
class ChannelScrollControllerSearchIT {

private static final Logger logger =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.server.ResponseStatusException;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(ChannelController.class)
@WithMockUser(roles = "CF-ADMINS")
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {ChannelController.class, ElasticConfig.class})
class ChannelValidationIT {

@Autowired IChannel channelManager;
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.util.LinkedMultiValueMap;
Expand All @@ -41,6 +42,7 @@
"metrics.properties=testProperty0: value0, value1; testProperty1: value0, !*",
"metrics.updateInterval=1"
})
@ContextConfiguration(classes = {ElasticConfig.class, MetricsService.class})
class MetricsServiceIT {

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

@AfterAll
void tearDown() throws IOException {
ElasticConfigIT.teardown(esService);
}

@AfterEach
public void cleanup() {
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void testGenerateAllMultiValueMaps_emptyMap() {
List<MultiValueMap<String, String>> allMaps =
MetricsService.generateAllMultiValueMaps(properties);

assertEquals(1, allMaps.size());
assertEquals(0, allMaps.size());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. Explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why I had that before, but since I updated MetricsService to now return an empty map instead of a list with an emtpymap, now this should be 0.

}

// Helper method to create a MultiValueMap for easier assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -35,6 +36,7 @@
@WebMvcTest(PropertyController.class) // TODO Somehow creating one
@WithMockUser(roles = "CF-ADMINS")
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {PropertyController.class, ElasticConfig.class})
class PropertyControllerIT {

@Autowired IProperty propertyManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.phoebus.channelfinder.repository.PropertyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -29,6 +30,7 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(PropertyRepository.class)
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {PropertyRepository.class, ElasticConfig.class})
class PropertyRepositoryIT {
public static final String TEST_PROPERTY_NAME = "testProperty";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.server.ResponseStatusException;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(PropertyController.class)
@WithMockUser(roles = "CF-ADMINS")
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {PropertyController.class, ElasticConfig.class})
class PropertyValidationIT {

@Autowired IProperty propertyManager;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.phoebus.channelfinder.repository.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -27,6 +28,7 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(TagRepository.class)
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {TagRepository.class, ElasticConfig.class})
class TagRepositoryIT {

@Autowired ElasticConfig esService;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/phoebus/channelfinder/TagValidationIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.server.ResponseStatusException;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@WebMvcTest(TagController.class)
@WithMockUser(roles = "CF-ADMINS")
@TestPropertySource(value = "classpath:application_test.properties")
@ContextConfiguration(classes = {TagController.class, ElasticConfig.class})
class TagValidationIT {

@Autowired ITag tagManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.springframework.test.context.TestPropertySource;

@WebMvcTest(AAChannelProcessor.class)
@TestPropertySource(value = "classpath:application_test.properties")
@TestPropertySource(value = "classpath:application_aa_proc_test.properties")
class AAChannelProcessorIT {

protected static Property archiveProperty = new Property("archive", "owner", "default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.springframework.test.context.TestPropertySource;

@WebMvcTest(AAChannelProcessor.class)
@TestPropertySource(value = "classpath:application_test.properties")
@TestPropertySource(value = "classpath:application_aa_proc_test.properties")
class AAChannelProcessorMultiIT {

public static final String BEING_ARCHIVED = "Being archived";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@WebMvcTest(AAChannelProcessor.class)
@TestPropertySource(
locations = "classpath:application_test.properties",
locations = "classpath:application_aa_proc_test.properties",
properties = "aa.urls:{'default': '','aa': 'http://localhost:17665'}")
class AAChannelProcessorNoDefaultIT {
protected static Property archiverProperty = new Property("archiver", "owner", "aa");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@WebMvcTest(AAChannelProcessor.class)
@TestPropertySource(
locations = "classpath:application_test.properties",
locations = "classpath:application_aa_proc_test.properties",
properties = "aa.auto_pause=none")
class AAChannelProcessorNoPauseIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@WebMvcTest(AAChannelProcessor.class)
@TestPropertySource(
locations = "classpath:application_test.properties",
locations = "classpath:application_aa_proc_test.properties",
properties = "aa.auto_pause=pvStatus")
class AAChannelProcessorStatusPauseIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@WebMvcTest(AAChannelProcessor.class)
@TestPropertySource(
locations = "classpath:application_test.properties",
locations = "classpath:application_aa_proc_test.properties",
properties = "aa.auto_pause=archive")
class AAChannelProcessorTagPauseIT {

Expand Down
38 changes: 38 additions & 0 deletions src/test/resources/application_aa_proc_test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

logging.level.org.springframework.web=INFO

############################## Service Info ###############################
# ChannelFinder version as defined in the pom file
[email protected]@

############################## REST Logging ###############################
# DEBUG level will log all requests and responses to and from the REST end points
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=INFO

################ Processor ##################################################
processors.chunking.size=10000

################ Archiver Appliance Configuration Processor #################
aa.urls={'default': 'http://localhost:17665'}
aa.default_alias=default
aa.enabled=true
aa.pva=false
aa.archive_property_name=archive
aa.archiver_property_name=archiver

# Set the auto pause behaviour
#
# Empty for no auto pause
# Or pvStatus to pause on pvStatus=Inactive
# Or match archive_property_name to pause on archive_property_name not existing
# Or both, i.e. aa.auto_pause=pvStatus,archive
#
aa.auto_pause=pvStatus,archive


############################## Metrics ###############################
#actuator
management.endpoints.web.exposure.include=prometheus, metrics, health, info
metrics.tags=
metrics.properties=
metrics.updateInterval=1
Loading
Loading