-
Notifications
You must be signed in to change notification settings - Fork 159
NXT-4224: WIP: New event type 'WORKFLOW_CHANGED' #25
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
Draft
xnhp
wants to merge
5
commits into
master
Choose a base branch
from
enh/NXT-4424-workflow-syncer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
125 changes: 125 additions & 0 deletions
125
org.knime.core.tests/src/org/knime/core/node/workflow/WorkflowResourceCacheTest.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,125 @@ | ||
| /* | ||
| * ------------------------------------------------------------------------ | ||
| * | ||
| * Copyright by KNIME AG, Zurich, Switzerland | ||
| * Website: http://www.knime.com; Email: [email protected] | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License, Version 3, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but | ||
| * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, see <http://www.gnu.org/licenses>. | ||
| * | ||
| * Additional permission under GNU GPL version 3 section 7: | ||
| * | ||
| * KNIME interoperates with ECLIPSE solely via ECLIPSE's plug-in APIs. | ||
| * Hence, KNIME and ECLIPSE are both independent programs and are not | ||
| * derived from each other. Should, however, the interpretation of the | ||
| * GNU GPL Version 3 ("License") under any applicable laws result in | ||
| * KNIME and ECLIPSE being a combined program, KNIME AG herewith grants | ||
| * you the additional permission to use and propagate KNIME together with | ||
| * ECLIPSE with only the license terms in place for ECLIPSE applying to | ||
| * ECLIPSE and the GNU GPL Version 3 applying for KNIME, provided the | ||
| * license terms of ECLIPSE themselves allow for the respective use and | ||
| * propagation of ECLIPSE together with KNIME. | ||
| * --------------------------------------------------------------------- | ||
| * | ||
| * History | ||
| * Dec 23, 2025 (assistant): created | ||
| */ | ||
| package org.knime.core.node.workflow; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertSame; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| /** | ||
| * Unit tests for {@link WorkflowResourceCache}. | ||
| */ | ||
| @SuppressWarnings("resource") // caches disposed by tests as needed | ||
| public class WorkflowResourceCacheTest { | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| // clean up any lingering context to not leak across tests | ||
| while (NodeContext.getContext() != null) { | ||
| NodeContext.removeLastContext(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testComputeIfAbsentCachesPerWorkflow() { | ||
| var cache = new WorkflowResourceCache(); | ||
| var wfm = Mockito.mock(WorkflowManager.class); | ||
| Mockito.when(wfm.getWorkflowResourceCache()).thenReturn(cache); | ||
|
|
||
| NodeContext.pushContext(wfm); | ||
|
|
||
| var calls = new AtomicInteger(); | ||
| var first = WorkflowResourceCache.computeIfAbsent(TestResource.class, () -> { | ||
| calls.incrementAndGet(); | ||
| return new TestResource(); | ||
| }); | ||
| var second = WorkflowResourceCache.computeIfAbsent(TestResource.class, TestResource::new); | ||
|
|
||
| assertSame(first, second); | ||
| assertEquals(1, calls.get()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPutAndGetFromCache() { | ||
| var cache = new WorkflowResourceCache(); | ||
|
|
||
| assertFalse(cache.getFromCache(TestResource.class).isPresent()); | ||
|
|
||
| var first = new TestResource(); | ||
| assertNull(cache.put(TestResource.class, first)); | ||
| assertSame(first, cache.getFromCache(TestResource.class).orElseThrow()); | ||
|
|
||
| var second = new TestResource(); | ||
| assertSame(first, cache.put(TestResource.class, second)); | ||
| assertSame(second, cache.getFromCache(TestResource.class).orElseThrow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDisposeClearsEntriesAndDisposesResources() { | ||
| var cache = new WorkflowResourceCache(); | ||
| var resource = new DisposingResource(); | ||
| cache.put(DisposingResource.class, resource); | ||
|
|
||
| cache.dispose(); | ||
|
|
||
| assertTrue("dispose() should clear cached entries", cache.getFromCache(DisposingResource.class).isEmpty()); | ||
| assertTrue("dispose() should call WorkflowResource.dispose()", resource.disposed); | ||
| } | ||
|
|
||
| private static final class TestResource implements WorkflowResource { | ||
| @Override | ||
| public void dispose() { | ||
| // no-op | ||
| } | ||
| } | ||
|
|
||
| private static final class DisposingResource implements WorkflowResource { | ||
| boolean disposed; | ||
|
|
||
| @Override | ||
| public void dispose() { | ||
| disposed = true; | ||
| } | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
WORKFLOW_CHANGEDevent is fired unconditionally on everysetDirty()call, even when the workflow is already dirty. This could result in redundant event notifications for listeners. Consider firing this event only whensendWorkflowDirtyEventis true, or document why unconditional firing is necessary for the browser sync functionality.