Package peer

Source Code of peer.MinimizeStorageStrategyTest

package peer;

import java.util.Iterator;

import util.Log;

import junit.framework.TestCase;

public class MinimizeStorageStrategyTest extends TestCase {

  PeerHash myMap = new PeerHash();
  Peer peer1;
  Peer peer2;
  Peer peer3;
  Peer peer4;
  MinimizeStorageStrategy minStrategy;
 
  protected void setUp() throws Exception {
    super.setUp();
    peer1 = new Peer("peer1",0,0);
    peer2 = new Peer("peer2",0,15);
    peer3 = new Peer("peer3",0,7);
    peer4 = new Peer("peer4",0,37);
    myMap.set(peer1);
    myMap.set(peer2);
    myMap.set(peer3);
    myMap.set(peer4);
    minStrategy = new MinimizeStorageStrategy();
  }
 
  public void testGetNearestPeers() {
    PeerHash nearestPeers = minStrategy.getNearestPeers(myMap, new Log());
    assertTrue(nearestPeers.getHashtable().size() == 2);
    assertTrue(nearestPeers.getHashtable().containsKey("peer1"));
    assertTrue(nearestPeers.getHashtable().containsKey("peer3"));
    assertFalse(nearestPeers.getHashtable().containsKey("peer2"));
   
  }
 
  public void testTwoValuesTheSame() {
    myMap.get("peer1").setNumberOfFiles(5);
    myMap.get("peer2").setNumberOfFiles(3);
    myMap.get("peer3").setNumberOfFiles(3);
    PeerHash nearestPeers = minStrategy.getNearestPeers(myMap, new Log());
    assertTrue(nearestPeers.getHashtable().size() == 2);
    assertTrue(nearestPeers.getHashtable().containsKey("peer2"));
    assertTrue(nearestPeers.getHashtable().containsKey("peer3"));
    assertFalse(nearestPeers.getHashtable().containsKey("peer1"));
  }

  public void testThreeValuesTheSame() {
    myMap.get("peer1").setNumberOfFiles(3);
    myMap.get("peer2").setNumberOfFiles(3);
    myMap.get("peer3").setNumberOfFiles(3);
   
    PeerHash nearestPeers = minStrategy.getNearestPeers(myMap, new Log());
    assertTrue(nearestPeers.getHashtable().size() == 2);
    assertFalse(nearestPeers.getHashtable().containsKey("peer4"));
    Iterator it = nearestPeers.getHashtable().keySet().iterator();
    while(it.hasNext()) {
      String key = (String) it.next();
      System.out.println("Key in map : " + key);
      assertTrue(nearestPeers.get(key).getNumberOfFiles() == 3);
    }
  }
 
}
TOP

Related Classes of peer.MinimizeStorageStrategyTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.