Class 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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    $LastChangedDate: 2020-02-13 11:08:16 +0100 (Thu, 13 Feb 2020) $, @version $Revision: 6383 $, by $Author: pknoppers $,

    Author:
    Peter Knoppers
    • Constructor Detail

      • Sim0MQPublisherTest

        public Sim0MQPublisherTest()
    • Method Detail

      • 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 - byte[]; the not-yet-decoded message that is expected to decode into an ACK or a NACK
        field5 - String; expected content for the message type id field
        field6 - int; expected content for the message id field
        expectedValue - Boolean; expected Boolean value for the first payload field (field 8)
        expectedDescription - String; expected String value for the second and last payload field (field 9)
        Throws:
        Sim0MQException - when that happens, this test has failed
        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 Sim0MQException,
                                         SerializationException,
                                         InterruptedException
        Wait for an incoming message and verify that it is an ACK or a NACK.
        Parameters:
        receivedMessages - List<byte[]>; the list where incoming messages should appear
        maximumSeconds - double; maximum time to wait
        field5 - String; expected content for the message type id field
        field6 - int; expected content for the message id field
        expectedValue - Boolean; expected Boolean value for the first payload field (field 8)
        expectedDescription - String; expected String value for the second and last payload field (field 9)
        Throws:
        Sim0MQException - when that happens, this test has failed
        SerializationException - when that happens this test has failed
        InterruptedException - when that happens this test has failed
      • 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 - List<byte[]>; the list to monitor
        maximumSeconds - double; how long to wait (in seconds)
        conversationId - int; the conversation id to wait for
        Throws:
        Sim0MQException - when that happens, this test has failed
        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 - List<byte[]>; the list to monitor
        maximumSeconds - double; 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 - byte[]; 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:
        byte[][]; the read messages