public void ObjectPool_Constructor_NullFunction_ShouldThrowException() { //--------------Arrange------------------------------ //--------------Act---------------------------------- var result = new ObjectPoolFactory <TestClass>().New(null, null); //--------------Assert------------------------------- }
public CourierClientFactoryImpl(GuidProxy guidProxy, IThreadingProxy threadingProxy, INetworkingProxy networkingProxy, ObjectPoolFactory objectPoolFactory, IPofSerializer pofSerializer) { this.guidProxy = guidProxy; this.threadingProxy = threadingProxy; this.networkingProxy = networkingProxy; this.objectPoolFactory = objectPoolFactory; this.pofSerializer = pofSerializer; }
public void ObjectPool_AcquireReleaseObject_CheckWithParallelObjectCreation_ShouldReturnObject() { //--------------Arrange------------------------------ TestClass expectedResult = new TestClass(); var objectPool = new ObjectPoolFactory <TestClass>().New(() => expectedResult, (instance) => false); Parallel.For(0, 1000, (i, loopState) => { //--------------Act---------------------------------- TestClass actualResult = objectPool.AcquireObject(); //--------------Assert------------------------------- Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(expectedResult.GetValue(i), actualResult.GetValue(i)); objectPool.ReleaseObject(actualResult); }); }
//IEnumerator LoadAsyncScene() //{ // AsyncOperation asyncload = SceneManager.LoadSceneAsync("desert", LoadSceneMode.Additive); // while (!asyncload.isDone) // { // yield return new WaitForEndOfFrame(); // } //} //private void onLoadingComplete(Scene scene, LoadSceneMode mode) //{ // Debug.Log("OnSceneLoaded: " + scene.name); // Debug.Log(mode); // SceneManager.sceneLoaded -= onLoadingComplete; // //AppFacade.Instance.SendNotification(LoadingNotify.Open, true); //} public void InitObjectPools(SimpleJSON.JSONArray ids, string types) { if (ids == null || ids.Count == 0) { return; } var of = new ObjectPoolFactory(); for (int i = 0; i < ids.Count; i++) { SimpleJSON.JSONNode p = ids[i]; int kindId = p.AsInt; string poolname = Utils.getPoolName(kindId, types); var pool = App.Inst.getObjectPoolManage().getPool(poolname); if (pool == null) { of.createPools(kindId, types); } } }
public void ObjectPool_Dispose_ShouldClearObjectList() { //--------------Arrange------------------------------ TestClass expectedResult = new TestClass(); var objectPool = new ObjectPoolFactory <TestClass>().New(() => expectedResult, (instance) => false); Parallel.For(0, 1000, (i, loopState) => { TestClass actualResult = objectPool.AcquireObject(); Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(expectedResult.GetValue(i), actualResult.GetValue(i)); objectPool.ReleaseObject(actualResult); }); //--------------Act---------------------------------- objectPool.Dispose(); //--------------Assert------------------------------- }
private void OnEnable() { PoolFactory = (ObjectPoolFactory)target; }
internal ObjectPool(ObjectPoolFactory factory) : this(20, factory) { }
internal ObjectPool(int size, ObjectPoolFactory factory) { _factory = factory; _queue = new Queue <T>(size); }
void Awake() { factory = this; }