Class HiveMQContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<HiveMQContainer>
org.testcontainers.hivemq.HiveMQContainer
All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<HiveMQContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class HiveMQContainer extends org.testcontainers.containers.GenericContainer<HiveMQContainer>
Testcontainers implementation for HiveMQ.

Supported images: hivemq/hivemq4, hivemq/hivemq-ce

Exposed ports:

  • MQTT: 1883
  • Control Center: 8080
  • Debug: 9000
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    HiveMQContainer(@NotNull org.testcontainers.utility.DockerImageName dockerImageName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
    containerIsStarted(@NotNull com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
     
    void
    disableExtension(@NotNull String extensionName, @NotNull String extensionDirectory)
    Disables the extension with the given name and extension directory name.
    void
    disableExtension(@NotNull String extensionName, @NotNull String extensionDirectory, @NotNull Duration timeout)
    Disables the extension with the given name and extension directory name.
    void
    disableExtension(@NotNull HiveMQExtension hiveMQExtension)
    Disables the extension.
    void
    disableExtension(@NotNull HiveMQExtension hiveMQExtension, @NotNull Duration timeout)
    Disables the extension.
    void
    enableExtension(@NotNull String extensionName, @NotNull String extensionDirectory)
    Enables the extension with the given name and extension directory name.
    void
    enableExtension(@NotNull String extensionName, @NotNull String extensionDirectory, @NotNull Duration timeout)
    Enables the extension with the given name and extension directory name.
    void
    enableExtension(@NotNull HiveMQExtension hiveMQExtension)
    Enables the extension.
    void
    enableExtension(@NotNull HiveMQExtension hiveMQExtension, @NotNull Duration timeout)
    Enables the extension.
    int
    Get the mapped port for the MQTT port of the container.
    waitForExtension(@NotNull String extensionName)
    Adds a wait condition for the extension with this name.
    waitForExtension(@NotNull HiveMQExtension extension)
    Adds a wait condition for this HiveMQExtension
    Enables connection to the HiveMQ Control Center on host port 8080.
    Enables the possibility for remote debugging clients to connect.
    withExtension(@NotNull HiveMQExtension hiveMQExtension)
    Wraps the given class and all its subclasses into an extension and puts it into '/opt/hivemq/temp-extensions/{extension-id}' inside the container.
    withExtension(@NotNull org.testcontainers.utility.MountableFile mountableExtension)
    Puts the given extension folder into '/opt/hivemq/temp-extensions/{directory-name}' inside the container.
    withFileInExtensionHomeFolder(@NotNull org.testcontainers.utility.MountableFile file, @NotNull String extensionId)
    Puts the given file into the root of the extension's home '/opt/hivemq/temp-extensions/{extensionId}/'.
    withFileInExtensionHomeFolder(@NotNull org.testcontainers.utility.MountableFile file, @NotNull String extensionId, @NotNull String pathInExtensionHome)
    Puts the given file into given subdirectory of the extensions's home '/opt/hivemq/temp-extensions/{id}/{pathInExtensionHome}/'
    withFileInHomeFolder(@NotNull org.testcontainers.utility.MountableFile mountableFile, @NotNull String pathInHomeFolder)
    Puts the given file into the given subdirectory of the HiveMQ home folder '/opt/hivemq/{pathInHomeFolder}'.
    withHiveMQConfig(@NotNull org.testcontainers.utility.MountableFile mountableConfig)
    Overwrites the HiveMQ configuration in '/opt/hivemq/conf/' inside the container.
    withLicense(@NotNull org.testcontainers.utility.MountableFile mountableLicense)
    Puts the given license into '/opt/hivemq/license/' inside the container.
    withLogLevel(@NotNull org.slf4j.event.Level level)
    Sets the logging Level inside the container.
    Removes all prepackaged extension folders from '/opt/hivemq/extensions' before the container is started.
    withoutPrepackagedExtensions(@NotNull String... extensionIds)
    Removes the specified prepackaged extension folders from '/opt/hivemq/extensions' before the container is started.

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, containerIsCreated, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, stop, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Constructor Details

    • HiveMQContainer

      public HiveMQContainer(@NotNull @NotNull org.testcontainers.utility.DockerImageName dockerImageName)
  • Method Details

    • configure

      protected void configure()
      Overrides:
      configure in class org.testcontainers.containers.GenericContainer<HiveMQContainer>
    • containerIsStarted

      protected void containerIsStarted(@NotNull @NotNull com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
      Overrides:
      containerIsStarted in class org.testcontainers.containers.GenericContainer<HiveMQContainer>
    • waitForExtension

      @NotNull public @NotNull HiveMQContainer waitForExtension(@NotNull @NotNull String extensionName)
      Adds a wait condition for the extension with this name.

      Must be called before the container is started.

      Parameters:
      extensionName - the extension to wait for
      Returns:
      self
    • waitForExtension

      @NotNull public @NotNull HiveMQContainer waitForExtension(@NotNull @NotNull HiveMQExtension extension)
      Adds a wait condition for this HiveMQExtension

      Must be called before the container is started.

      Parameters:
      extension - the extension to wait for
      Returns:
      self
    • withDebugging

      @NotNull public @NotNull HiveMQContainer withDebugging()
      Enables the possibility for remote debugging clients to connect.

      Must be called before the container is started.

      Returns:
      self
    • withLogLevel

      @NotNull public @NotNull HiveMQContainer withLogLevel(@NotNull @NotNull org.slf4j.event.Level level)
      Sets the logging Level inside the container.

      Must be called before the container is started.

      Parameters:
      level - the Level
      Returns:
      self
    • withExtension

      @NotNull public @NotNull HiveMQContainer withExtension(@NotNull @NotNull HiveMQExtension hiveMQExtension)
      Wraps the given class and all its subclasses into an extension and puts it into '/opt/hivemq/temp-extensions/{extension-id}' inside the container.

      Must be called before the container is started.

      The contents of the '/opt/hivemq/temp-extensions/' directory are copied to '/opt/hivemq/extensions/' before the container is started.

      Parameters:
      hiveMQExtension - the HiveMQExtension of the extension
      Returns:
      self
    • withExtension

      @NotNull public @NotNull HiveMQContainer withExtension(@NotNull @NotNull org.testcontainers.utility.MountableFile mountableExtension)
      Puts the given extension folder into '/opt/hivemq/temp-extensions/{directory-name}' inside the container. It must at least contain a valid hivemq-extension.xml and a valid extension.jar in order to be executed. The directory-name is taken from the id defined in the hivemq-extension.xml.

      Must be called before the container is started.

      The contents of the '/opt/hivemq/temp-extensions/' directory are copied to '/opt/hivemq/extensions/' before the container is started.

      Parameters:
      mountableExtension - the extension folder on the host machine
      Returns:
      self
    • withoutPrepackagedExtensions

      @NotNull public @NotNull HiveMQContainer withoutPrepackagedExtensions(@NotNull @NotNull String... extensionIds)
      Removes the specified prepackaged extension folders from '/opt/hivemq/extensions' before the container is started.

      Must be called before the container is started.

      Parameters:
      extensionIds - the prepackaged extensions to remove
      Returns:
      self
    • withoutPrepackagedExtensions

      @NotNull public @NotNull HiveMQContainer withoutPrepackagedExtensions()
      Removes all prepackaged extension folders from '/opt/hivemq/extensions' before the container is started.

      Must be called before the container is started.

      Returns:
      self
    • withLicense

      @NotNull public @NotNull HiveMQContainer withLicense(@NotNull @NotNull org.testcontainers.utility.MountableFile mountableLicense)
      Puts the given license into '/opt/hivemq/license/' inside the container. It must end with '.lic' or '.elic'.

      Must be called before the container is started.

      Parameters:
      mountableLicense - the license file on the host machine
      Returns:
      self
    • withHiveMQConfig

      @NotNull public @NotNull HiveMQContainer withHiveMQConfig(@NotNull @NotNull org.testcontainers.utility.MountableFile mountableConfig)
      Overwrites the HiveMQ configuration in '/opt/hivemq/conf/' inside the container.

      Must be called before the container is started.

      Parameters:
      mountableConfig - the config file on the host machine
      Returns:
      self
    • withFileInExtensionHomeFolder

      @NotNull public @NotNull HiveMQContainer withFileInExtensionHomeFolder(@NotNull @NotNull org.testcontainers.utility.MountableFile file, @NotNull @NotNull String extensionId)
      Puts the given file into the root of the extension's home '/opt/hivemq/temp-extensions/{extensionId}/'.

      Must be called before the container is started.

      The contents of the '/opt/hivemq/temp-extensions/' directory are copied to '/opt/hivemq/extensions/' before the container is started.

      Parameters:
      file - the file on the host machine
      extensionId - the extension
      Returns:
      self
    • withFileInExtensionHomeFolder

      @NotNull public @NotNull HiveMQContainer withFileInExtensionHomeFolder(@NotNull @NotNull org.testcontainers.utility.MountableFile file, @NotNull @NotNull String extensionId, @NotNull @NotNull String pathInExtensionHome)
      Puts the given file into given subdirectory of the extensions's home '/opt/hivemq/temp-extensions/{id}/{pathInExtensionHome}/'

      Must be called before the container is started.

      The contents of the '/opt/hivemq/temp-extensions/' directory are copied to '/opt/hivemq/extensions/' before the container is started.

      Parameters:
      file - the file on the host machine
      extensionId - the extension
      pathInExtensionHome - the path
      Returns:
      self
    • withFileInHomeFolder

      @NotNull public @NotNull HiveMQContainer withFileInHomeFolder(@NotNull @NotNull org.testcontainers.utility.MountableFile mountableFile, @NotNull @NotNull String pathInHomeFolder)
      Puts the given file into the given subdirectory of the HiveMQ home folder '/opt/hivemq/{pathInHomeFolder}'.

      Must be called before the container is started.

      Parameters:
      mountableFile - the file on the host machine
      pathInHomeFolder - the path
      Returns:
      self
    • disableExtension

      public void disableExtension(@NotNull @NotNull String extensionName, @NotNull @NotNull String extensionDirectory, @NotNull @NotNull Duration timeout) throws TimeoutException
      Disables the extension with the given name and extension directory name. This method blocks until the HiveMQ log for successful disabling is consumed or it times out after {timeOut}. Note: Disabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      extensionName - the name of the extension to disable
      extensionDirectory - the name of the extension's directory
      timeout - the timeout
      Throws:
      TimeoutException - if the extension was not disabled within the configured timeout
    • disableExtension

      public void disableExtension(@NotNull @NotNull String extensionName, @NotNull @NotNull String extensionDirectory) throws TimeoutException
      Disables the extension with the given name and extension directory name. This method blocks until the HiveMQ log for successful disabling is consumed or it times out after 60 seconds. Note: Disabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      extensionName - the name of the extension to disable
      extensionDirectory - the name of the extension's directory
      Throws:
      TimeoutException - if the extension was not disabled within 60 seconds
    • disableExtension

      public void disableExtension(@NotNull @NotNull HiveMQExtension hiveMQExtension, @NotNull @NotNull Duration timeout) throws TimeoutException
      Disables the extension. This method blocks until the HiveMQ log for successful disabling is consumed or it times out after {timeOut}. Note: Disabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      hiveMQExtension - the extension
      timeout - the timeout
      Throws:
      TimeoutException - if the extension was not disabled within the configured timeout
    • disableExtension

      public void disableExtension(@NotNull @NotNull HiveMQExtension hiveMQExtension) throws TimeoutException
      Disables the extension. This method blocks until the HiveMQ log for successful disabling is consumed or it times out after 60 seconds. Note: Disabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      hiveMQExtension - the extension
      Throws:
      TimeoutException - if the extension was not disabled within 60 seconds
    • enableExtension

      public void enableExtension(@NotNull @NotNull String extensionName, @NotNull @NotNull String extensionDirectory, @NotNull @NotNull Duration timeout) throws TimeoutException
      Enables the extension with the given name and extension directory name. This method blocks until the HiveMQ log for successful enabling is consumed or it times out after {timeOut}. Note: Enabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      extensionName - the name of the extension to disable
      extensionDirectory - the name of the extension's directory
      timeout - the timeout
      Throws:
      TimeoutException - if the extension was not enabled within the configured timeout
    • enableExtension

      public void enableExtension(@NotNull @NotNull String extensionName, @NotNull @NotNull String extensionDirectory) throws TimeoutException
      Enables the extension with the given name and extension directory name. This method blocks until the HiveMQ log for successful enabling is consumed or it times out after 60 seconds. Note: Enabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      extensionName - the name of the extension to disable
      extensionDirectory - the name of the extension's directory
      Throws:
      TimeoutException - if the extension was not enabled within 60 seconds
    • enableExtension

      public void enableExtension(@NotNull @NotNull HiveMQExtension hiveMQExtension, @NotNull @NotNull Duration timeout) throws TimeoutException
      Enables the extension. This method blocks until the HiveMQ log for successful enabling is consumed or it times out after {timeOut}. Note: Enabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      hiveMQExtension - the extension
      timeout - the timeout
      Throws:
      TimeoutException - if the extension was not enabled within the configured timeout
    • enableExtension

      public void enableExtension(@NotNull @NotNull HiveMQExtension hiveMQExtension) throws TimeoutException
      Enables the extension. This method blocks until the HiveMQ log for successful enabling is consumed or it times out after {timeOut}. Note: Enabling Extensions is a HiveMQ Enterprise feature, it will not work when using the HiveMQ Community Edition.

      This can only be called once the container is started.

      Parameters:
      hiveMQExtension - the extension
      Throws:
      TimeoutException - if the extension was not enabled within 60 seconds
    • withControlCenter

      @NotNull public @NotNull HiveMQContainer withControlCenter()
      Enables connection to the HiveMQ Control Center on host port 8080. Note: the control center is a HiveMQ 4 Enterprise feature.

      Must be called before the container is started.

      Returns:
      self
    • getMqttPort

      public int getMqttPort()
      Get the mapped port for the MQTT port of the container.

      Must be called after the container is started.

      Returns:
      the port on the host machine for mqtt clients to connect