Ejemplo n.º 1
0
        public virtual void TestMultiplePeersWithSameKey()
        {
            int        Capacity = 3;
            PeerCache  cache    = new PeerCache(Capacity, 100000);
            DatanodeID dnId     = new DatanodeID("192.168.0.1", "fakehostname", "fake_datanode_id"
                                                 , 100, 101, 102, 103);
            HashMultiset <TestPeerCache.FakePeer> peers = HashMultiset.Create(Capacity);

            for (int i = 0; i < Capacity; ++i)
            {
                TestPeerCache.FakePeer peer = new TestPeerCache.FakePeer(dnId, false);
                peers.AddItem(peer);
                cache.Put(dnId, peer);
            }
            // Check that all of the peers ended up in the cache
            NUnit.Framework.Assert.AreEqual(Capacity, cache.Size());
            while (!peers.IsEmpty())
            {
                Peer peer = cache.Get(dnId, false);
                NUnit.Framework.Assert.IsTrue(peer != null);
                NUnit.Framework.Assert.IsTrue(!peer.IsClosed());
                peers.Remove(peer);
            }
            NUnit.Framework.Assert.AreEqual(0, cache.Size());
            cache.Close();
        }
Ejemplo n.º 2
0
        public virtual void TestDomainSocketPeers()
        {
            int        Capacity = 3;
            PeerCache  cache    = new PeerCache(Capacity, 100000);
            DatanodeID dnId     = new DatanodeID("192.168.0.1", "fakehostname", "fake_datanode_id"
                                                 , 100, 101, 102, 103);
            HashMultiset <TestPeerCache.FakePeer> peers = HashMultiset.Create(Capacity);

            for (int i = 0; i < Capacity; ++i)
            {
                TestPeerCache.FakePeer peer = new TestPeerCache.FakePeer(dnId, i == Capacity - 1);
                peers.AddItem(peer);
                cache.Put(dnId, peer);
            }
            // Check that all of the peers ended up in the cache
            NUnit.Framework.Assert.AreEqual(Capacity, cache.Size());
            // Test that get(requireDomainPeer=true) finds the peer with the
            // domain socket.
            Peer peer_1 = cache.Get(dnId, true);

            NUnit.Framework.Assert.IsTrue(peer_1.GetDomainSocket() != null);
            peers.Remove(peer_1);
            // Test that get(requireDomainPeer=true) returns null when there are
            // no more peers with domain sockets.
            peer_1 = cache.Get(dnId, true);
            NUnit.Framework.Assert.IsTrue(peer_1 == null);
            // Check that all of the other peers ended up in the cache.
            while (!peers.IsEmpty())
            {
                peer_1 = cache.Get(dnId, false);
                NUnit.Framework.Assert.IsTrue(peer_1 != null);
                NUnit.Framework.Assert.IsTrue(!peer_1.IsClosed());
                peers.Remove(peer_1);
            }
            NUnit.Framework.Assert.AreEqual(0, cache.Size());
            cache.Close();
        }