/// <summary> /// 测试对象池对具体类型的容量 /// </summary> public void TestCapacity() { PoolListener <AdvancedCalculator> listener = new PoolListener <AdvancedCalculator>(); AdvancedCalculator obj1 = listener.Acquire(); obj1.Activate(); //Assert.IsNotNull(obj1); AdvancedCalculator obj2 = listener.Acquire(); obj2.Activate(); //Assert.IsNotNull(obj2); AdvancedCalculator obj3 = listener.Acquire(); // 满了,无法继续申请 //Assert.IsNull(obj3); }
/// <summary> /// 测试对象池的重用机制 /// </summary> public void TestResue() { PoolListener <AdvancedCalculator> listener = new PoolListener <AdvancedCalculator>(); AdvancedCalculator obj1 = listener.Acquire(); obj1.Activate(); AdvancedCalculator obj2 = listener.Acquire(); obj2.Activate(); obj1.Deactivate(); AdvancedCalculator obj3 = listener.Acquire(); obj3.Activate(); //Assert.IsNotNull(obj3); //Assert.AreEqual<string>(obj1.Guid, obj3.Guid); //Assert.AreEqual<int>(obj3.Multiple(2, 2), 2 * 2); }