public void TestLoop()
        {
            ConnectionPool pool = new ConnectionPool();

            pool.Logger = new ConsoleLogger();

            pool.Parameters.Add(ConnectionPool.AdapterTypeParam, "OneCService2.V81Adapter");
            pool.Parameters.Add(ConnectionPool.NameParam, "TestName");
            pool.Parameters.Add(ConnectionPool.PoolSizeParam, "1");
            pool.Parameters.Add(ConnectionPool.PoolUserNameParam, "PoolUserName");
            pool.Parameters.Add(ConnectionPool.PoolPasswordParam, "PoolPassword");

            pool.Parameters.Add(V81Adapter.ModeParam, "File");
            pool.Parameters.Add(V81Adapter.FileParam, @"C:\Work\1C\Test");
            pool.Parameters.Add(V81Adapter.UserNameParam, "");
            pool.Parameters.Add(V81Adapter.PasswordParam, "");

            try
            {
                pool.Init();

                int loopCount = 1000000;

                for (int i = 0; i < loopCount; i++)
                {
                    AbstractAdapter adapter = pool.GetConnection("PoolUserName", "PoolPassword");

                    try
                    {
                        ResultSet r = adapter.ExecuteScript(
                            "с = Новый Структура(); с.Вставить(\"A\", Справочники.Номенклатура.НайтиПоКоду(1)); с.Вставить(\"B\", 2); результат=с;"
                            );
                        Console.WriteLine("Loop: " + i);
                        Thread.Sleep(50);
                    }
                    finally
                    {
                        pool.ReleaseConnection(adapter);
                    }
                }
            }
            finally
            {
                pool.Done();
            }
        }
Beispiel #2
0
        public void TestGetAndReleaseConnections()
        {
            ConnectionPool pool = new ConnectionPool();

            pool.Logger = new ConsoleLogger();

            pool.Parameters.Add(ConnectionPool.AdapterTypeParam, "OneCService2.V81Adapter");
            pool.Parameters.Add(ConnectionPool.NameParam, "TestName");
            pool.Parameters.Add(ConnectionPool.PoolSizeParam, "3");
            pool.Parameters.Add(ConnectionPool.PoolUserNameParam, "PoolUserName");
            pool.Parameters.Add(ConnectionPool.PoolPasswordParam, "PoolPassword");

            pool.Parameters.Add(V81Adapter.ModeParam, "File");
            pool.Parameters.Add(V81Adapter.FileParam, @"C:\Work\1C\Test");
            pool.Parameters.Add(V81Adapter.UserNameParam, "");
            pool.Parameters.Add(V81Adapter.PasswordParam, "");

            try
            {
                pool.Init();

                /*Неправильная аутентификация*/
                try
                {
                    AbstractAdapter adapter = pool.GetConnection("AAA", "BBB");
                    Assert.IsTrue(false);
                }
                catch (Exception _e)
                {
                    Console.WriteLine(_e.ToString());
                }

                AbstractAdapter adapter1 = pool.GetConnection("PoolUserName", "PoolPassword");
                AbstractAdapter adapter2 = pool.GetConnection("PoolUserName", "PoolPassword");
                AbstractAdapter adapter3 = pool.GetConnection("PoolUserName", "PoolPassword");

                try
                {
                    /*Должно отвалится по таймауту*/
                    pool.GetConnection("PoolUserName", "PoolPassword");
                    Assert.IsTrue(false);
                }
                catch (Exception _e)
                {
                    Console.WriteLine(_e.ToString());
                }

                pool.ReleaseConnection(adapter1);
                pool.ReleaseConnection(adapter2);
                pool.ReleaseConnection(adapter3);

                /*Берем и не отдаем назад соединение - должно все равно закрыться*/
                adapter1 = pool.GetConnection("PoolUserName", "PoolPassword");

                Assert.IsTrue(true);
            }
            finally
            {
                pool.Done();
            }

            Assert.IsTrue(true);
        }