Exemple #1
0
        public void Tessellate_WithAsset_ReturnsExpectedTriangulation(TestCaseData data)
        {
            var pset = data.Asset.Polygons;
            var pool = new TestPool();
            var tess = new Tess(pool);

            PolyConvert.ToTess(pset, tess);
            tess.Tessellate(data.Winding, ElementType.Polygons, data.ElementSize);

            var resourceName = Assembly.GetExecutingAssembly().GetName().Name + ".TestData." + data.Asset.Name + ".testdat";
            var testData     = ParseTestData(data.Winding, data.ElementSize, Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName));

            Assert.IsNotNull(testData);
            Assert.AreEqual(testData.ElementSize, data.ElementSize);

            var indices = new List <int>();

            for (int i = 0; i < tess.ElementCount; i++)
            {
                for (int j = 0; j < data.ElementSize; j++)
                {
                    int index = tess.Elements[i * data.ElementSize + j];
                    indices.Add(index);
                }
            }

            Assert.AreEqual(testData.Indices, indices.ToArray());
            pool.AssertCounts();
        }
        public void TestGetRelease_NonBucketSizes()
        {
            _pool = new TestPool(10, 10, MakeBucketSizeArray(2, 1, 4, 1, 6, 1));
            _stats.SetPool(_pool);

            _pool.Get(2);
            byte[] b1 = _pool.Get(7);
            _stats.Refresh();
            Assert.AreEqual(10, _stats.UsedBytes);
            Assert.AreEqual(2, _stats.UsedCount);
            _pool.Release(b1);
            _stats.Refresh();
            Assert.AreEqual(2, _stats.UsedBytes);
            Assert.AreEqual(1, _stats.UsedCount);
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(0, _stats.FreeCount);

            byte[] b2 = new byte[3];
            _pool.Release(b2);
            _stats.Refresh();
            Assert.AreEqual(2, _stats.UsedBytes);
            Assert.AreEqual(1, _stats.UsedCount);
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(0, _stats.FreeCount);
        }
Exemple #3
0
        public void Tesselate_WithSingleTriangle_ProducesSameTriangle()
        {
            string data            = "0,0,0\n0,1,0\n1,1,0";
            var    indices         = new List <int>();
            var    expectedIndices = new int[] { 0, 1, 2 };

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var pset = DataLoader.LoadDat(stream);
                var pool = new TestPool();
                var tess = new Tess(pool);

                PolyConvert.ToTess(pset, tess);
                tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);

                indices.Clear();
                for (int i = 0; i < tess.ElementCount; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        int index = tess.Elements[i * 3 + j];
                        indices.Add(index);
                    }
                }

                Assert.AreEqual(expectedIndices, indices.ToArray());
                pool.AssertCounts();
            }
        }
        public void TestRelease_BucketLengths()
        {
            _pool = new TestPool(int.MaxValue, int.MaxValue, MakeBucketSizeArray(2, 2));
            _stats.SetPool(_pool);

            byte[] b0 = _pool.Get(2);
            _pool.Get(2);
            _pool.Get(2);
            _stats.Refresh();
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(3, 0) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
            Assert.AreEqual(6, _stats.UsedBytes);
            Assert.AreEqual(3, _stats.UsedCount);
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(0, _stats.FreeCount);

            // Now release one of the buffers
            _pool.Release(b0);
            _stats.Refresh();
            testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(2, 0) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
            Assert.AreEqual(4, _stats.UsedBytes);
            Assert.AreEqual(2, _stats.UsedCount);
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(0, _stats.FreeCount);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            // 测试方法.
            TestPool.TestThreadPool();

            // 读取用户输入 (避免主线程结束).
            Console.ReadLine();
        }
Exemple #6
0
 byte[] INodeService.FetchDLL(string nodeName, string branchName)
 {
     using (FileStream fileStream = new FileStream(TestPool.GetCurrenTestingJob().TestFile, FileMode.Open))
     {
         byte[] buffer      = new byte[52428800];
         int    size        = fileStream.Read(buffer, 0, 52428800);
         byte[] bufferShort = buffer.Take(size).ToArray();
         return(bufferShort);
     }
 }
Exemple #7
0
        public void BufferWriter_Writing_text()
        {
            var pool   = new TestPool();
            var writer = new BufferWriter(ArrayPool <char> .Shared);

            writer.Write("text1".ToCharArray(), 0, "text1".Length);
            writer.Write("something".ToCharArray(), 2, 3);
            Assert.AreEqual(8, writer.Count);
            Assert.AreEqual("text1met", new string(writer.WrittenSegment.Array, writer.WrittenSegment.Offset, writer.WrittenSegment.Count));
            writer.Dispose();
        }
Exemple #8
0
        public ActionResult Edit(TestPoolModel testPool)
        {
            TestPool res = _modelSaver.CreateOrUpdate(testPool);

            if (res != null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.Message = "Невозможно обновить тестпул";
            return(View(testPool));
        }
        public void TestTrimToSize()
        {
            _pool = new TestPool(100, 100, MakeBucketSizeArray(2, 2, 4, 2, 6, 2));
            _stats.SetPool(_pool);

            // Allocate and release multiple buffers
            byte[] b1;
            _pool.Get(2);
            b1 = _pool.Get(2);
            _pool.Release(b1);
            b1 = _pool.Get(6);
            _pool.Release(b1);
            b1 = _pool.Get(4);
            _pool.Release(b1);

            _stats.Refresh();
            Assert.AreEqual(12, _stats.FreeBytes);
            Assert.AreEqual(2, _stats.UsedBytes);

            // Perform a dummy trim - nothing should happen
            _pool.TrimToSize(100);
            _stats.Refresh();
            Assert.AreEqual(12, _stats.FreeBytes);
            Assert.AreEqual(2, _stats.UsedBytes);

            // Now perform the real trim
            _pool.TrimToSize(8);
            _stats.Refresh();
            Assert.AreEqual(6, _stats.FreeBytes);
            Assert.AreEqual(2, _stats.UsedBytes);
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(1, 0) },
                { 4, new Tuple <int, int>(0, 0) },
                { 6, new Tuple <int, int>(0, 1) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));

            // Perform another trim
            _pool.TrimToSize(1);
            _stats.Refresh();
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(2, _stats.UsedBytes);
            testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(1, 0) },
                { 4, new Tuple <int, int>(0, 0) },
                { 6, new Tuple <int, int>(0, 0) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
        }
        public void Test_CanAllocate()
        {
            TestPool pool = new TestPool(4, 8);

            pool.Get(4);
            Assert.IsFalse(pool.IsMaxSizeSoftCapExceeded());
            Assert.IsTrue(pool.CanAllocate(2));
            pool.Get(2);
            Assert.IsTrue(pool.IsMaxSizeSoftCapExceeded());
            Assert.IsTrue(pool.CanAllocate(2));
            Assert.IsFalse(pool.CanAllocate(4));
        }
Exemple #11
0
        public ActionResult Create(TestPoolModel testPool)
        {
            TestPool res = _modelSaver.CreateOrUpdate(testPool);

            if (res != null)
            {
                return(RedirectToAction("Edit", new { id = res.Id }));
            }

            ViewBag.Message = "Невозможно сохранить тестпул";
            return(View(testPool));
        }
Exemple #12
0
        private static (ConfigurationClient service, TestPool <byte> pool) CreateTestService(MockHttpClientTransport transport)
        {
            HttpPipelineOptions options = ConfigurationClient.CreateDefaultPipelineOptions();
            var testPool = new TestPool <byte>();

            options.AddService(testPool, typeof(ArrayPool <byte>));

            options.Transport = transport;

            var service = new ConfigurationClient(connectionString, options);

            return(service, testPool);
        }
        private static (ConfigurationClient service, TestPool <byte> pool) CreateTestService(MockHttpClientTransport transport)
        {
            var options  = new PipelineOptions();
            var testPool = new TestPool <byte>();

            options.Pool = testPool;

            options.Transport = transport;
            options.Logger    = new MockLogger();

            var service = new ConfigurationClient(connectionString, options);

            return(service, testPool);
        }
Exemple #14
0
    // Start is called before the first frame update
    void Start()
    {
        DontDestroyOnLoad(gameObject);
        Log.SetLogOpen(_isOpenLog);

        //这里是为了避免懒加载获取其中的某些对象时出现“场景内GameObject过多”导致的查找消耗问题
        GlobalInstance.Init();
        FrameController.I.EnsureInit();
        ObjectPoolMgr.I.Init();

        TestPool pool = ObjectPoolMgr.I.CreateDefaultObjectPoolTest <TestPool>();

        pool.Do();
    }
        public void TestGet_AllocFailure()
        {
            TestPool pool = new TestPool(4, 5);

            pool.Get(4);
            try
            {
                pool.Get(4);
                Assert.Fail();
            }
            catch (PoolSizeViolationException)
            {
                // This is expected
            }
        }
        private static (FileUri service, TestPool <byte> pool) CreateTestService(MockHttpClientTransport transport)
        {
            var options = new PipelineOptions();
            var pool    = new TestPool <byte>();

            if (transport.Responses.Count == 0)
            {
                transport.Responses.Add(HttpStatusCode.GatewayTimeout);
                transport.Responses.Add(HttpStatusCode.OK);
            }
            options.Transport = transport;
            options.Pool      = pool;

            var service = new FileUri(baseUri, options);

            return(service, pool);
        }
Exemple #17
0
        public void BufferWriter_Pool_Handing()
        {
            var pool   = new TestPool();
            var writer = new BufferWriter(pool);

            Assert.AreEqual(0, writer.Count);

            writer.Write(new char[10], 0, 1);
            Assert.AreEqual(1, writer.Count);
            Assert.AreEqual(0, pool.currentBufferIndex);

            writer.Write(new char[10], 0, 2);
            Assert.AreEqual(3, writer.Count);
            Assert.AreEqual(1, pool.currentBufferIndex);

            writer.Dispose();
            //check if all buffers were returned
            Assert.True(Array.TrueForAll(pool.buffers, b => b == null));
        }
        public void TestRelease_Free2()
        {
            // Create a new pool with a max size cap of zero.
            _pool = new TestPool(0, 10);
            _stats.SetPool(_pool);

            // get a buffer and release it - this should trigger the soft cap
            byte[] b1 = _pool.Get(4);
            _pool.Release(b1);
            _stats.Refresh();
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 4, new Tuple <int, int>(0, 0) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(0, _stats.UsedBytes);
            Assert.AreEqual(0, _stats.FreeCount);
            Assert.AreEqual(0, _stats.UsedCount);
        }
        public void TestGet_AllocAndTrim()
        {
            _pool = new TestPool(10, 10, MakeBucketSizeArray(2, 2, 4, 2, 6, 2));
            _stats.SetPool(_pool);

            // Allocate and release multiple buffers
            byte[] b1 = _pool.Get(2);
            _pool.Release(b1);
            b1 = _pool.Get(6);
            _pool.Release(b1);

            // Get current stats
            _stats.Refresh();
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(0, 1) },
                { 4, new Tuple <int, int>(0, 0) },
                { 6, new Tuple <int, int>(0, 1) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));

            // Get a new buffer; this should cause an alloc and a trim
            _pool.Get(3);
            _stats.Refresh();

            // Validate stats
            testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(0, 0) },
                { 4, new Tuple <int, int>(1, 0) },
                { 6, new Tuple <int, int>(0, 1) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
            Assert.AreEqual(6, _stats.FreeBytes);
            Assert.AreEqual(4, _stats.UsedBytes);
            Assert.AreEqual(1, _stats.FreeCount);
            Assert.AreEqual(1, _stats.UsedCount);
        }
        public void TestRelease_NonReusable()
        {
            TestPool pool = new TestPool(100, 100, MakeBucketSizeArray(2, 3));

            _pool.Reusable = false;
            _stats.SetPool(pool);

            // Get a buffer, and then release it
            byte[] b1 = _pool.Get(2);
            _pool.Release(b1);

            // Verify stats
            _stats.Refresh();
            var testStat = new Dictionary <int, Tuple <int, int> >()
            {
                { 2, new Tuple <int, int>(0, 0) }
            };

            Assert.IsTrue(testStat.All(e => _stats.BucketStats.Contains(e)));
            Assert.AreEqual(0, _stats.FreeBytes);
            Assert.AreEqual(0, _stats.UsedBytes);
            Assert.AreEqual(0, _stats.FreeCount);
            Assert.AreEqual(0, _stats.UsedCount);
        }
 public void Initialize()
 {
     _pool  = new TestPool(10, 14);
     _stats = new PoolStats <byte[]>(_pool);
 }
Exemple #22
0
 void INodeService.FinishedWork(string nodeName, TestResult testResult)
 {
     TestPool.FinishedWorkItem(nodeName, testResult);
 }
Exemple #23
0
        Guid ISlimServerService.AddTestJob(string testsystemName, byte[] data)
        {
            var    jobGuid  = Guid.NewGuid();
            string testFile = RegtestingServerConfiguration.Testsfolder + jobGuid + ".dll";;

            Directory.CreateDirectory(Path.GetDirectoryName(testFile));
            using (FileStream fileStream = new FileStream(testFile, FileMode.Create, FileAccess.Write))
            {
                fileStream.Write(data, 0, data.Length);
            }
            TestcaseProvider testcaseProvider = new TestcaseProvider(testFile);

            testcaseProvider.CreateAppDomain();


            List <WorkItem> items = new List <WorkItem>();

            foreach (string testcaseType in testcaseProvider.Types)
            {
                ITestable testable = testcaseProvider.GetTestableFromTypeName(testcaseType);
                if (testable == null)
                {
                    continue;
                }
                WorkItem workItem = new WorkItem
                {
                    Browser = new BrowserDto
                    {
                        Browserstring = "phantomjs",
                        Name          = "phantomjs"
                    },
                    Language = new LanguageDto
                    {
                        Name         = "Deutsch",
                        Languagecode = "DE"
                    },
                    Testcase = new TestcaseDto
                    {
                        Name = testable.GetName(),
                        Type = testcaseType
                    },
                    Testsystem = new TestsystemDto
                    {
                        Filename = jobGuid + ".dll",
                        Name     = testsystemName,
                        Url      = testsystemName
                    }
                };
                items.Add(workItem);
            }
            testcaseProvider.Unload();

            TestingJob testingJob = new TestingJob
            {
                Guid              = jobGuid,
                ResultCode        = TestState.Pending,
                WaitingWorkItems  = items,
                TestFile          = testFile,
                CurrentWorkItems  = new Dictionary <string, WorkItemTask>(),
                FinishedWorkItems = new List <WorkItem>(),
                ResultGenerator   = new ResultGenerator()
            };

            TestPool.AddTestingJob(testingJob);
            Console.WriteLine("Added Job " + jobGuid + "(" + testcaseProvider.Types.Count() + " tests) to Testpool.");
            return(jobGuid);
        }
Exemple #24
0
 bool ISlimServerService.IsTestJobFinished(Guid testJobId)
 {
     return(TestPool.GetStatus(testJobId));
 }
Exemple #25
0
 string ISlimServerService.GetResultFile(Guid testJobId)
 {
     return(TestPool.GetResultFile(testJobId));
 }
Exemple #26
0
        WorkItem INodeService.GetWork(string nodeName)
        {
            WorkItem workItem = TestPool.GetWork(nodeName);

            return(workItem);
        }