KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > slaveselection > filter > MintimeonlineFilterTest


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.drftpd.slaveselection.filter;
19
20 import java.util.Arrays JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import net.sf.drftpd.NoAvailableSlaveException;
26 import net.sf.drftpd.master.RemoteSlave;
27 import net.sf.drftpd.slave.Transfer;
28 import net.sf.drftpd.util.Time;
29
30 import org.apache.log4j.BasicConfigurator;
31
32 /**
33  * @author mog
34  * @version $Id: MintimeonlineFilterTest.java,v 1.2 2004/03/01 00:21:10 mog Exp $
35  */

36 public class MintimeonlineFilterTest extends TestCase {
37
38     public MintimeonlineFilterTest(String JavaDoc name) {
39         super(name);
40     }
41
42     public static TestSuite suite() {
43         return new TestSuite(MintimeonlineFilterTest.class);
44     }
45
46     public static class RS extends RemoteSlave {
47
48         public RS(String JavaDoc name) {
49             super(name, null);
50         }
51
52         public long getLastTransferForDirection(char dir) {
53             return System.currentTimeMillis() - Time.parseTime("1m");
54         }
55     }
56     public void setUp() {
57         BasicConfigurator.configure();
58     }
59     public void testSimple() throws NoAvailableSlaveException {
60         Properties JavaDoc p = new Properties JavaDoc();
61         p.put("1.multiplier", "1");
62         p.put("1.mintime", "2m");
63
64         RemoteSlave rslaves[] = { new RS("slave1")};
65         ScoreChart sc = new ScoreChart(Arrays.asList(rslaves));
66         Filter f = new MintimeonlineFilter(null, 1, p);
67         f.process(sc, null, null, Transfer.TRANSFER_UNKNOWN, null);
68         assertEquals(-Time.parseTime("1m"), sc.getBestSlaveScore().getScore());
69     }
70 }
71
Popular Tags