예제 #1
0
        private static void RecursiveAcquirePoolItems(int poolItemCount, NLog.Internal.StringBuilderPool pool, string payload, bool mustGrow)
        {
            if (poolItemCount <= 0)
            {
                return;
            }

            using (var itemHolder = pool.Acquire())
            {
                Assert.Equal(0, itemHolder.Item.Length);
                Assert.True(payload.Length > itemHolder.Item.Capacity == mustGrow);
                itemHolder.Item.Append(payload);
                RecursiveAcquirePoolItems(poolItemCount - 1, pool, payload, mustGrow);
            }
        }
예제 #2
0
        public void StringBuilderPoolMaxCapacityTest()
        {
            int poolItemCount = 10;

            NLog.Internal.StringBuilderPool pool = new NLog.Internal.StringBuilderPool(poolItemCount);
            string mediumPayload = new string('A', 300000);

            RecursiveAcquirePoolItems(poolItemCount, pool, mediumPayload, true);        // Verify fast-pool + slow-pool must grow
            RecursiveAcquirePoolItems(poolItemCount, pool, mediumPayload, false);       // Verify fast-pool + slow-pool has kept their capacity

            string largePayload = new string('A', 1000000);

            RecursiveAcquirePoolItems(poolItemCount, pool, largePayload, true);
            using (var itemHolder = pool.Acquire())
            {
                Assert.Equal(0, itemHolder.Item.Length);
                Assert.True(largePayload.Length <= itemHolder.Item.Capacity);           // Verify fast-pool has kept its capacity
                RecursiveAcquirePoolItems(poolItemCount, pool, mediumPayload, true);    // Verify slow-pool must grow
            }
        }