Example #1
0
        /// <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();
        }
Example #2
0
        /// <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();
        }