Class AxonServerContainerUtils

java.lang.Object
io.axoniq.framework.testcontainer.AxonServerContainerUtils

public class AxonServerContainerUtils extends Object
Utility class for the AxonServerContainer, used to initialize the cluster.
Since:
4.8.0
Author:
Milan Savic, Sara Pelligrini
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Constant boolean specifying that a context supports DCB.
    static final boolean
    Constant boolean specifying that a context does not support DCB.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<String>
    contexts(String hostname, int port)
    Retrieves all the contexts of the Axon Server instance located at the given hostname and port combination.
    static void
    createContext(String hostname, int port, String context, boolean dcbContext)
    Calls the API of Axon Server at the given hostname and (http) port to create a context with the given context name.
    static void
    createContext(String hostname, int port, String context, boolean dcbContext, String replicationGroup)
    Calls the API of Axon Server at the given hostname and (http) port to create a context with the given context name.
    static void
    deleteContext(String hostname, int port, String context)
    Calls the API of Axon Server at the given hostname and (http) port to delete the given context.
    static void
    initCluster(String hostname, int port, boolean shouldBeReused, boolean dcbContext)
    Initialize the cluster of the Axon Server instance located at the given hostname and port combination.
    static List<String>
    internalContexts(String hostname, int port)
    Retrieves all the internal contexts (registered in the RAFT protocol) of the Axon Server instance located at the given hostname and port combination.
    static void
    purgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext)
    Calls the API of Axon Server at given hostname and (http) port to purge events of the given context.
    static void
    purgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext, String replicationGroup)
    Calls the API of Axon Server at given hostname and (http) port to purge events of the given context.

    Methods inherited from class java.lang.Object

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

    • DCB_CONTEXT

      public static final boolean DCB_CONTEXT
      Constant boolean specifying that a context supports DCB.
      See Also:
    • NO_DCB_CONTEXT

      public static final boolean NO_DCB_CONTEXT
      Constant boolean specifying that a context does not support DCB.
      See Also:
  • Method Details

    • initCluster

      public static void initCluster(String hostname, int port, boolean shouldBeReused, boolean dcbContext) throws IOException
      Initialize the cluster of the Axon Server instance located at the given hostname and port combination.

      Note that this constructs the contexts _admin and default.

      A reusable container (e.g. SharedAxonServerContainer.INSTANCE) can be attached to by more than one Surefire/Failsafe JVM fork at nearly the same time -- synchronized in the caller only guards within a single JVM, not across forked processes. Two concurrent /v2/cluster/init requests against the same, still-uninitialized node corrupt its single-node Raft group membership: the node gets stuck in a perpetual pre-vote/follower loop and never becomes leader, so initCluster always times out (observed directly in CI: two "Request to initialize cluster" log lines 82ms apart on the same node, followed by an endless "Timeout in follower state" / "Starting pre-vote" cycle). A FileLock on a path derived from hostname/port serializes callers targeting the *same* instance across processes, without blocking callers initializing a different instance.

      Parameters:
      hostname - The hostname of the Axon Server instance to initiate the cluster for.
      port - The port of the Axon Server instance to initiate the cluster for.
      shouldBeReused - If set to true, ensure the cluster is not accidentally initialized twice.
      dcbContext - A boolean stating whether a DCB or non-DCB context is being created.
      Throws:
      IOException - When there are issues with the HTTP connection to the Axon Server instance at the given hostname and port, or acquiring the cross-process init lock.
    • contexts

      public static List<String> contexts(String hostname, int port) throws IOException
      Retrieves all the contexts of the Axon Server instance located at the given hostname and port combination.
      Parameters:
      hostname - The hostname of the Axon Server instance to create the given context of.
      port - The port of the Axon Server instance to create the given context of.
      Returns:
      All the contexts of the Axon Server instances located at the given hostname and port combination.
      Throws:
      IOException - When there are issues with the HTTP connection to the Axon Server instance at the given hostname and port.
    • internalContexts

      public static List<String> internalContexts(String hostname, int port) throws IOException
      Retrieves all the internal contexts (registered in the RAFT protocol) of the Axon Server instance located at the given hostname and port combination.
      Parameters:
      hostname - The hostname of the Axon Server instance to create the given context of.
      port - The port of the Axon Server instance to create the given context of.
      Returns:
      All the contexts of the Axon Server instances located at the given hostname and port combination.
      Throws:
      IOException - When there are issues with the HTTP connection to the Axon Server instance at the given hostname and port.
    • purgeEventsFromAxonServer

      public static void purgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext) throws IOException
      Calls the API of Axon Server at given hostname and (http) port to purge events of the given context.
      Parameters:
      hostname - The hostname where AxonServer can be reached.
      port - The HTTP port AxonServer listens to for API calls.
      context - The context to purge.
      dcbContext - A boolean stating whether a DCB or non-DCB context is being purged.
      Throws:
      IOException - When an error occurs communicating with Axon Server.
      Since:
      5.0.0
    • purgeEventsFromAxonServer

      public static void purgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext, String replicationGroup) throws IOException
      Calls the API of Axon Server at given hostname and (http) port to purge events of the given context.
      Parameters:
      hostname - The hostname where AxonServer can be reached.
      port - The HTTP port AxonServer listens to for API calls.
      context - The context to purge.
      dcbContext - A boolean stating whether a DCB or non-DCB context is being purged.
      replicationGroup - The replication group to use for recreating the contest.
      Throws:
      IOException - When an error occurs communicating with Axon Server.
      Since:
      5.0.0
    • deleteContext

      public static void deleteContext(String hostname, int port, String context) throws IOException
      Calls the API of Axon Server at the given hostname and (http) port to delete the given context.

      Concurrent context-mutating calls (create or delete, for any context) against the same Axon Server instance can race each other on its single Raft-backed admin replication group, the same way concurrent cluster-init calls do (see initCluster(java.lang.String, int, boolean, boolean)): a request arriving while the admin group is mid-operation for another context can be rejected with a transient non-2xx response that clears up moments later. This retries on any such response for up to 30 seconds, except a 404 -- that means the context genuinely doesn't exist, which callers commonly rely on failing fast for (e.g. deleting a context that may or may not be there yet, ignoring the failure) -- so a 404 is thrown immediately instead of retried.

      Parameters:
      hostname - The hostname where Axon Server can be reached.
      port - The HTTP port Axon Server listens to for API calls.
      context - The context to delete.
      Throws:
      IOException - When the context does not exist (HTTP 404), or deletion did not succeed within 30 seconds of retrying.
    • createContext

      public static void createContext(String hostname, int port, String context, boolean dcbContext) throws IOException
      Calls the API of Axon Server at the given hostname and (http) port to create a context with the given context name. The dcbContext dictates whether the context to be created support DCB, yes or no.
      Parameters:
      hostname - The hostname where Axon Server can be reached.
      port - The HTTP port Axon Server listens to for API calls.
      context - The context to create.
      dcbContext - A boolean stating whether a DCB or non-DCB context is being created.
      Throws:
      IOException - When an error occurs communicating with Axon Server.
    • createContext

      public static void createContext(String hostname, int port, String context, boolean dcbContext, String replicationGroup) throws IOException
      Calls the API of Axon Server at the given hostname and (http) port to create a context with the given context name. The dcbContext dictates whether the context to be created support DCB, yes or no.

      Concurrent context-mutating calls (create or delete, for any context) against the same Axon Server instance can race each other on its single Raft-backed admin replication group, the same way concurrent cluster-init calls do (see initCluster(java.lang.String, int, boolean, boolean)): a request arriving while the admin group is mid-operation for another context can be rejected with a transient non-2xx response that clears up moments later. This retries on any such response for up to 30 seconds.

      Parameters:
      hostname - The hostname where Axon Server can be reached.
      port - The HTTP port Axon Server listens to for API calls.
      context - The context to create.
      dcbContext - A boolean stating whether a DCB or non-DCB context is being created.
      replicationGroup - The replication group to be used.
      Throws:
      IOException - When creation did not succeed within 30 seconds of retrying.