private CachedArray InitCachedIArray(string arrayName, int elementSize, int userHeaderSize, int cacheSize) { CachedArray cache; try { cache = new CachedArray(arrayName, elementSize, userHeaderSize, cacheSize); } catch (FileNameConflictException) { cache = new CachedArray(arrayName); cache.Delete(); cache = new CachedArray(arrayName, elementSize, userHeaderSize, cacheSize); } return cache; }
private static void GetPutUserHeaderSizeTestAssert(byte[] uHeader, CachedArray cache) { cache.PutUserHeader(uHeader); byte[] actual = cache.GetUserHeader(); TestHelper.AssertByteArraysAreSame(uHeader, actual); }
private static void PutGetTestAssert(byte[] bytes, int elementIdx, CachedArray cache) { cache.Put(elementIdx, bytes); byte[] actual = cache.Get(elementIdx); TestHelper.AssertByteArraysAreSame(bytes, actual); }
public void ReopenTest() { string arrayName = "ReopenCachedArrayTest"; const int elementSize = 10; const int userHeaderSize = 4; const int cacheSize = 15; CachedArray cache = InitCachedIArray(arrayName, elementSize, userHeaderSize, cacheSize); try { int index1 = 4; byte[] bytes1 = new byte[]{1,2,3,4,5,6,7,8,9,0}; cache.Put(index1, bytes1); int index2 = 5; byte[] bytes2 = new byte[] { 255,254,253,252,251,250,249,248,247,246 }; cache.Put(index2, bytes2); cache.Close(); cache = new CachedArray(arrayName); Assert.AreEqual(elementSize, cache.GetElementSize()); Assert.AreEqual(userHeaderSize, cache.GetUserHeaderSize()); Assert.AreEqual(cacheSize, cache.GetCacheSize()); TestHelper.AssertByteArraysAreSame(bytes1, cache.Get(index1)); TestHelper.AssertByteArraysAreSame(bytes2, cache.Get(index2)); } finally { cache.Close(); } }