Esempio n. 1
0
        public async Task RestartUnfinishedBuild()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                env.BatchTrainer.Train(Arg.Any <IProgress <ProgressStatus> >(), Arg.Do <Action>(checkCanceled =>
                {
                    while (true)
                    {
                        checkCanceled();
                    }
                }));
                Build build = await runtime.StartBuildAsync();

                Assert.That(build, Is.Not.Null);
                await env.WaitForBuildToStartAsync(build.Id);

                env.DisposeEngineService();
                build = await env.BuildRepository.GetAsync(build.Id);

                Assert.That(build.State, Is.EqualTo(BuildStates.Pending));
                env.CreateEngineService();
                await env.WaitForBuildToFinishAsync(build.Id);

                build = await env.BuildRepository.GetAsync(build.Id);

                Assert.That(build.State, Is.EqualTo(BuildStates.Completed));
            }
        }
Esempio n. 2
0
        public async Task <bool> AddProjectAsync(Project project)
        {
            CheckDisposed();

            using (await _lock.WriterLockAsync())
            {
                Engine engine = project.IsShared
                                        ? await _engines.GetByLanguageTagAsync(project.SourceLanguageTag, project.TargetLanguageTag)
                                        : null;

                try
                {
                    if (engine == null)
                    {
                        // no existing shared engine or a project-specific engine
                        engine = new Engine
                        {
                            Projects          = { project.Id },
                            IsShared          = project.IsShared,
                            SourceLanguageTag = project.SourceLanguageTag,
                            TargetLanguageTag = project.TargetLanguageTag
                        };
                        await _engines.InsertAsync(engine);

                        EngineRuntime runtime = CreateRuntime(engine.Id);
                        await runtime.InitNewAsync();
                    }
                    else
                    {
                        // found an existing shared engine
                        if (engine.Projects.Contains(project.Id))
                        {
                            return(false);
                        }
                        engine = await _engines.ConcurrentUpdateAsync(engine, e => e.Projects.Add(project.Id));
                    }
                }
                catch (KeyAlreadyExistsException)
                {
                    // a project with the same id already exists
                    return(false);
                }

                project.EngineRef = engine.Id;
                await _projects.InsertAsync(project);

                return(true);
            }
        }
Esempio n. 3
0
        public async Task TranslateAsync()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.EngineOptions.InactiveEngineTimeout = TimeSpan.FromHours(1);
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                TranslationResult result = await runtime.TranslateAsync("esto es una prueba .".Split());

                Assert.That(result.TargetSegment, Is.EqualTo("this is a test .".Split()));
            }
        }
Esempio n. 4
0
        public async Task CommitAsync_LoadedActive()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.EngineOptions.InactiveEngineTimeout = TimeSpan.FromHours(1);
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                await runtime.TrainSegmentPairAsync("esto es una prueba .".Split(), "this is a test .".Split());

                await runtime.CommitAsync();

                env.SmtModel.Received().Save();
                Assert.That(runtime.IsLoaded, Is.True);
            }
        }
Esempio n. 5
0
        public async Task StartBuildAsync_BatchTrainerCalled()
        {
            using (var env = new EngineServiceTestEnvironment())
            {
                env.CreateEngineService();
                Engine engine = await env.CreateEngineAsync();

                EngineRuntime runtime = env.GetRuntime(engine.Id);
                await runtime.InitNewAsync();

                Build build = await runtime.StartBuildAsync();

                Assert.That(build, Is.Not.Null);
                await env.WaitForBuildToFinishAsync(build.Id);

                env.BatchTrainer.Received().Train(Arg.Any <IProgress <ProgressStatus> >(), Arg.Any <Action>());
                env.BatchTrainer.Received().Save();
                build = await env.BuildRepository.GetAsync(build.Id);

                Assert.That(build.State, Is.EqualTo(BuildStates.Completed));
            }
        }