Beispiel #1
0
        public void TestLruSetBoundary()
        {
            var lru = new LruSet <int>();

            Assert.False(lru.IsFull);

            lru.Add(0);
            Assert.False(lru.IsFull);
            Assert.Equal(1, lru.Count);

            Assert.True(lru.Remove(0));
            Assert.Equal(0, lru.Count);
            Assert.False(lru.IsFull);

            lru.Fill(x => x, 100);
            Assert.Equal(100, lru.Count);
            Assert.True(lru.IsFull);

            for (var i = 0; i < 100; i++)
            {
                Assert.True(lru.Remove(i));
                Assert.False(lru.IsFull);
            }

            Assert.Equal(0, lru.Count);
            lru.Add(0);
            Assert.Equal(1, lru.Count);
        }
Beispiel #2
0
        public void TestLruSetConstructor()
        {
            var lru = new LruSet <int>();

            Assert.Equal(100, lru.MaxSize);
            lru.Fill(x => x, 100);
            Assert.Equal(100, lru.Count);
            Assert.True(lru.IsFull);
            for (var i = 100; i < 200; i++)
            {
                lru.Add(i);
            }
            Assert.Equal(100, lru.Count);
            Assert.True(lru.IsFull);
            for (var i = 0; i < 100; i++)
            {
                Assert.False(lru.Contains(i));
            }
            for (var i = 100; i < 200; i++)
            {
                Assert.True(lru.Contains(i));
            }
            Assert.Throws(typeof(ArgumentException), () => lru.Add(100));
            Assert.Throws(typeof(ArgumentException), () => lru.Add(101));

            var lru2 = new LruSet <int>(1000);

            Assert.Equal(1000, lru2.MaxSize);
            lru2.Fill(x => x);
            Assert.Equal(1000, lru2.Count);
            lru2.Fill(x => x + 1000, 100);
            for (var i = 0; i < 100; i++)
            {
                Assert.False(lru2.Contains(i));
            }
            for (var i = 100; i < 1100; i++)
            {
                Assert.True(lru2.Contains(i));
            }

            var lru3 = new LruSet <Order>(10000, new OrderEqualityComparer());

            LruSetConstructor(lru3);

            var lru4 = new LruSet <Order>(10000, (x1, x2) => x1.Id == x2.Id);

            LruSetConstructor(lru4);
        }
        /// <summary>
        ///   Ensures that the identified image resides on this server
        ///   The image will be pulled if the tag is not in a set of known pulled images
        ///   Images may be removed to make space on the disk by calling EvictImages
        /// </summary>
        private void PullImage(Identifier identifier)
        {
            // Pull the docker image. If there is not enough space on disk, evict some images and try again
            while (!pulledImages.Refresh(identifier))
            {
                using (var process = Util.Run("docker", $"pull {identifier.Name}:{identifier.Tag}"))
                {
                    process.WaitForExit();

                    if (process.ExitCode != 0)
                    {
                        if (process.StandardError.ReadToEnd().Contains("no space left on device"))
                        {
                            EvictImages();
                            continue;
                        }
                        throw new DockerException(
                                  $"Docker image pull exited with code {process.ExitCode}. Error output follows:\n{process.StandardError.ReadToEnd()}"
                                  );
                    }
                    else
                    {
                        pulledImages.Add(identifier);
                    }
                }
            }
        }
Beispiel #4
0
        public void TestLruSetEliminate()
        {
            var lru = new LruSet <int>(10000);

            lru.Fill(x => x, 10000);
            lru.Add(10000);
            Assert.False(lru.Contains(0));
            for (var i = 0; i < 10000; i++)
            {
                Assert.True(lru.Contains(i + 1));
            }
            Assert.True(lru.IsFull);
        }