コード例 #1
0
 public override void Dispose()
 {
     RpcApi.DisposeAsync().AsTask().Wait();
     base.Dispose();
 }
コード例 #2
0
        public AdminTestsSetup()
        {
            var configDirectory =
                System.IO.Directory.CreateDirectory(
                    System.IO.Path.Combine(
                        System.IO.Path.GetTempPath(),
                        System.IO.Path.GetRandomFileName()));

            System.IO.File.WriteAllText(
                System.IO.Path.Combine(configDirectory.FullName, "rippled.cfg"),
                config);


            System.IO.File.WriteAllText(
                System.IO.Path.Combine(configDirectory.FullName, "validators.txt"),
                validators);

            Client = new DockerClientConfiguration(null, TimeSpan.FromMinutes(1.0)).CreateClient();

            // Pull the latest image
            var imagesCreateParameters = new ImagesCreateParameters
            {
                FromImage = "xrpllabsofficial/xrpld",
                Tag       = "latest"
            };
            var progress = new Progress <JSONMessage>();

            Client.Images.CreateImageAsync(imagesCreateParameters, null, progress).Wait();

            var createParameters = new CreateContainerParameters();

            createParameters.Volumes = new Dictionary <string, EmptyStruct>(new [] {
                KeyValuePair.Create("/config", new EmptyStruct()),
            });
            createParameters.Image      = imagesCreateParameters.FromImage + ":" + imagesCreateParameters.Tag;
            createParameters.HostConfig = new HostConfig {
                Binds           = new [] { configDirectory + ":/config:ro" },
                PublishAllPorts = true
            };
            createParameters.Cmd = new[] { "-a", "--start" };

            var container = Client.Containers.CreateContainerAsync(createParameters).Result;

            ID = container.ID;

            var startParameters = new ContainerStartParameters();
            var started         = Client.Containers.StartContainerAsync(ID, startParameters).Result;

            if (!started)
            {
                Dispose();
                throw new Exception("Could not start rippled container");
            }

            var inspect = Client.Containers.InspectContainerAsync(ID).Result;

            foreach (var port in inspect.NetworkSettings.Ports)
            {
                if (port.Key == "5005/tcp")
                {
                    HttpPort = port.Value[0].HostPort;
                }

                if (port.Key == "6006/tcp")
                {
                    WsPort = port.Value[0].HostPort;
                }
            }

            // Check we can ping the server
            for (int i = 0; i < 10; ++i)
            {
                var address    = new Uri("http://localhost:" + this.HttpPort);
                var httpClient = new HttpClient();
                httpClient.BaseAddress = address;
                var api = new JsonRpcApi(httpClient);
                try
                {
                    api.Ping().Wait(TimeSpan.FromSeconds(5.0));
                    break;
                }
                catch
                {
                    if (i == 9)
                    {
                        Dispose();
                        throw;
                    }
                    System.Threading.Thread.Sleep(500);
                }
                finally
                {
                    api.DisposeAsync().AsTask().Wait();
                }
            }
        }