Пример #1
0
        public void UnloadNonexistingChunkTest()
        {
            var cache = new GlobalChunkCache((p, i) => null, (i) => null, (p, i, c) => { });

            Assert.Throws <NotSupportedException>(() =>
            {
                cache.Release(4, new Index2(2, 2), false);
            });
        }
Пример #2
0
        public void UnloadNonexistingChunkTest()
        {
            var cache = new GlobalChunkCache((i) => null, (i, c) => { });

            try
            {
                cache.Release(new PlanetIndex3(4, new Index3(2, 2, 2)), true);
                Assert.Fail("Exception expected");
            }
            catch (NotSupportedException) { }
        }
Пример #3
0
        public void LoadChunkTest()
        {
            int          planet          = 2;
            Index2       index           = new Index2(6, 7);
            IChunkColumn result          = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
            {
                Assert.Equals(i, index);
                loadCallCounter++;
                return(result = new TestChunkColumn(planet, index));
            },
                (i) => null,
                (p, i, c) =>
            {
                Assert.Equals(p, planet);
                Assert.Equals(i, index);
                Assert.Equals(c, result);
                saveCallCounter++;
            });

            Assert.Equals(0, cache.LoadedChunkColumns);
            Assert.Equals(0, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            // Chunk laden
            IChunkColumn x = cache.Subscribe(planet, index, false);

            Assert.Equals(x, result);
            Assert.Equals(x.Planet, planet);
            Assert.Equals(x.Index, index);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            Assert.Equals(1, cache.LoadedChunkColumns);

            // Chunk unload
            cache.Release(planet, index, false);
            System.Threading.Thread.Sleep(150);//TODO: dirty fix wait till completly cleaned up
            Assert.Equals(0, cache.LoadedChunkColumns);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(0, saveCallCounter);//Expected 0 cause chunk wasn't changed
        }
Пример #4
0
        public void LoadChunkTest()
        {
            int          planet          = 2;
            Index2       index           = new Index2(6, 7);
            IChunkColumn result          = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
            {
                Assert.AreEqual(i, index);
                loadCallCounter++;
                return(result = new TestChunkColumn(planet, index));
            },
                (p, i, c) =>
            {
                Assert.AreEqual(p, planet);
                Assert.AreEqual(i, index);
                Assert.AreEqual(c, result);
                saveCallCounter++;
            });

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Chunk laden
            IChunkColumn x = cache.Subscribe(planet, index);

            Assert.AreEqual(x, result);
            Assert.AreEqual(x.Planet, planet);
            Assert.AreEqual(x.Index, index);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            Assert.AreEqual(1, cache.LoadedChunkColumns);

            // Chunk unload
            cache.Release(planet, index);

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #5
0
        public void LoadChunkTest()
        {
            int planet = 2;
            Index2 index = new Index2(6, 7);
            IChunkColumn result = null;
            int loadCallCounter = 0;
            int saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
                {
                    Assert.AreEqual(i, index);
                    loadCallCounter++;
                    return result = new TestChunkColumn(planet, index);
                },
                (p, i, c) =>
                {
                    Assert.AreEqual(p, planet);
                    Assert.AreEqual(i, index);
                    Assert.AreEqual(c, result);
                    saveCallCounter++;
                });

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Chunk laden
            IChunkColumn x = cache.Subscribe(planet, index);
            Assert.AreEqual(x, result);
            Assert.AreEqual(x.Planet, planet);
            Assert.AreEqual(x.Index, index);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            Assert.AreEqual(1, cache.LoadedChunkColumns);

            // Chunk unload
            cache.Release(planet, index);

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #6
0
        public void LoadChunkTest()
        {
            PlanetIndex3 index           = new PlanetIndex3(4, new Index3(5, 6, 7));
            IChunk       result          = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (i) =>
            {
                Assert.AreEqual(i, index);
                loadCallCounter++;
                return(result = new TestChunk(index));
            },
                (i, c) =>
            {
                Assert.AreEqual(i, index);
                Assert.AreEqual(c, result);
                saveCallCounter++;
            });

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Chunk laden
            IChunk x = cache.Subscribe(index, true);

            Assert.AreEqual(x, result);
            Assert.AreEqual(x.Planet, index.Planet);
            Assert.AreEqual(x.Index, index.ChunkIndex);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            Assert.AreEqual(1, cache.LoadedChunks);

            // Chunk unload
            cache.Release(index, true);

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #7
0
        public void LoadChunkTest()
        {
            PlanetIndex3 index = new PlanetIndex3(4, new Index3(5, 6, 7));
            IChunk result = null;
            int loadCallCounter = 0;
            int saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (i) =>
                {
                    Assert.AreEqual(i, index);
                    loadCallCounter++;
                    return result = new TestChunk(index);
                },
                (i, c) =>
                {
                    Assert.AreEqual(i, index);
                    Assert.AreEqual(c, result);
                    saveCallCounter++;
                });

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Chunk laden
            IChunk x = cache.Subscribe(index, true);
            Assert.AreEqual(x, result);
            Assert.AreEqual(x.Planet, index.Planet);
            Assert.AreEqual(x.Index, index.ChunkIndex);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            Assert.AreEqual(1, cache.LoadedChunks);

            // Chunk unload
            cache.Release(index, true);

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #8
0
 public void UnloadNonexistingChunkTest()
 {
     var cache = new GlobalChunkCache((i) => null, (i, c) => { });
     try
     {
         cache.Release(new PlanetIndex3(4, new Index3(2, 2, 2)), true);
         Assert.Fail("Exception expected");
     }
     catch (NotSupportedException) { }
 }
Пример #9
0
        public void LoadMultipleChunksTest()
        {
            PlanetIndex3 index1 = new PlanetIndex3(4, new Index3(5, 6, 7));
            PlanetIndex3 index2 = new PlanetIndex3(12, new Index3(15, 16, 17));
            IChunk result1 = null;
            IChunk result2 = null;
            int loadCallCounter = 0;
            int saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (i) =>
                {
                    loadCallCounter++;
                    if (i.Planet == 4)
                    {
                        Assert.AreEqual(i, index1);
                        return result1 = new TestChunk(index1);
                    }
                    else if (i.Planet == 12)
                    {
                        Assert.AreEqual(i, index2);
                        return result2 = new TestChunk(index2);
                    }

                    throw new NotSupportedException();
                },
                (i, c) =>
                {
                    saveCallCounter++;
                    if (i.Planet == 4)
                    {
                        Assert.AreEqual(i, index1);
                        Assert.AreEqual(c, result1);
                        return;
                    }
                    else if (i.Planet == 12)
                    {
                        Assert.AreEqual(i, index2);
                        Assert.AreEqual(c, result2);
                        return;
                    }

                    throw new NotSupportedException();
                });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunk x1 = cache.Subscribe(index1, true);
            Assert.AreEqual(x1, result1);
            Assert.AreEqual(x1.Planet, index1.Planet);
            Assert.AreEqual(x1.Index, index1.ChunkIndex);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunk x2 = cache.Subscribe(index2, true);
            Assert.AreEqual(x2, result2);
            Assert.AreEqual(x2.Planet, index2.Planet);
            Assert.AreEqual(x2.Index, index2.ChunkIndex);

            Assert.AreEqual(2, cache.LoadedChunks);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(index1, true);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);

            // Unload 2
            cache.Release(index2, true);

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(2, saveCallCounter);
        }
Пример #10
0
        public void LoadMultipleChunksTest()
        {
            PlanetIndex3 index1          = new PlanetIndex3(4, new Index3(5, 6, 7));
            PlanetIndex3 index2          = new PlanetIndex3(12, new Index3(15, 16, 17));
            IChunk       result1         = null;
            IChunk       result2         = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (i) =>
            {
                loadCallCounter++;
                if (i.Planet == 4)
                {
                    Assert.AreEqual(i, index1);
                    return(result1 = new TestChunk(index1));
                }
                else if (i.Planet == 12)
                {
                    Assert.AreEqual(i, index2);
                    return(result2 = new TestChunk(index2));
                }

                throw new NotSupportedException();
            },
                (i, c) =>
            {
                saveCallCounter++;
                if (i.Planet == 4)
                {
                    Assert.AreEqual(i, index1);
                    Assert.AreEqual(c, result1);
                    return;
                }
                else if (i.Planet == 12)
                {
                    Assert.AreEqual(i, index2);
                    Assert.AreEqual(c, result2);
                    return;
                }

                throw new NotSupportedException();
            });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunk x1 = cache.Subscribe(index1, true);

            Assert.AreEqual(x1, result1);
            Assert.AreEqual(x1.Planet, index1.Planet);
            Assert.AreEqual(x1.Index, index1.ChunkIndex);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunk x2 = cache.Subscribe(index2, true);

            Assert.AreEqual(x2, result2);
            Assert.AreEqual(x2.Planet, index2.Planet);
            Assert.AreEqual(x2.Index, index2.ChunkIndex);

            Assert.AreEqual(2, cache.LoadedChunks);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(index1, true);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);

            // Unload 2
            cache.Release(index2, true);

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(2, saveCallCounter);
        }
Пример #11
0
        public void LoadChunkWithMultipleReferencesTest()
        {
            PlanetIndex3 index           = new PlanetIndex3(4, new Index3(5, 6, 7));
            IChunk       result          = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (i) =>
            {
                loadCallCounter++;
                Assert.AreEqual(i, index);
                return(result = new TestChunk(index));
            },
                (i, c) =>
            {
                saveCallCounter++;
                Assert.AreEqual(i, index);
                Assert.AreEqual(c, result);
            });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunk x1 = cache.Subscribe(index, true);

            Assert.AreEqual(x1, result);
            Assert.AreEqual(x1.Planet, index.Planet);
            Assert.AreEqual(x1.Index, index.ChunkIndex);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunk x2 = cache.Subscribe(index, true);

            Assert.AreEqual(x2, result);
            Assert.AreEqual(x2.Planet, index.Planet);
            Assert.AreEqual(x2.Index, index.ChunkIndex);
            Assert.AreEqual(x1, x2);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(index, true);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 2
            cache.Release(index, true);

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #12
0
        public void LoadMultipleChunksTest()
        {
            int planet1 = 4;
            int planet2 = 12;
            Index2 index1 = new Index2(5, 6);
            Index2 index2 = new Index2(15, 16);
            IChunkColumn result1 = null;
            IChunkColumn result2 = null;
            int loadCallCounter = 0;
            int saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
                {
                    loadCallCounter++;
                    if (p == planet1)
                    {
                        Assert.AreEqual(i, index1);
                        return result1 = new TestChunkColumn(p, index1);
                    }
                    else if (p == planet2)
                    {
                        Assert.AreEqual(i, index2);
                        return result2 = new TestChunkColumn(p, index2);
                    }

                    throw new NotSupportedException();
                },
                (p, i, c) =>
                {
                    saveCallCounter++;
                    if (p == planet1)
                    {
                        Assert.AreEqual(i, index1);
                        Assert.AreEqual(c, result1);
                        return;
                    }
                    else if (p == planet2)
                    {
                        Assert.AreEqual(i, index2);
                        Assert.AreEqual(c, result2);
                        return;
                    }

                    throw new NotSupportedException();
                });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunkColumn x1 = cache.Subscribe(planet1, index1);
            Assert.AreEqual(x1, result1);
            Assert.AreEqual(x1.Planet, planet1);
            Assert.AreEqual(x1.Index, index1);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunkColumn x2 = cache.Subscribe(planet2, index2);
            Assert.AreEqual(x2, result2);
            Assert.AreEqual(x2.Planet, planet2);
            Assert.AreEqual(x2.Index, index2);

            Assert.AreEqual(2, cache.LoadedChunkColumns);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(planet1, index1);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);

            // Unload 2
            cache.Release(planet2, index2);

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(2, saveCallCounter);
        }
Пример #13
0
        public void LoadMultipleChunksTest()
        {
            int          planet1         = 4;
            int          planet2         = 12;
            Index2       index1          = new Index2(5, 6);
            Index2       index2          = new Index2(15, 16);
            IChunkColumn result1         = null;
            IChunkColumn result2         = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
            {
                loadCallCounter++;
                if (p == planet1)
                {
                    Assert.AreEqual(i, index1);
                    return(result1 = new TestChunkColumn(p, index1));
                }
                else if (p == planet2)
                {
                    Assert.AreEqual(i, index2);
                    return(result2 = new TestChunkColumn(p, index2));
                }

                throw new NotSupportedException();
            },
                (p, i, c) =>
            {
                saveCallCounter++;
                if (p == planet1)
                {
                    Assert.AreEqual(i, index1);
                    Assert.AreEqual(c, result1);
                    return;
                }
                else if (p == planet2)
                {
                    Assert.AreEqual(i, index2);
                    Assert.AreEqual(c, result2);
                    return;
                }

                throw new NotSupportedException();
            });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunkColumn x1 = cache.Subscribe(planet1, index1);

            Assert.AreEqual(x1, result1);
            Assert.AreEqual(x1.Planet, planet1);
            Assert.AreEqual(x1.Index, index1);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunkColumn x2 = cache.Subscribe(planet2, index2);

            Assert.AreEqual(x2, result2);
            Assert.AreEqual(x2.Planet, planet2);
            Assert.AreEqual(x2.Index, index2);

            Assert.AreEqual(2, cache.LoadedChunkColumns);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(planet1, index1);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);

            // Unload 2
            cache.Release(planet2, index2);

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(2, loadCallCounter);
            Assert.AreEqual(2, saveCallCounter);
        }
Пример #14
0
        public void LoadChunkWithMultipleReferencesTest()
        {
            int          planet          = 4;
            Index2       index           = new Index2(5, 6);
            IChunkColumn result          = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
            {
                loadCallCounter++;
                Assert.AreEqual(i, index);
                return(result = new TestChunkColumn(planet, index));
            },
                (p, i, c) =>
            {
                saveCallCounter++;
                Assert.AreEqual(i, index);
                Assert.AreEqual(c, result);
            });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunkColumn x1 = cache.Subscribe(planet, index);

            Assert.AreEqual(x1, result);
            Assert.AreEqual(x1.Planet, planet);
            Assert.AreEqual(x1.Index, index);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunkColumn x2 = cache.Subscribe(planet, index);

            Assert.AreEqual(x2, result);
            Assert.AreEqual(x2.Planet, planet);
            Assert.AreEqual(x2.Index, index);
            Assert.AreEqual(x1, x2);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(planet, index);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 2
            cache.Release(planet, index);

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #15
0
        public void LoadMultipleChunksTest()
        {
            int          planet1         = 4;
            int          planet2         = 12;
            Index2       index1          = new Index2(5, 6);
            Index2       index2          = new Index2(15, 16);
            IChunkColumn result1         = null;
            IChunkColumn result2         = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
            {
                loadCallCounter++;
                if (p == planet1)
                {
                    Assert.Equals(i, index1);
                    return(result1 = new TestChunkColumn(p, index1));
                }
                else if (p == planet2)
                {
                    Assert.Equals(i, index2);
                    return(result2 = new TestChunkColumn(p, index2));
                }

                throw new NotSupportedException();
            },
                (i) => null,
                (p, i, c) =>
            {
                saveCallCounter++;
                if (p == planet1)
                {
                    Assert.Equals(i, index1);
                    Assert.Equals(c, result1);
                    return;
                }
                else if (p == planet2)
                {
                    Assert.Equals(i, index2);
                    Assert.Equals(c, result2);
                    return;
                }

                throw new NotSupportedException();
            });

            // Load 1
            Assert.Equals(0, cache.LoadedChunkColumns);
            Assert.Equals(0, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            IChunkColumn x1 = cache.Subscribe(planet1, index1, false);

            Assert.Equals(x1, result1);
            Assert.Equals(x1.Planet, planet1);
            Assert.Equals(x1.Index, index1);

            Assert.Equals(1, cache.LoadedChunkColumns);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            // Load 2
            IChunkColumn x2 = cache.Subscribe(planet2, index2, false);

            Assert.Equals(x2, result2);
            Assert.Equals(x2.Planet, planet2);
            Assert.Equals(x2.Index, index2);

            Assert.Equals(2, cache.LoadedChunkColumns);
            Assert.Equals(2, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            //Change Chunk so that they get saved
            result1.Chunks[0].SetBlock(Index3.Zero, 0, 0);


            // Unload 1
            cache.Release(planet1, index1, false);
            System.Threading.Thread.Sleep(150);//TODO: dirty fix wait till completly cleaned up
            Assert.Equals(1, cache.LoadedChunkColumns);
            Assert.Equals(2, loadCallCounter);
            Assert.Equals(1, saveCallCounter);

            result2.Chunks[0].SetBlock(Index3.Zero, 0, 0);
            // Unload 2
            cache.Release(planet2, index2, false);
            System.Threading.Thread.Sleep(150);//TODO: dirty fix wait till completly cleaned up
            Assert.Equals(0, cache.LoadedChunkColumns);
            Assert.Equals(2, loadCallCounter);
            Assert.Equals(2, saveCallCounter);
        }
Пример #16
0
        public void LoadChunkWithMultipleReferencesTest()
        {
            int planet = 4;
            Index2 index = new Index2(5, 6);
            IChunkColumn result = null;
            int loadCallCounter = 0;
            int saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
                {
                    loadCallCounter++;
                    Assert.AreEqual(i, index);
                    return result = new TestChunkColumn(planet, index);
                },
                (p, i, c) =>
                {
                    saveCallCounter++;
                    Assert.AreEqual(i, index);
                    Assert.AreEqual(c, result);
                });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunkColumn x1 = cache.Subscribe(planet, index);
            Assert.AreEqual(x1, result);
            Assert.AreEqual(x1.Planet, planet);
            Assert.AreEqual(x1.Index, index);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunkColumn x2 = cache.Subscribe(planet, index);
            Assert.AreEqual(x2, result);
            Assert.AreEqual(x2.Planet, planet);
            Assert.AreEqual(x2.Index, index);
            Assert.AreEqual(x1, x2);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(planet, index);

            Assert.AreEqual(1, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 2
            cache.Release(planet, index);

            Assert.AreEqual(0, cache.LoadedChunkColumns);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #17
0
        public void LoadChunkWithMultipleReferencesTest()
        {
            PlanetIndex3 index = new PlanetIndex3(4, new Index3(5, 6, 7));
            IChunk result = null;
            int loadCallCounter = 0;
            int saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (i) =>
                {
                    loadCallCounter++;
                    Assert.AreEqual(i, index);
                    return result = new TestChunk(index);
                },
                (i, c) =>
                {
                    saveCallCounter++;
                    Assert.AreEqual(i, index);
                    Assert.AreEqual(c, result);
                });

            // Load 1
            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(0, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            IChunk x1 = cache.Subscribe(index, true);
            Assert.AreEqual(x1, result);
            Assert.AreEqual(x1.Planet, index.Planet);
            Assert.AreEqual(x1.Index, index.ChunkIndex);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Load 2
            IChunk x2 = cache.Subscribe(index, true);
            Assert.AreEqual(x2, result);
            Assert.AreEqual(x2.Planet, index.Planet);
            Assert.AreEqual(x2.Index, index.ChunkIndex);
            Assert.AreEqual(x1, x2);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 1
            cache.Release(index, true);

            Assert.AreEqual(1, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(0, saveCallCounter);

            // Unload 2
            cache.Release(index, true);

            Assert.AreEqual(0, cache.LoadedChunks);
            Assert.AreEqual(1, loadCallCounter);
            Assert.AreEqual(1, saveCallCounter);
        }
Пример #18
0
        public void LoadChunkWithMultipleReferencesTest()
        {
            int          planet          = 4;
            Index2       index           = new Index2(5, 6);
            IChunkColumn result          = null;
            int          loadCallCounter = 0;
            int          saveCallCounter = 0;

            GlobalChunkCache cache = new GlobalChunkCache(
                (p, i) =>
            {
                loadCallCounter++;
                Assert.Equals(i, index);
                return(result = new TestChunkColumn(planet, index));
            },
                (i) => null,
                (p, i, c) =>
            {
                saveCallCounter++;
                Assert.Equals(i, index);
                Assert.Equals(c, result);
            });

            // Load 1
            Assert.Equals(0, cache.LoadedChunkColumns);
            Assert.Equals(0, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            IChunkColumn x1 = cache.Subscribe(planet, index, false);

            Assert.Equals(x1, result);
            Assert.Equals(x1.Planet, planet);
            Assert.Equals(x1.Index, index);

            Assert.Equals(1, cache.LoadedChunkColumns);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            // Load 2
            IChunkColumn x2 = cache.Subscribe(planet, index, false);

            Assert.Equals(x2, result);
            Assert.Equals(x2.Planet, planet);
            Assert.Equals(x2.Index, index);
            Assert.Equals(x1, x2);

            Assert.Equals(1, cache.LoadedChunkColumns);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(0, saveCallCounter);



            // Unload 1
            cache.Release(planet, index, false);
            System.Threading.Thread.Sleep(150);//TODO: dirty fix wait till completly cleaned up
            Assert.Equals(1, cache.LoadedChunkColumns);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(0, saveCallCounter);

            x2.Chunks[0].SetBlock(Index3.Zero, 0);
            // Unload 2
            cache.Release(planet, index, false);
            System.Threading.Thread.Sleep(150);//TODO: dirty fix wait till completly cleaned up
            Assert.Equals(0, cache.LoadedChunkColumns);
            Assert.Equals(1, loadCallCounter);
            Assert.Equals(1, saveCallCounter);
        }