1 18 package org.drftpd.slaveselection.filter; 19 20 import java.rmi.RemoteException ; 21 import java.util.Arrays ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.HashSet ; 25 import java.util.Properties ; 26 import java.util.Set ; 27 28 import net.sf.drftpd.NoAvailableSlaveException; 29 import net.sf.drftpd.ObjectNotFoundException; 30 import net.sf.drftpd.SlaveUnavailableException; 31 import net.sf.drftpd.master.RemoteSlave; 32 import net.sf.drftpd.master.SlaveManagerImpl; 33 import net.sf.drftpd.slave.SlaveStatus; 34 import net.sf.drftpd.slave.Transfer; 35 36 import org.drftpd.remotefile.AbstractLinkedRemoteFile; 37 38 import junit.framework.TestCase; 39 40 44 public class MaxbandwidthFilterTest extends TestCase { 45 public static class LinkedRemoteFilePath extends AbstractLinkedRemoteFile { 46 private String _path; 47 public LinkedRemoteFilePath(String path) { 48 _path = path; 49 } 50 public String getPath() { 51 return _path; 52 } 53 public void deleteOthers(Set destSlaves) { 54 } 55 } 56 60 public MaxbandwidthFilterTest(String arg0) { 61 super(arg0); 62 } 63 64 public class FC extends FilterChain { 65 public SlaveManagerImpl getSlaveManager() { 66 try { 67 return new SM(); 68 } catch (RemoteException e) { 69 throw new RuntimeException (e); 70 } 71 } 72 } 73 74 public class SM extends SlaveManagerImpl { 75 public SM() throws RemoteException { 76 super(); 77 } 78 public RemoteSlave getSlave(String s) throws ObjectNotFoundException { 79 if(s == null) throw new RuntimeException (); 80 if(rslaves[0] == null) throw new RuntimeException (); 81 if (s.equals(rslaves[0].getName())) 82 return rslaves[0]; 83 if (s.equals(rslaves[1].getName())) 84 return rslaves[1]; 85 throw new ObjectNotFoundException(); 86 } 87 88 } 89 90 public class RS extends RemoteSlave { 91 public RS(String name,Collection duh) { 92 super(name,duh); 93 } 94 95 public synchronized SlaveStatus getStatus() 96 throws SlaveUnavailableException { 97 if (getName().equals("slave2")) 98 return new SlaveStatus(0,0,0,0,0,0,0,0); 99 return new SlaveStatus(0,0,0,0,9999999,1,9999999,1); 101 } 102 } 103 104 RemoteSlave rslaves[] = 105 { 106 new RS("slave1", Collections.EMPTY_LIST), 107 new RS("slave2", Collections.EMPTY_LIST)}; 108 109 public static void main(String [] args) { 110 junit.textui.TestRunner.run(MaxbandwidthFilterTest.class); 111 } 112 113 public void testSimple() throws ObjectNotFoundException, NoAvailableSlaveException { 114 Properties p = new Properties (); 115 p.put("1.maxbandwidth", "800kb"); 116 117 Filter f = new MaxbandwidthFilter(new FC(), 1, p); 118 ScoreChart sc = new ScoreChart(Arrays.asList(rslaves)); 119 120 f.process(sc, null, null,Transfer.TRANSFER_SENDING_DOWNLOAD, new LinkedRemoteFilePath("/")); 121 assertEquals(sc.getBestSlave(),rslaves[1]); 122 } 123 } 124 | Popular Tags |