-
Notifications
You must be signed in to change notification settings - Fork 20
Make processor enabled runtime #192
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
Merged
shroffk
merged 5 commits into
ChannelFinder:master
from
jacomago:runtime-processor-config
Nov 6, 2025
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de7db43
Make processor enabled runtime
jacomago 599381a
Move aa processor tests into own package
jacomago 7d9d3dc
Add test for the enable disable processor
jacomago 701b713
ChannelProcessorManager test
jacomago 010fbce
Remove verbose comments
jacomago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package org.phoebus.channelfinder.processors; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public record ChannelProcessorInfo(String name, boolean enabled, Map<String, String> properties) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/test/java/org/phoebus/channelfinder/processors/ChannelProcessorServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| package org.phoebus.channelfinder.processors; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.phoebus.channelfinder.entity.Channel; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.test.context.TestPropertySource; | ||
|
|
||
| @SpringBootTest() | ||
| @TestPropertySource(value = "classpath:application_test.properties") | ||
| class ChannelProcessorServiceTest { | ||
|
|
||
| private ChannelProcessorService channelProcessorService; | ||
|
|
||
| @Autowired private DummyProcessor dummyProcessor; | ||
|
|
||
| @Configuration | ||
| static class TestConfig { | ||
| @Bean | ||
| public DummyProcessor dummyProcessor() { | ||
| return new DummyProcessor(); | ||
| } | ||
| } | ||
|
|
||
| static class DummyProcessor implements ChannelProcessor { | ||
| private final AtomicBoolean enabled = new AtomicBoolean(false); | ||
| private final AtomicBoolean processed = new AtomicBoolean(false); | ||
|
|
||
| @Override | ||
| public boolean enabled() { | ||
| return enabled.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setEnabled(boolean enabled) { | ||
| this.enabled.set(enabled); | ||
| } | ||
|
|
||
| @Override | ||
| public ChannelProcessorInfo processorInfo() { | ||
| return new ChannelProcessorInfo("DummyProcessor", enabled.get(), Map.of()); | ||
| } | ||
|
|
||
| @Override | ||
| public long process(List<Channel> channels) throws JsonProcessingException { | ||
| processed.set(true); | ||
| return channels.size(); | ||
| } | ||
|
|
||
| public boolean hasBeenProcessed() { | ||
| return processed.get(); | ||
| } | ||
|
|
||
| public void reset() { | ||
| processed.set(false); | ||
| } | ||
| } | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| channelProcessorService = | ||
| new ChannelProcessorService(List.of(dummyProcessor), Runnable::run, 10); | ||
| } | ||
|
|
||
| @Test | ||
| void testEnableAndDisableDummyProcessor() { | ||
| // Initially, the dummy processor should be disabled | ||
anderslindho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assertions.assertFalse( | ||
| dummyProcessor.enabled(), "Dummy processor should be disabled initially"); | ||
|
|
||
| // Enable the dummy processor | ||
| channelProcessorService.setProcessorEnabled("DummyProcessor", true); | ||
| Assertions.assertTrue(dummyProcessor.enabled(), "Dummy processor should be enabled"); | ||
|
|
||
| // Disable the dummy processor | ||
| channelProcessorService.setProcessorEnabled("DummyProcessor", false); | ||
| Assertions.assertFalse(dummyProcessor.enabled(), "Dummy processor should be disabled"); | ||
| } | ||
|
|
||
| @Test | ||
| void testDummyProcessorProcessing() { | ||
| // Disable the dummy processor | ||
| dummyProcessor.reset(); | ||
| channelProcessorService.setProcessorEnabled("DummyProcessor", false); | ||
| Assertions.assertFalse(dummyProcessor.enabled(), "Dummy processor should be disabled"); | ||
|
|
||
| // Process a channel - dummy processor should not be called | ||
| channelProcessorService.sendToProcessors( | ||
| Collections.singletonList(new Channel("test-channel"))); | ||
| Assertions.assertFalse( | ||
| dummyProcessor.hasBeenProcessed(), "Dummy processor should not have been called"); | ||
|
|
||
| // Enable the dummy processor | ||
| channelProcessorService.setProcessorEnabled("DummyProcessor", true); | ||
| Assertions.assertTrue(dummyProcessor.enabled(), "Dummy processor should be enabled"); | ||
|
|
||
| // Process a channel - dummy processor should be called | ||
| channelProcessorService.sendToProcessors( | ||
| Collections.singletonList(new Channel("test-channel"))); | ||
| Assertions.assertTrue( | ||
| dummyProcessor.hasBeenProcessed(), "Dummy processor should have been called"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.