Пример #1
0
            public void WhenManagingMultipleProcesses()
            {
                const long oneProcessPrivateMemory = 1024;
                TimeSpan   expectedTotalKernelTime = TimeSpan.FromSeconds(2);
                TimeSpan   expectedTotalUserTime   = TimeSpan.FromSeconds(2);

                var expectedCpuStats = new CpuStatistics
                {
                    TotalKernelTime = expectedTotalKernelTime,
                    TotalUserTime   = expectedTotalUserTime,
                };

                var firstProcess = Substitute.For <IProcess>();

                firstProcess.Id.Returns(1);
                firstProcess.PrivateMemoryBytes.Returns(oneProcessPrivateMemory);

                var secondProcess = Substitute.For <IProcess>();

                secondProcess.Id.Returns(2);
                secondProcess.PrivateMemoryBytes.Returns(oneProcessPrivateMemory);

                JobObject.GetCpuStatistics().Returns(expectedCpuStats);
                JobObject.GetProcessIds().Returns(new int[] { 1, 2 });

                ProcessHelper.GetProcesses(null).ReturnsForAnyArgs(new[] { firstProcess, secondProcess });

                var metrics = Container.GetMetrics();

                Assert.Equal(expectedTotalKernelTime + expectedTotalUserTime, metrics.CpuStat.TotalProcessorTime);
                Assert.Equal((ulong)firstProcess.PrivateMemoryBytes + (ulong)secondProcess.PrivateMemoryBytes, metrics.MemoryStat.PrivateBytes);
            }
Пример #2
0
        private ContainerCpuStat GetCpuStat()
        {
            var cpuStatistics = jobObject.GetCpuStatistics();

            return(new ContainerCpuStat
            {
                TotalProcessorTime = cpuStatistics.TotalKernelTime + cpuStatistics.TotalUserTime,
            });
        }
Пример #3
0
        public ContainerTests()
        {
            ConstrainedProcessRunner = Substitute.For <IProcessRunner>();
            ContainerEnvironment     = new Dictionary <string, string>()
            {
                { "Handle", "handle" }
            };

            Directory = Substitute.For <IContainerDirectory>();

            JobObject = Substitute.For <JobObject>();
            JobObject.GetCpuStatistics().Returns(new CpuStatistics
            {
                TotalKernelTime = TimeSpan.Zero,
                TotalUserTime   = TimeSpan.Zero,
            });
            JobObject.GetProcessIds().Returns(new int[0]);

            ProcessHelper = Substitute.For <ProcessHelper>();
            ProcessRunner = Substitute.For <IProcessRunner>();
            ContainerPropertiesService = Substitute.For <IContainerPropertyService>();

            TcpPortManager = Substitute.For <ILocalTcpPortManager>();

            User = Substitute.For <IContainerUser>();
            _containerUsername = string.Concat("container-username-", Guid.NewGuid().ToString());
            User.UserName.Returns(_containerUsername);

            ContainerDiskQuota = Substitute.For <IContainerDiskQuota>();

            DependencyHelper = Substitute.For <ContainerHostDependencyHelper>();

            bindMounts = new[]
            {
                new BindMount()
            };

            Container = new Container(
                string.Concat("id-", Guid.NewGuid()),
                string.Concat("handle-", Guid.NewGuid()),
                User,
                Directory,
                ContainerPropertiesService,
                TcpPortManager,
                JobObject,
                ContainerDiskQuota,
                ProcessRunner,
                ConstrainedProcessRunner,
                ProcessHelper,
                ContainerEnvironment,
                DependencyHelper,
                bindMounts
                );
        }
Пример #4
0
            public void WhenContainerStopped_Runs()
            {
                JobObject.GetCpuStatistics().Returns(new CpuStatistics
                {
                    TotalKernelTime = TimeSpan.Zero,
                    TotalUserTime   = TimeSpan.Zero,
                });
                JobObject.GetProcessIds().Returns(new int[0]);

                Container.Stop(false);
                var info = Container.GetInfo();

                Assert.NotNull(info);
            }
Пример #5
0
            public void WhenManagingNoProcess()
            {
                JobObject.GetCpuStatistics().Returns(new CpuStatistics
                {
                    TotalKernelTime = TimeSpan.Zero,
                    TotalUserTime   = TimeSpan.Zero,
                });
                JobObject.GetProcessIds().Returns(new int[0]);


                var metrics = Container.GetMetrics();

                Assert.Equal(TimeSpan.Zero, metrics.CpuStat.TotalProcessorTime);
                Assert.Equal(0ul, metrics.MemoryStat.PrivateBytes);
            }