示例#1
0
            public void KillsProcesses()
            {
                Container.Destroy();

                ProcessRunner.Received(1).StopAll(true);
                ConstrainedProcessRunner.Received(1).StopAll(true);
            }
示例#2
0
            public void DisposesRunners()
            {
                Container.Destroy();

                ProcessRunner.Received(1).Dispose();
                ConstrainedProcessRunner.Received(1).Dispose();
            }
示例#3
0
            public void DisposesProcessRunners()
            {
                Container.Stop(false);

                ProcessRunner.Received(1).Dispose();
                ConstrainedProcessRunner.Received(1).Dispose();
            }
            public void DisposesHostClient()
            {
                var runner = new ConstrainedProcessRunner(Client);

                runner.Dispose();

                Client.Received(1).Dispose();
            }
示例#5
0
                public void ReturnsNullWhenProcessNotFound()
                {
                    ConstrainedProcessRunner.FindProcessById(-1).Returns(null as IProcess);

                    var actualProcess = Container.FindProcessById(-1);

                    Assert.Null(actualProcess);
                }
            public void DisposesHostClient()
            {
                var runner = new ConstrainedProcessRunner(Client);

                runner.Dispose();

                Client.Received(1).Dispose();
            }
示例#7
0
            public void WhenContainerStopAllThrows_CallsJobobjectTerminate()
            {
                ConstrainedProcessRunner
                .When(x => x.StopAll(true))
                .Do(x => { throw new TimeoutException("Test timeout exception"); });

                Container.Stop(true);

                JobObject.Received(1).TerminateProcessesAndWait();
            }
示例#8
0
                public void CanFindProcessByPid()
                {
                    var pid     = 9123;
                    var process = Substitute.For <IProcess>();

                    process.Id.Returns(pid);
                    ConstrainedProcessRunner.FindProcessById(pid).Returns(process);

                    var actualProcess = Container.FindProcessById(pid);

                    Assert.Equal(actualProcess.Id, pid);
                }
示例#9
0
                public void ProcessIoCanBeNull()
                {
                    var io = new TestProcessIO();

                    io.Output = null;
                    io.Error  = null;

                    Container.Run(Spec, io);

                    var proc = ConstrainedProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal(null, proc.OutputCallback);
                    Assert.Equal(null, proc.ErrorCallback);
                }
示例#10
0
                public void WhenPathMappingIsDisabled_DoesNotMapExecutablePath()
                {
                    var io = Substitute.For <IProcessIO>();

                    Spec.DisablePathMapping = true;
                    Spec.ExecutablePath     = "cmd.exe";

                    var process = Container.Run(Spec, io);

                    Assert.NotNull(process);
                    var actual = ConstrainedProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal("cmd.exe", actual.ExecutablePath);
                }
示例#11
0
                public void RunsTheProcessRemotely()
                {
                    var io = Substitute.For <IProcessIO>();

                    var process = Container.Run(Spec, io);

                    Assert.NotNull(process);
                    var actual = ConstrainedProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal(ExpectedRunSpec.ExecutablePath, actual.ExecutablePath);
                    Assert.Equal(ExpectedRunSpec.Arguments, actual.Arguments);
                    Assert.Superset(
                        new HashSet <string>(ExpectedRunSpec.Environment.Keys),
                        new HashSet <string>(actual.Environment.Keys));
                    Assert.Equal(ExpectedRunSpec.WorkingDirectory, actual.WorkingDirectory);
                }
示例#12
0
                public void ProcessIoIsRedirected()
                {
                    var io            = new TestProcessIO();
                    var remoteProcess = Substitute.For <IProcess>();

                    ConstrainedProcessRunner.Run(Arg.Any <ProcessRunSpec>()).Returns(remoteProcess)
                    .AndDoes(call =>
                    {
                        var runSpec = call.Arg <ProcessRunSpec>();
                        runSpec.OutputCallback("This is STDOUT");
                        runSpec.ErrorCallback("This is STDERR");
                    });

                    Container.Run(Spec, io);

                    Assert.Equal("This is STDOUT", io.Output.ToString());
                    Assert.Equal("This is STDERR", io.Error.ToString());
                }
 public StopAll()
 {
     Runner = new ConstrainedProcessRunner(Client);
 }
 public FindProcessWithId()
 {
     Runner = new ConstrainedProcessRunner(Client);
 }
 public Run()
 {
     Runner = new ConstrainedProcessRunner(Client);
 }
        public IContainer CreateContainer(ContainerSpec containerSpec)
        {
            Guard.NotNull(containerSpec, "containerSpec");

            UndoStack undoStack = new UndoStack();
            IContainer container;

            try
            {
                var handle = containerSpec.Handle;
                if (String.IsNullOrEmpty(handle))
                    handle = handleHelper.GenerateHandle();

                var id = handleHelper.GenerateId(handle);

                var user = ContainerUser.Create(userManager, id);
                undoStack.Push(() => user.Delete());

                var directory = directoryFactory.Create(fileSystem, containerBasePath, id);
                directory.CreateSubdirectories(user);
                undoStack.Push(directory.Destroy);

                directory.CreateBindMounts(containerSpec.BindMounts, user);

                var jobObject = new JobObject(id);
                undoStack.Push(() => jobObject.Dispose());

                var containerHostClient = containerHostService.StartContainerHost(id, directory, jobObject, user.GetCredential());
                undoStack.Push(() => containerHostClient.Shutdown());

                var constrainedProcessRunner = new ConstrainedProcessRunner(containerHostClient);
                undoStack.Push(() => constrainedProcessRunner.Dispose());

                var processHelper = new ProcessHelper();
                var dependencyHelper = new ContainerHostDependencyHelper();

                var diskQuotaControl = diskQuotaManager.CreateDiskQuotaControl(directory);

                container = new Container(
                    id,
                    handle,
                    user,
                    directory,
                    containerPropertiesService,
                    tcpPortManager,
                    jobObject,
                    diskQuotaControl,
                    processRunner,
                    constrainedProcessRunner,
                    processHelper,
                    containerSpec.Environment,
                    dependencyHelper);

                containerPropertiesService.SetProperties(container, containerSpec.Properties);
                lock (containers)
                {
                    containers.Add(container);
                }
            }
            catch (Exception e)
            {
                try
                {
                    undoStack.UndoAll();
                    throw;
                }
                catch (AggregateException undoException)
                {
                    throw new AggregateException(new[] { e, undoException });
                }
            }

            return container;
        }
 public Run()
 {
     Runner = new ConstrainedProcessRunner(Client);
 }
 public StopAll()
 {
     Runner = new ConstrainedProcessRunner(Client);
 }
 public FindProcessWithId()
 {
     Runner = new ConstrainedProcessRunner(Client);
 }
示例#20
0
        public IContainer CreateContainer(ContainerSpec containerSpec)
        {
            Guard.NotNull(containerSpec, "containerSpec");

            UndoStack  undoStack = new UndoStack();
            IContainer container;

            try
            {
                var handle = containerSpec.Handle;
                if (String.IsNullOrEmpty(handle))
                {
                    handle = handleHelper.GenerateHandle();
                }

                var id = handleHelper.GenerateId(handle);

                var user = ContainerUser.Create(userManager, id);
                undoStack.Push(() => user.Delete());

                var directory = directoryFactory.Create(fileSystem, containerBasePath, id);
                directory.CreateSubdirectories(user);
                undoStack.Push(directory.Destroy);

                directory.CreateBindMounts(containerSpec.BindMounts, user);

                var jobObject = new JobObject(id);
                undoStack.Push(() => jobObject.Dispose());

                var containerHostClient = containerHostService.StartContainerHost(id, directory, jobObject, user.GetCredential());
                undoStack.Push(() => containerHostClient.Shutdown());

                var constrainedProcessRunner = new ConstrainedProcessRunner(containerHostClient);
                undoStack.Push(() => constrainedProcessRunner.Dispose());

                var processHelper    = new ProcessHelper();
                var dependencyHelper = new ContainerHostDependencyHelper();

                var diskQuotaControl = diskQuotaManager.CreateDiskQuotaControl(directory);

                container = new Container(
                    id,
                    handle,
                    user,
                    directory,
                    containerPropertiesService,
                    tcpPortManager,
                    jobObject,
                    diskQuotaControl,
                    processRunner,
                    constrainedProcessRunner,
                    processHelper,
                    containerSpec.Environment,
                    dependencyHelper);

                containerPropertiesService.SetProperties(container, containerSpec.Properties);
                lock (containers)
                {
                    containers.Add(container);
                }
            }
            catch (Exception e)
            {
                try
                {
                    undoStack.UndoAll();
                    throw;
                }
                catch (AggregateException undoException)
                {
                    throw new AggregateException(new[] { e, undoException });
                }
            }

            return(container);
        }