/// <exception cref="System.Exception"/> public virtual void TestExpiry() { ShortCircuitCache cache = new ShortCircuitCache(2, 1, 1, 10000000, 1, 10000000, 0 ); TestShortCircuitCache.TestFileDescriptorPair pair = new TestShortCircuitCache.TestFileDescriptorPair (); ShortCircuitReplicaInfo replicaInfo1 = cache.FetchOrCreate(new ExtendedBlockId(123 , "test_bp1"), new TestShortCircuitCache.SimpleReplicaCreator(123, cache, pair)); Preconditions.CheckNotNull(replicaInfo1.GetReplica()); Preconditions.CheckState(replicaInfo1.GetInvalidTokenException() == null); pair.CompareWith(replicaInfo1.GetReplica().GetDataStream(), replicaInfo1.GetReplica ().GetMetaStream()); replicaInfo1.GetReplica().Unref(); MutableBoolean triedToCreate = new MutableBoolean(false); do { Sharpen.Thread.Sleep(10); ShortCircuitReplicaInfo replicaInfo2 = cache.FetchOrCreate(new ExtendedBlockId(123 , "test_bp1"), new _ShortCircuitReplicaCreator_229(triedToCreate)); if ((replicaInfo2 != null) && (replicaInfo2.GetReplica() != null)) { replicaInfo2.GetReplica().Unref(); } }while (triedToCreate.IsFalse()); cache.Close(); }
public bool Get() { ShortCircuitReplicaInfo info = cache.FetchOrCreate(new ExtendedBlockId(0, "test_bp1" ), new _ShortCircuitReplicaCreator_355()); if (info.GetReplica() != null) { info.GetReplica().Unref(); return(false); } return(true); }
/// <exception cref="System.Exception"/> public virtual void TestAddAndRetrieve() { ShortCircuitCache cache = new ShortCircuitCache(10, 10000000, 10, 10000000, 1, 10000 , 0); TestShortCircuitCache.TestFileDescriptorPair pair = new TestShortCircuitCache.TestFileDescriptorPair (); ShortCircuitReplicaInfo replicaInfo1 = cache.FetchOrCreate(new ExtendedBlockId(123 , "test_bp1"), new TestShortCircuitCache.SimpleReplicaCreator(123, cache, pair)); Preconditions.CheckNotNull(replicaInfo1.GetReplica()); Preconditions.CheckState(replicaInfo1.GetInvalidTokenException() == null); pair.CompareWith(replicaInfo1.GetReplica().GetDataStream(), replicaInfo1.GetReplica ().GetMetaStream()); ShortCircuitReplicaInfo replicaInfo2 = cache.FetchOrCreate(new ExtendedBlockId(123 , "test_bp1"), new _ShortCircuitReplicaCreator_175()); Preconditions.CheckNotNull(replicaInfo2.GetReplica()); Preconditions.CheckState(replicaInfo2.GetInvalidTokenException() == null); Preconditions.CheckState(replicaInfo1 == replicaInfo2); pair.CompareWith(replicaInfo2.GetReplica().GetDataStream(), replicaInfo2.GetReplica ().GetMetaStream()); replicaInfo1.GetReplica().Unref(); replicaInfo2.GetReplica().Unref(); // Even after the reference count falls to 0, we still keep the replica // around for a while (we have configured the expiry period to be really, // really long here) ShortCircuitReplicaInfo replicaInfo3 = cache.FetchOrCreate(new ExtendedBlockId(123 , "test_bp1"), new _ShortCircuitReplicaCreator_195()); Preconditions.CheckNotNull(replicaInfo3.GetReplica()); Preconditions.CheckState(replicaInfo3.GetInvalidTokenException() == null); replicaInfo3.GetReplica().Unref(); pair.Close(); cache.Close(); }
/// <exception cref="System.Exception"/> public virtual void TestTimeBasedStaleness() { // Set up the cache with a short staleness time. ShortCircuitCache cache = new ShortCircuitCache(2, 10000000, 1, 10000000, 1, 10, 0); TestShortCircuitCache.TestFileDescriptorPair[] pairs = new TestShortCircuitCache.TestFileDescriptorPair [] { new TestShortCircuitCache.TestFileDescriptorPair(), new TestShortCircuitCache.TestFileDescriptorPair () }; ShortCircuitReplicaInfo[] replicaInfos = new ShortCircuitReplicaInfo[] { null, null }; long HourInMs = 60 * 60 * 1000; for (int i = 0; i < pairs.Length; i++) { int iVal = i; ExtendedBlockId key = new ExtendedBlockId(i, "test_bp1"); replicaInfos[i] = cache.FetchOrCreate(key, new _ShortCircuitReplicaCreator_330(key , pairs, iVal, cache, HourInMs)); Preconditions.CheckNotNull(replicaInfos[i].GetReplica()); Preconditions.CheckState(replicaInfos[i].GetInvalidTokenException() == null); pairs[i].CompareWith(replicaInfos[i].GetReplica().GetDataStream(), replicaInfos[i ].GetReplica().GetMetaStream()); } // Keep trying to getOrCreate block 0 until it goes stale (and we must re-create.) GenericTestUtils.WaitFor(new _Supplier_351(cache), 500, 60000); // Make sure that second replica did not go stale. ShortCircuitReplicaInfo info = cache.FetchOrCreate(new ExtendedBlockId(1, "test_bp1" ), new _ShortCircuitReplicaCreator_371()); info.GetReplica().Unref(); // Clean up for (int i_1 = 1; i_1 < pairs.Length; i_1++) { replicaInfos[i_1].GetReplica().Unref(); } cache.Close(); }