예제 #1
0
        public void Test()
        {
            // Deploy a couple of simple NodeJS based services, one listening on
            // port 8080 and the other on 8081.  We're also going to use the
            // [HostsFixture] to map a couple of DNS names to a hive manager
            // address and then use these to query the services.

            // Confirm that the hive starts out with no running stacks or services.

            Assert.Empty(hiveFixture.ListStacks());
            Assert.Empty(hiveFixture.ListServices());

            // Add the local DNS entries for the services we'll deploy.  We're
            // publishing these on host ports, so we'll map the DNS entries to
            // the local loopback address.

            var managerAddress = hive.FirstManager.PrivateAddress.ToString();

            hosts.AddHostAddress("foo.com", managerAddress, deferCommit: true);
            hosts.AddHostAddress("bar.com", managerAddress, deferCommit: true);
            hosts.Commit();

            // Spin up a couple of NodeJS as stacks configuring them to return
            // different text using the OUTPUT environment variable.

            hiveFixture.CreateService("foo", "nhive/node", dockerArgs: new string[] { "--publish", "8080:80" }, env: new string[] { "OUTPUT=FOO" });
            hiveFixture.CreateService("bar", "nhive/node", dockerArgs: new string[] { "--publish", "8081:80" }, env: new string[] { "OUTPUT=BAR" });

            // Verify that each of the services are returning the expected output.

            using (var client = new HttpClient())
            {
                Assert.Equal("FOO", client.GetStringAsync("http://foo.com:8080").Result.Trim());
                Assert.Equal("BAR", client.GetStringAsync("http://bar.com:8081").Result.Trim());
            }

            // Remove one of the services and verify.

            hiveFixture.RemoveStack("foo-service");
            Assert.Empty(hiveFixture.ListServices().Where(s => s.Name == "foo-service"));
        }
예제 #2
0
        public async Task HostsDbStacks()
        {
            // Deploy a couple of simple NodeJS based services as stacks, one
            // listening on  port 8080 and the other on 8081.  We're also going
            // to use the [HostsFixture] to map a couple of DNS names to the local
            // loopback address and then use these to query the services and finally,
            // we're going to do some things to Couchbase.

            // Confirm that Docker starts out with no running stacks or services.

            Assert.Empty(fixture.ListStacks());
            Assert.Empty(fixture.ListServices());

            // Use the [HostsFixture] to initialize a couple DNS entries and then verify that these work.

            hosts.AddHostAddress("test-foo.com", "127.0.0.1", deferCommit: true);
            hosts.AddHostAddress("test-bar.com", "127.0.0.1", deferCommit: true);
            hosts.Commit();

            Assert.Equal(new IPAddress[] { IPAddress.Parse("127.0.0.1") }, Dns.GetHostAddresses("test-foo.com"));
            Assert.Equal(new IPAddress[] { IPAddress.Parse("127.0.0.1") }, Dns.GetHostAddresses("test-bar.com"));

            // Spin up a couple of NodeJS services configuring them to return
            // different text using the OUTPUT environment variable.

            var fooCompose =
                @"version: '3'

services:
  web:
    image: nhive/node
    ports:
      - ""8080:80""
    environment:
      - ""OUTPUT=FOO""
";

            fixture.DeployStack("foo-stack", fooCompose);

            var barCompose =
                @"version: '3'

services:
  web:
    image: nhive/node
    ports:
      - ""8081:80""
    environment:
      - ""OUTPUT=BAR""
";

            fixture.DeployStack("bar-stack", barCompose);

            // Verify that each of the services are returning the expected output.

            using (var client = new HttpClient())
            {
                Assert.Equal("FOO", client.GetStringAsync("http://test-foo.com:8080").Result.Trim());
                Assert.Equal("BAR", client.GetStringAsync("http://test-bar.com:8081").Result.Trim());
            }

            // Do some Couchbase operations to prove that we can.

            bucket.UpsertSafeAsync("one", "1").Wait();
            bucket.UpsertSafeAsync("two", "2").Wait();

            Assert.Equal("1", await bucket.GetSafeAsync <string>("one"));
            Assert.Equal("2", await bucket.GetSafeAsync <string>("two"));

            // Remove one of the stacks and verify.

            fixture.RemoveStack("foo-stack");
            Assert.Empty(fixture.ListStacks().Where(s => s.Name == "foo-stack"));
        }