Class Sim0MQPublisherTest

java.lang.Object
org.opentrafficsim.sim0mq.swing.Sim0MQPublisherTest

public class Sim0MQPublisherTest extends Object
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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static class 
    Thread that runs a PublisherExperiment.
    (package private) static class 
    Repeatedly try to read all available messages.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This 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.
    (package private) static void
    sendCommand(org.zeromq.ZMQ.Socket socket, byte[] message)
    Wrapper for ZMQ.Socket.send that may output some debugging information.
    void
    Test code.
    void
    verifyAckNack(byte[] got, String field5, int field6, Boolean expectedValue, String expectedDescription)
    Verify an ACK or a NACK message.
    void
    waitAndEatMessagesUntilConversationId(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.
    void
    waitAndVerifyAckNack(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.
    (package private) static void
    waitForReceivedMessages(List<byte[]> receivedMessages, double maximumSeconds)
    Sleep up to 1 second waiting for at least one message to be received.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sim0MQPublisherTest

      public Sim0MQPublisherTest()
  • Method Details

    • dummyTest

      @Test public void 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 org.sim0mq.Sim0MQException, org.djutils.serialization.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 NACK
      field5 - expected content for the message type id field
      field6 - expected content for the message id field
      expectedValue - expected Boolean value for the first payload field (field 8)
      expectedDescription - expected String value for the second and last payload field (field 9)
      Throws:
      org.sim0mq.Sim0MQException - when that happens, this test has failed
      org.djutils.serialization.SerializationException - 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 org.sim0mq.Sim0MQException, org.djutils.serialization.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 appear
      maximumSeconds - maximum time to wait
      field5 - expected content for the message type id field
      field6 - expected content for the message id field
      expectedValue - expected Boolean value for the first payload field (field 8)
      expectedDescription - expected String value for the second and last payload field (field 9)
      Throws:
      org.sim0mq.Sim0MQException - when that happens, this test has failed
      org.djutils.serialization.SerializationException - when that happens this test has failed
      InterruptedException - when that happens this test has failed
    • testSim0MQPublisher

      public void testSim0MQPublisher() throws IOException, nl.tudelft.simulation.dsol.SimRuntimeException, NamingException, nl.tudelft.simulation.language.DsolException, org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException, InterruptedException, URISyntaxException
      Test code.
      Throws:
      IOException - if that happens uncaught; this test has failed
      NamingException - if that happens uncaught; this test has failed
      nl.tudelft.simulation.dsol.SimRuntimeException - if that happens uncaught; this test has failed
      nl.tudelft.simulation.language.DsolException - if that happens uncaught; this test has failed
      org.djutils.serialization.SerializationException - if that happens uncaught; this test has failed
      org.sim0mq.Sim0MQException - if that happens uncaught; this test has failed
      InterruptedException - if that happens uncaught; this test has failed
      URISyntaxException - if network.xml file not found
    • waitAndEatMessagesUntilConversationId

      public void waitAndEatMessagesUntilConversationId(List<byte[]> receivedMessages, double maximumSeconds, int conversationId) throws org.sim0mq.Sim0MQException, org.djutils.serialization.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 monitor
      maximumSeconds - how long to wait (in seconds)
      conversationId - the conversation id to wait for
      Throws:
      org.sim0mq.Sim0MQException - when that happens, this test has failed
      org.djutils.serialization.SerializationException - when that happens, this test has failed
      InterruptedException - when that happens, this test has failed
    • waitForReceivedMessages

      static void waitForReceivedMessages(List<byte[]> receivedMessages, double maximumSeconds) throws InterruptedException
      Sleep up to 1 second waiting for at least one message to be received.
      Parameters:
      receivedMessages - the list to monitor
      maximumSeconds - how long to wait (in seconds)
      Throws:
      InterruptedException - when that happens uncaught; this test has failed
    • sendCommand

      static void sendCommand(org.zeromq.ZMQ.Socket socket, byte[] message)
      Wrapper for ZMQ.Socket.send that may output some debugging information.
      Parameters:
      socket - ZMQ.Socket; the socket to send onto
      message - the message to transmit
    • 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