Package org.opentrafficsim.sim0mq.swing
Class Sim0MQPublisherTest
java.lang.Object
org.opentrafficsim.sim0mq.swing.Sim0MQPublisherTest
Unit tests. This requires half of OTS in the imports because it sets up a simulation and runs that for a couple of seconds.
Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Peter Knoppers
-
Method Summary
Modifier and TypeMethodDescriptionvoidThis test exists such that the project has a test, and no errors occur during build.static byte[][]readMessages(org.zeromq.ZMQ.Socket socket) Read as many messages from a ZMQ socket as are available.voidTest code.voidverifyAckNack(byte[] got, String field5, int field6, Boolean expectedValue, String expectedDescription) Verify an ACK or a NACK message.voidwaitAndEatMessagesUntilConversationId(List<byte[]> receivedMessages, double maximumSeconds, int conversationId) Wait for incoming messages up to one that has a specified conversation id, or until 1000 times time out.voidwaitAndVerifyAckNack(List<byte[]> receivedMessages, double maximumSeconds, String field5, int field6, Boolean expectedValue, String expectedDescription) Wait for an incoming message and verify that it is an ACK or a NACK.
-
Method Details
-
dummyTest
This test exists such that the project has a test, and no errors occur during build. -
verifyAckNack
public void verifyAckNack(byte[] got, String field5, int field6, Boolean expectedValue, String expectedDescription) throws Sim0MQException, SerializationException Verify an ACK or a NACK message.- Parameters:
got- the not-yet-decoded message that is expected to decode into an ACK or a NACKfield5- expected content for the message type id fieldfield6- expected content for the message id fieldexpectedValue- expected Boolean value for the first payload field (field 8)expectedDescription- expected String value for the second and last payload field (field 9)- Throws:
Sim0MQException- when that happens, this test has failedSerializationException- when that happens this test has failed
-
waitAndVerifyAckNack
public void waitAndVerifyAckNack(List<byte[]> receivedMessages, double maximumSeconds, String field5, int field6, Boolean expectedValue, String expectedDescription) throws Sim0MQException, SerializationException, InterruptedException Wait for an incoming message and verify that it is an ACK or a NACK.- Parameters:
receivedMessages- the list where incoming messages should appearmaximumSeconds- maximum time to waitfield5- expected content for the message type id fieldfield6- expected content for the message id fieldexpectedValue- expected Boolean value for the first payload field (field 8)expectedDescription- expected String value for the second and last payload field (field 9)- Throws:
Sim0MQException- when that happens, this test has failedSerializationException- when that happens this test has failedInterruptedException- when that happens this test has failed
-
testSim0MQPublisher
public void testSim0MQPublisher() throws IOException, nl.tudelft.simulation.dsol.SimRuntimeException, NamingException, nl.tudelft.simulation.language.DsolException, Sim0MQException, SerializationException, InterruptedException, URISyntaxExceptionTest code.- Throws:
IOException- if that happens uncaught; this test has failedNamingException- if that happens uncaught; this test has failednl.tudelft.simulation.dsol.SimRuntimeException- if that happens uncaught; this test has failednl.tudelft.simulation.language.DsolException- if that happens uncaught; this test has failedSerializationException- if that happens uncaught; this test has failedSim0MQException- if that happens uncaught; this test has failedInterruptedException- if that happens uncaught; this test has failedURISyntaxException- if network.xml file not found
-
waitAndEatMessagesUntilConversationId
public void waitAndEatMessagesUntilConversationId(List<byte[]> receivedMessages, double maximumSeconds, int conversationId) throws Sim0MQException, SerializationException, InterruptedException Wait for incoming messages up to one that has a specified conversation id, or until 1000 times time out.- Parameters:
receivedMessages- the list to monitormaximumSeconds- how long to wait (in seconds)conversationId- the conversation id to wait for- Throws:
Sim0MQException- when that happens, this test has failedSerializationException- when that happens, this test has failedInterruptedException- when that happens, this test has failed
-
readMessages
public static byte[][] readMessages(org.zeromq.ZMQ.Socket socket) Read as many messages from a ZMQ socket as are available. Do NOT block when there are no (more) messages to read.- Parameters:
socket- ZMQ.Socket; the socket- Returns:
- the read messages
-