Aerospike 测试容器:2 个命名空间

Sem*_*kov 3 testing integration-testing docker aerospike testcontainers

我正在使用官方Aerospike Docker 映像与 Testcontainers 一起运行它。我可以指定默认名称空间作为环境变量。不幸的是,我无法在容器启动时创建 2 个命名空间。

有什么方法可以实现吗?

Sem*_*kov 5

不能使用环境变量声明多个名称空间。但您可以传递自定义 Aerospike 配置文件。看一下下面的例子:

static final GenericContainer<?> aerospike =
            new GenericContainer<>(DockerImageName.parse("aerospike/aerospike-server:5.6.0.4"))
                .withClasspathResourceMapping("aerospike.conf", "/opt/aerospike/etc/aerospike.conf", READ_ONLY)
                .withExposedPorts(3000, 3001, 3002)
                .withCommand("--config-file /opt/aerospike/etc/aerospike.conf")
                .waitingFor(Wait.forLogMessage(".*migrations: complete.*", 2));
Run Code Online (Sandbox Code Playgroud)

withClasspathResourceMapping方法将aerospike.conf文件复制到容器中。文件被放置在src/test/resources目录中。以下是具有两个命名空间的 Aerospike 配置示例。

# This stanza must come first.
service {
  user root
  group root
  paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1.
  pidfile /var/run/aerospike/asd.pid
  proto-fd-max 15000
}

logging {
  # Log file must be an absolute path.
  file /dev/null {
    context any info
  }

  # Send log messages to stdout
  console {
    context any info
  }
}

network {
  service {
    address any
    port 3000
  }

  heartbeat {

    address any
    mode mesh
    port 3002

    interval 150
    timeout 10
  }

  fabric {
    address any
    port 3001
  }

}

namespace product-namespace {
  replication-factor 1
  memory-size 1G
  default-ttl 30d
  nsup-period 120

  storage-engine device {
    file /opt/aerospike/data/product_namespace.dat
    filesize 4G
    data-in-memory true # Store data in memory in addition to file.
  }
}

namespace client-namespace {
  replication-factor 1
  memory-size 1G
  default-ttl 30d
  nsup-period 120

  storage-engine device {
    file /opt/aerospike/data/client_namespace.dat
    filesize 4G
    data-in-memory true # Store data in memory in addition to file.
  }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,将创建 和product-namespaceclient-namespace