-
Notifications
You must be signed in to change notification settings - Fork 52
Fix: copy of event data for remote events #2906
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
WhoBrokeTheBuild
merged 7 commits into
MDSplus:alpha
from
merlea:bugfix/remote-event-data
Jun 3, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9d64efe
Fix: fix typo using addEvent instead of removeEvent
merlea e7086f7
Fix: start test for java remote event handling
merlea 74d36f6
Fix: Test wfevent with local and remote events
merlea 7109122
Fix: Fix copy data from remote event
merlea 9f16bb2
Fix: typos and uninitialized memory
merlea dbe3278
Skip wfevent tests
merlea 4ac348b
Skip java tests as well
merlea 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
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
145 changes: 145 additions & 0 deletions
145
java/mdsobjects/src/test/java/MDSplus/MdsRemoteEventTest.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,145 @@ | ||
| package MDSplus; | ||
|
|
||
| import mds.connection.*; | ||
|
|
||
| import java.io.File; | ||
| import java.net.DatagramSocket; | ||
| import java.net.SocketException; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| public class MdsRemoteEventTest implements UpdateEventListener, ConnectionListener | ||
| { | ||
| // See testing/ports.csv | ||
| static int port = 8019; | ||
| static Process mdsip; | ||
|
|
||
| static java.lang.String event = "test_event"; | ||
| static boolean eventReceived = false; | ||
| static boolean connectionLost = false; | ||
|
|
||
| @BeforeClass | ||
| public static void setUpBeforeClass() throws Exception | ||
| { | ||
| int test_port_offset = 0; | ||
| java.lang.String test_port_offset_env = System.getenv("TEST_PORT_OFFSET"); | ||
| if (test_port_offset_env != null) { | ||
| try { | ||
| test_port_offset = Integer.parseInt(test_port_offset_env); | ||
| } | ||
| catch (final NumberFormatException exc) | ||
| {} | ||
| } | ||
|
|
||
| port += test_port_offset; | ||
|
|
||
| try | ||
| { | ||
| new DatagramSocket(port).close(); | ||
| java.lang.String hostspath = System.getenv("MDSPLUS_DIR") + "/testing/mdsip.hosts"; | ||
| if (!new File(hostspath).exists()) | ||
| { | ||
| hostspath = "/etc/mdsip.hosts"; | ||
| if (!new File(hostspath).exists()) | ||
| { | ||
| System.exit(5); | ||
| } | ||
| } | ||
| final java.lang.String parts[] = | ||
| { "mdsip", "-s", "-p", Integer.toString(port), "-h", hostspath }; | ||
| System.out.println(java.lang.String.join(" ", parts)); | ||
| final ProcessBuilder pb = new ProcessBuilder(parts); | ||
| mdsip = pb.start(); | ||
| return; | ||
| } | ||
| catch (final SocketException exc) | ||
| {} | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDownAfterClass() throws Exception | ||
| { | ||
| mdsip.destroy(); | ||
| mdsip.waitFor(); | ||
| } | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception | ||
| {} | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception | ||
| {} | ||
|
|
||
| @Test | ||
| public void testEvent() throws MDSplus.MdsException | ||
| { | ||
| try | ||
| { | ||
| System.out.println("connecting to localhost:" + port + " ... "); | ||
| MdsConnection c = new MdsConnection("localhost:" + port); | ||
| for (int count = 0; count < 3; ++count) | ||
| { | ||
| try | ||
| { | ||
| c.ConnectToMds(false); | ||
| System.out.println("connected!"); | ||
|
|
||
| // Success, stop trying | ||
| break; | ||
| } | ||
| catch (final Exception exc) | ||
| { | ||
| exc.printStackTrace(); | ||
|
|
||
| System.out.println("retry ... "); | ||
| Thread.sleep(1000); | ||
|
|
||
| // Failure, keep trying | ||
| continue; | ||
| } | ||
| } | ||
| Assert.assertFalse("Cannot connect to mdsip server", c == null || !c.isConnected()); | ||
| // Set up connection listener | ||
| c.addConnectionListener(this); | ||
| // Set up event listener | ||
| c.MdsSetEvent((UpdateEventListener) this, event); | ||
| // Trigger Event | ||
| final MDSplus.Data dataMsg = new MDSplus.String("data message"); | ||
| eventReceived = false; | ||
| MDSplus.Event.setEvent(event, dataMsg); | ||
| Thread.sleep(2000); | ||
| // Check connection is still up | ||
| Assert.assertFalse("Connection to mdsip server has been lost", connectionLost); | ||
| // Check event received | ||
| Assert.assertTrue("Data Event not received", eventReceived); | ||
| } | ||
| catch (final Exception exc) | ||
| { | ||
| exc.printStackTrace(); | ||
| Assert.fail(exc.toString()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void processUpdateEvent(UpdateEvent e) | ||
| { | ||
| System.out.println("Event "+e.getName()+" received"); | ||
| if (e.getName().equals(event)) { | ||
| eventReceived = true; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void processConnectionEvent(ConnectionEvent e) | ||
| { | ||
| System.out.println("Connection event: "+e.getInfo()); | ||
| if (e.getID() == ConnectionEvent.LOST_CONNECTION) { | ||
| connectionLost = 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,3 +24,4 @@ TESTS = \ | |
| MDSplus.MdsTreeNodeTest\ | ||
| MDSplus.MdsTreeTest\ | ||
| MDSplus.MdsWindowTest | ||
| # MDSplus.MdsRemoteEventTest | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/bin/bash | ||
|
|
||
| status=0 | ||
|
|
||
| srcdir=$(readlink -f $(dirname ${0})) | ||
|
|
||
| event_name=test_event | ||
| timeout=20 | ||
| sleepdur=5 | ||
|
|
||
| if [ "$OS" == "windows" ]; then | ||
| WFEVENT="wine wfevent" | ||
| SETEVENT="wine setevent" | ||
| OPTTIMEOUT="/t:$timeout" | ||
| OPTDATA="/d" | ||
| DIFF_Z="-Z" | ||
| else | ||
| WFEVENT="wfevent" | ||
| SETEVENT="setevent" | ||
| OPTTIMEOUT="--timeout=$timeout" | ||
| OPTDATA="--data" | ||
| DIFF_Z="" | ||
| fi | ||
|
|
||
| ### TEST 1: local event no data | ||
|
|
||
| name=wfevent | ||
|
|
||
| $WFEVENT $event_name $OPTTIMEOUT > $name.log 2> $name.err & | ||
| pid=$! | ||
| sleep $sleepdur | ||
| $SETEVENT $event_name | ||
|
|
||
| # Make sure wfevent is terminated | ||
| if [ ! kill -0 $pid 2> /dev/null ]; then | ||
| sleep $timeout | ||
| if [ ! kill -0 $pid 2> /dev/null ]; then | ||
| kill -SIGKILL $pid | ||
| fi | ||
| fi | ||
|
|
||
| # Check output of actlog against reference | ||
| if diff $DIFF_Z $name.log ${srcdir}/$name.ans; then | ||
| echo "PASS: $name" | ||
| else | ||
| echo "FAIL: $name" | ||
| status=1 | ||
| fi | ||
|
|
||
| ### TEST 2: local event with data | ||
|
|
||
| name=wfeventData | ||
|
|
||
| $WFEVENT $event_name $OPTDATA $OPTTIMEOUT > $name.log 2> $name.err & | ||
| pid=$! | ||
| sleep $sleepdur | ||
| $SETEVENT $event_name "hello" | ||
|
|
||
| # Make sure wfevent is terminated | ||
| if [ ! kill -0 $pid 2> /dev/null ]; then | ||
| sleep $timeout | ||
| if [ ! kill -0 $pid 2> /dev/null ]; then | ||
| kill -SIGKILL $pid | ||
| fi | ||
| fi | ||
|
|
||
| # Check output of actlog against reference | ||
| if diff $DIFF_Z $name.log ${srcdir}/$name.ans; then | ||
| echo "PASS: $name" | ||
| else | ||
| echo "FAIL: $name" | ||
| status=1 | ||
| fi | ||
|
|
||
| # Return | ||
| exit $status |
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.