Search code examples
javavagrantconsul

Testing Consul in two datacenter mode


We're integration testing a Java application which uses Consul for Service Discovery. The Embedded Consul examples bootstrap a Consul server in a single datacenter, which works well for most of our testing. However, we're trying to test a situation in which a service record exists in one datacenter and not another. The consul guide uses vagrant to create virtual environments for each datacenter, but this seems difficult to do in an automated testing environment.

Is this the only way to have a consul cluster running locally and simulating two datacenters? Can the Embedded Consul library do this behind the scenes for us, or do we need to invoke vagrant in our integration testing configuration?


Solution

  • Ultimately the issue was that the -data-dir needs to be different for each instance:

    consul agent -server -data-dir=/tmp/consul/node1 -node=agent-tpc -bind=127.0.0.1 -client==127.0.0.1 -datacenter=tpc
    consul agent -server -data-dir=/tmp/consul/node2 -node=agent-cnj -bind=127.0.0.2 -client==127.0.0.2 -datacenter=cnj –retry-join-wan=127.0.0.1