-
Notifications
You must be signed in to change notification settings - Fork 7
[NAE-2355] CreateCaseEvent is published twice per creation #406
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
Open
Smotanka
wants to merge
9
commits into
release/7.0.0-rev10
Choose a base branch
from
NAE-2355
base: release/7.0.0-rev10
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e26a957
[NAE-2355] CreateCaseEvent is published twice per creation
9227234
[NAE-2355] CreateCaseEvent is published twice per creation
445c98b
Merge remote-tracking branch 'origin/NAE-2355' into NAE-2355
31a7f1e
[NAE-2355] CreateCaseEvent is published twice per creation
30799f2
[NAE-2355] CreateCaseEvent is published twice per creation
e593d33
Merge remote-tracking branch 'origin/NAE-2355' into NAE-2355
e1574e6
[NAE-2355] CreateCaseEvent is published twice per creation
8408ff4
[NAE-2355] CreateCaseEvent is published twice per creation
0ebb1b7
Merge remote-tracking branch 'origin/NAE-2355' into NAE-2355
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
Some comments aren't visible on the classic Files Changed page.
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
117 changes: 117 additions & 0 deletions
117
application-engine/src/test/java/com/netgrif/application/engine/event/EventTest.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,117 @@ | ||
| package com.netgrif.application.engine.event; | ||
|
|
||
|
|
||
| import com.netgrif.application.engine.TestHelper; | ||
| import com.netgrif.application.engine.event.dispatchers.CaseDispatcher; | ||
| import com.netgrif.application.engine.objects.event.dispatchers.common.AbstractDispatcher; | ||
| import com.netgrif.application.engine.objects.event.events.workflow.CreateCaseEvent; | ||
| import com.netgrif.application.engine.objects.event.listeners.Listener; | ||
| import com.netgrif.application.engine.objects.petrinet.domain.PetriNet; | ||
| import com.netgrif.application.engine.objects.petrinet.domain.events.EventPhase; | ||
| import com.netgrif.application.engine.startup.ImportHelper; | ||
| import com.netgrif.application.engine.startup.runner.SuperCreatorRunner; | ||
| import com.netgrif.application.engine.workflow.service.interfaces.IWorkflowService; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
|
||
| import java.util.EventObject; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| @SpringBootTest | ||
| @ActiveProfiles({"test"}) | ||
| @ExtendWith(SpringExtension.class) | ||
| public class EventTest { | ||
|
|
||
| @Autowired | ||
| private TestHelper helper; | ||
|
|
||
| @Autowired | ||
| private IWorkflowService workflowService; | ||
|
|
||
| @Autowired | ||
| private ImportHelper importHelper; | ||
|
|
||
| @Autowired | ||
| private SuperCreatorRunner superCreator; | ||
|
|
||
| @Autowired | ||
| private CaseDispatcher caseDispatcher; | ||
|
|
||
| private PetriNet net; | ||
|
|
||
| @BeforeEach | ||
| void beforeEach() { | ||
| helper.truncateDbs(); | ||
| Optional<PetriNet> netOptional = importHelper.createNet("all_data.xml"); | ||
| assertTrue(netOptional.isPresent()); | ||
| this.net = netOptional.get(); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void testCreateCaseEventMultiplicity() { | ||
| AtomicInteger preEventsCounter = new AtomicInteger(0); | ||
| AtomicInteger postEventsCounter = new AtomicInteger(0); | ||
| AtomicReference<Object> createCaseEventRef = new AtomicReference<>(); | ||
| CountDownLatch latch = new CountDownLatch(2); | ||
| AtomicReference<Throwable> asyncException = new AtomicReference<>(); | ||
|
|
||
| Listener listener = new Listener() { | ||
| @Override | ||
| public <E extends EventObject> void onEvent(E event, AbstractDispatcher dispatcher) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public <E extends EventObject> void onAsyncEvent(E event, AbstractDispatcher dispatcher) { | ||
| try { | ||
| createCaseEventRef.set(event); | ||
| CreateCaseEvent createCaseEvent = (CreateCaseEvent) event; | ||
| if (createCaseEvent.getEventPhase() == EventPhase.PRE) { | ||
| preEventsCounter.incrementAndGet(); | ||
| } else { | ||
| postEventsCounter.incrementAndGet(); | ||
| } | ||
| } catch (Throwable e) { | ||
| asyncException.set(e); | ||
| } finally { | ||
|
|
||
| latch.countDown(); | ||
| } | ||
| } | ||
| }; | ||
| listener.register(caseDispatcher, CreateCaseEvent.class, AbstractDispatcher.DispatchMethod.ASYNC); | ||
| workflowService.createCase(net.getStringId(), null, null, superCreator.getLoggedSuper()); | ||
|
|
||
| boolean completed = false; | ||
| try { | ||
| completed = latch.await(5, TimeUnit.SECONDS); | ||
| } catch (InterruptedException e) { | ||
| fail("Interrupted while waiting for async events to complete"); | ||
| } | ||
| assertTrue(completed, "Async events did not complete within timeout"); | ||
|
|
||
| if (asyncException.get() != null) { | ||
| fail("Exception in async event handler: " + asyncException.get().getMessage(), asyncException.get()); | ||
| } | ||
|
|
||
| Object eventObj = createCaseEventRef.get(); | ||
| assertNotNull(eventObj, "Expected non-null event object"); | ||
| assertEquals(CreateCaseEvent.class, eventObj.getClass(), "Expected CreateCaseEvent class"); | ||
| assertNotNull(((CreateCaseEvent) eventObj).getEventPhase(), "Expected non-null Phase Enum"); | ||
| assertEquals(1, preEventsCounter.get(), "Expected exactly one PRE phase event"); | ||
| assertEquals(1, postEventsCounter.get(), "Expected exactly one POST phase event"); | ||
| caseDispatcher.unregisterListener(listener, CreateCaseEvent.class, AbstractDispatcher.DispatchMethod.ASYNC); | ||
| } | ||
| } | ||
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.