Class LazyNetwork

java.lang.Object
software.xdev.tci.network.LazyNetwork
All Implemented Interfaces:
AutoCloseable, org.junit.rules.TestRule, org.testcontainers.containers.Network

public class LazyNetwork extends Object implements org.testcontainers.containers.Network
A better implementation of Network in relation to Network.NetworkImpl.

Improvements:

  • Allows creation of the network in the background
  • Doesn't create the network inside Network.NetworkImpl.getId()
  • Doesn't check for duplicate network names when using a random UUID as name (see below)
  • Tries to delete the network when it's closed

  • Field Details

    • name

      protected String name
      Behavior if null: random UUID will be chosen
    • enableIpv6

      protected Boolean enableIpv6
    • driver

      protected String driver
    • createNetworkCmdModifiers

      protected Set<Consumer<com.github.dockerjava.api.command.CreateNetworkCmd>> createNetworkCmdModifiers
    • checkDuplicate

      protected Boolean checkDuplicate
      Behavior if null: false when no name is specified (random UUID), otherwise true because
      • When using a random UUIDv4 as name the chances of collision are extremely small (1 : 2.17 x 10^18)
        Wikipedia
      • According to the Docker docs this is "best effort" and not guaranteed to catch all name collisions.
    • deleteNetworkOnClose

      protected boolean deleteNetworkOnClose
    • deleteNetworkOnCloseTries

      protected int deleteNetworkOnCloseTries
    • startCF

      protected CompletableFuture<Void> startCF
    • id

      protected String id
  • Constructor Details

    • LazyNetwork

      public LazyNetwork()
  • Method Details

    • create

      public void create()
    • create

      public void create(Function<Runnable,CompletableFuture<Void>> executor)
    • startInternal

      protected void startInternal()
    • waitForCreation

      public void waitForCreation(Duration timeout)
    • getIdWithoutCheck

      public String getIdWithoutCheck()
    • getId

      public String getId()
      Specified by:
      getId in interface org.testcontainers.containers.Network
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface org.testcontainers.containers.Network
    • closeInternal

      protected void closeInternal()
    • getClient

      protected com.github.dockerjava.api.DockerClient getClient()
    • withName

      public LazyNetwork withName(String name)
    • withEnableIpv6

      public LazyNetwork withEnableIpv6(Boolean enableIpv6)
    • withDriver

      public LazyNetwork withDriver(String driver)
    • withCreateNetworkCmdModifier

      public LazyNetwork withCreateNetworkCmdModifier(Consumer<com.github.dockerjava.api.command.CreateNetworkCmd> createNetworkCmdModifier)
    • withCheckDuplicate

      public LazyNetwork withCheckDuplicate(Boolean checkDuplicate)
    • withDeleteNetworkOnClose

      public LazyNetwork withDeleteNetworkOnClose(boolean deleteNetworkOnClose)
    • withDeleteNetworkOnCloseTries

      public LazyNetwork withDeleteNetworkOnCloseTries(int deleteNetworkOnCloseTries)
    • getName

      public String getName()
    • getEnableIpv6

      public Boolean getEnableIpv6()
    • getDriver

      public String getDriver()
    • getCreateNetworkCmdModifiers

      public Set<Consumer<com.github.dockerjava.api.command.CreateNetworkCmd>> getCreateNetworkCmdModifiers()
    • getCheckDuplicate

      public Boolean getCheckDuplicate()
    • isDeleteNetworkOnClose

      public boolean isDeleteNetworkOnClose()
    • getDeleteNetworkOnCloseTries

      public int getDeleteNetworkOnCloseTries()
    • apply

      @Deprecated(forRemoval=true) public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Deprecated, for removal: This API element is subject to removal in a future version.
      JUNit4 is effectively dead
      Specified by:
      apply in interface org.junit.rules.TestRule