コード例 #1
0
        public void ParsePythonApi()
        {
            var json = loadJsonFile("pythonApi.json");

            var simData = json.ToObject <SimulationData>();

            SimulationConfigUtils.ProcessKnownTemplates(ref simData);

            Assert.That(simData.Template != null, Is.True);
            Assert.That(simData.Template.Alias, Is.EqualTo("pythonApi"));
            Assert.That(simData.Template.Parameters.Length, Is.EqualTo(3));

            Assert.That(simData.ApiOnly, Is.True);

            var s = Newtonsoft.Json.JsonConvert.SerializeObject(simData, JsonSettings.camelCase);

            Debug.Log($"Simulation data: {s}");

            Assert.That(simData.Map == null, Is.True);
            Assert.That(simData.Vehicles == null, Is.True);

            var environment = new Dictionary <string, string>();

            SimulationConfigUtils.UpdateTestCaseEnvironment(simData.Template, environment);

            Assert.That(environment["SIMULATOR_API_ONLY"], Is.EqualTo("1"));
            Assert.That(environment["SIMULATOR_TC_FILENAME"], Is.EqualTo("scenario.py"));
        }
コード例 #2
0
        public void ParseRandomTrafficFull()
        {
            var json = loadJsonFile("randomTrafficFull.json");

            var simData = json.ToObject <SimulationData>();

            SimulationConfigUtils.ProcessKnownTemplates(ref simData);

            Assert.That(simData.Template != null, Is.True);
            Assert.That(simData.Template.Alias, Is.EqualTo("randomTraffic"));
            Assert.That(simData.Template.Parameters.Length, Is.EqualTo(12));

            Assert.That(simData.ApiOnly, Is.False);

            var s = Newtonsoft.Json.JsonConvert.SerializeObject(simData, JsonSettings.camelCase);

            Debug.Log($"Simulation data: {s}");

            Assert.That(simData.Map != null, Is.True);
            Assert.That(simData.Map.Id, Is.EqualTo("a7b32bdb-acc3-40e9-b893-29e4955a209f"));
            Assert.That(simData.Vehicles != null, Is.True);
            Assert.That(simData.Vehicles.Length, Is.EqualTo(1));
            Assert.That(simData.Vehicles[0].Id, Is.EqualTo("a88495aa-e4f9-4e1f-a790-cdbca41deeff"));
            Assert.That(simData.Seed, Is.EqualTo(42));
        }
コード例 #3
0
        public void ParseRandomTrafficWithoutVehicles()
        {
            // Config data does not contain SIMULATOR_MAP parameter
            var json = loadJsonFile("randomTrafficWithoutVehicles.json");

            var simData = json.ToObject <SimulationData>();

            Assert.That(
                () => { SimulationConfigUtils.ProcessKnownTemplates(ref simData); },
                Throws.InstanceOf <MissedTemplateParameterError>().With.Message.EqualTo("SIMULATOR_VEHICLES")
                );
        }
コード例 #4
0
        public void ParseLeagcy01()
        {
            var json = loadJsonFile("legacy01.json");

            var simData = json.ToObject <SimulationData>();

            SimulationConfigUtils.ProcessKnownTemplates(ref simData);

            Assert.That(simData.Map != null, Is.True);
            Assert.That(simData.Map.Id, Is.EqualTo("841b956b-7848-4c04-a017-5bd4d8385bbd"));
            Assert.That(simData.Vehicles != null, Is.True);
            Assert.That(simData.Vehicles[0].Id, Is.EqualTo("a65e1504-27d9-4338-8161-e59cef6de2bb"));
        }
コード例 #5
0
        public void ParseApiOnly()
        {
            var json = loadJsonFile("apiOnly.json");

            var simData = json.ToObject <SimulationData>();

            SimulationConfigUtils.ProcessKnownTemplates(ref simData);

            Assert.That(simData.ApiOnly, Is.True);
            Assert.True(simData.ApiOnly);

            var s = Newtonsoft.Json.JsonConvert.SerializeObject(simData, JsonSettings.camelCase);

            Debug.Log($"Simulation data: {s}");
        }
コード例 #6
0
        public async Task <TestCaseFinishedArgs> StartProcess(TemplateData template, string workingDirectory)
        {
            var environment = new Dictionary <string, string>();

            SimulationConfigUtils.UpdateTestCaseEnvironment(template, environment);
            var runArgs = new List <string> {
                "run"
            };

            if (environment.ContainsKey("SIMULATOR_TC_FILENAME"))
            {
                runArgs.Add(environment["SIMULATOR_TC_FILENAME"]);
            }

            Debug.Log($"Start TC process from image {template.Runner.Docker.Image}");

            // path/image
            // path/image:tag

            // host/path/image
            // host/path/image:tag

            // host:port/path/image
            // host:port/path/image:tag

            string dockerRepository = template.Runner.Docker.Image;
            string dockerTag        = "latest";

            int colonPos = dockerRepository.LastIndexOf(":");

            if (colonPos > 0 && dockerRepository.IndexOf('/', colonPos) < 0)
            {
                dockerTag        = dockerRepository.Substring(colonPos + 1);
                dockerRepository = dockerRepository.Substring(0, colonPos);
            }

            Debug.Log($"Docker repository:{dockerRepository} tag:{dockerTag}");

            var authConfig = AuthConfigFromTemplate(template);

            var id = await RunContainer(authConfig, dockerRepository, dockerTag, runArgs, environment, workingDirectory);

            return(await GetContainerResult(id));
        }
コード例 #7
0
        public void ParseRandomTrafic()
        {
            var json = loadJsonFile("randomTraffic.json");

            var simData = json.ToObject <SimulationData>();

            SimulationConfigUtils.ProcessKnownTemplates(ref simData);

            Assert.That(simData.Template != null, Is.True);
            Assert.That(simData.Template.Alias, Is.EqualTo("randomTraffic"));
            Assert.That(simData.Template.Parameters.Length, Is.EqualTo(3));

            Assert.That(simData.ApiOnly, Is.False);

            var s = Newtonsoft.Json.JsonConvert.SerializeObject(simData, JsonSettings.camelCase);

            Debug.Log($"Simulation data: {s}");

            Assert.That(simData.Map != null, Is.True);
            Assert.That(simData.Map.Id, Is.EqualTo("841b956b-7848-4c04-a017-5bd4d8385bbd"));
            Assert.That(simData.Vehicles != null, Is.True);
            Assert.That(simData.Vehicles[0].Id, Is.EqualTo("a65e1504-27d9-4338-8161-e59cef6de2bb"));
        }
コード例 #8
0
    async Task Parse(string s)
    {
        // Debug.Log(s);
        if (string.IsNullOrEmpty(s))
        {
            return;
        }

        try
        {
            if (s.StartsWith("data:") && !string.IsNullOrEmpty(s.Substring(6)))
            {
                JObject deserialized = JObject.Parse(s.Substring(5));
                if (deserialized != null && deserialized.HasValues)
                {
                    var status = deserialized.GetValue("status");
                    if (status != null)
                    {
                        switch (status.ToString())
                        {
                        case "Unrecognized":
                            RunOnUnityThread(() =>
                            {
                                Status = ConnectionStatus.Connected;
                                ConnectionUI.instance.UpdateStatus();
                            });
                            break;

                        case "OK":
                            RunOnUnityThread(() =>
                            {
                                Status = ConnectionStatus.Online;
                                ConnectionUI.instance.UpdateStatus();
                            });
                            break;

                        case "Config":
                            RunOnUnityThread(() =>
                            {
                                Status = ConnectionStatus.Online;
                                ConnectionUI.instance.UpdateStatus();

                                SimulationData simData;
                                try
                                {
                                    simData = deserialized["data"].ToObject <SimulationData>();
                                    SimulationConfigUtils.ProcessKnownTemplates(ref simData);
                                }
                                catch (Exception e) when(e is InvalidCastException ||
                                                         e is NullReferenceException)
                                {
                                    Debug.LogError($"[CONN] Failed to parse Config data: '{s}'");
                                    Debug.LogException(e);
                                    throw;
                                }
                                Loader.StartSimulation(simData);
                            });
                            break;

                        case "Disconnect":
                            RunOnUnityThread(() =>
                            {
                                DisconnectReason = deserialized.GetValue("reason")?.ToString() ?? "unknown reason";
                                Disconnect();
                            });
                            break;

                        case "Timeout":
                            RunOnUnityThread(() =>
                            {
                                DisconnectReason = deserialized.GetValue("reason")?.ToString() ?? "unknown reason";
                                Disconnect();
                            });
                            break;

                        case "Stop":
                            if (Loader.Instance.Status == SimulatorStatus.Idle || Loader.Instance.Status == SimulatorStatus.Stopping)
                            {
                                SimulationData simData = Newtonsoft.Json.JsonConvert.DeserializeObject <SimulationData>(deserialized.GetValue("data").ToString());
                                Debug.Log("not running");
                                await API.UpdateStatus("Stopping", simData.Id, "stop requested but was not running simulation");

                                await API.UpdateStatus("Idle", simData.Id, "");

                                return;
                            }
                            Loader.StopAsync();
                            break;

                        default:
                            Debug.LogError($"Unknown Status '{status.ToString()}'! Disconnecting.");
                            RunOnUnityThread(() =>
                            {
                                Disconnect();
                            });
                            break;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }