Beispiel #1
0
        public async Task CreateConnectionStringBasedPool()
        {
            PoolFactory.InitializeNamedPool <TestPoolWithConnectionString>(2, null);
            var item1 = PoolFactory.Create <TestPoolWithConnectionString>("http://test1.com/mongo");
            var item2 = PoolFactory.Create <TestPoolWithConnectionString>("http://test2.com/mongo");
            var item3 = PoolFactory.Create <TestPoolWithConnectionString>("http://test1.com/mongo");
            var item4 = PoolFactory.Create <TestPoolWithConnectionString>("http://test2.com/mongo");

            Assert.AreNotEqual(item1, item2);
            Assert.AreNotEqual(item3, item4);
            Assert.AreNotEqual(item1, item3);
            Assert.AreNotEqual(item2, item3);
            Assert.AreNotEqual(item1, item4);
            try
            {
                var item = PoolFactory.Create <TestPoolWithConnectionString>("http://test1.com/mongo");
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(Exception));
            }

            var itemTask = Task.Run(() => PoolFactory.CreateAsync <TestPoolWithConnectionString>("http://test1.com/mongo"));

            item1.Dispose();
            await Task.Delay(1);

            var item5 = await itemTask.ConfigureAwait(false);

            item2.Dispose();
            item3.Dispose();
            item4.Dispose();
            item5.Dispose();
            try
            {
                PoolFactory.DisposeNamedPool <TestPoolWithConnectionString>();
            }
            catch
            { }
        }
Beispiel #2
0
        public IPooledServiceContainer <TService> CreatePooledServiceProxy <TService>(IRuntime runtime, string serviceName) where TService : class
        {
            var attrib         = typeof(TService).GetAttribute <ServiceNameAttribute>();
            var serviceRootUrl = attrib.IsInstance()
                ? runtime.Context.GetEnvironmentConfiguration().GetConfigParameter(attrib.UrlRootName)
                : null;
            var address = runtime.Context.GetEndpointConfiguration(serviceName).GetRemoteAddress(serviceRootUrl);

            if (!PoolStatus.ContainsKey(address))
            {
                lock (PoolStatus)
                {
                    if (!PoolStatus.ContainsKey(address))
                    {
                        PoolFactory.InitializeNamedPool <PooledServiceContainer <TService> >(GetInstanceCount(runtime.Context), (i) => InitializePoolItem <TService>(i, serviceName, serviceRootUrl, runtime.Context));
                        PoolStatus.Add(address, true);
                    }
                }
            }
            return(PoolFactory.Create <PooledServiceContainer <TService> >(address));
        }