01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * 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 junit.framework.TestCase;
21:
22: import net.sf.drftpd.NoAvailableSlaveException;
23:
24: import org.apache.log4j.BasicConfigurator;
25:
26: import org.drftpd.Time;
27: import org.drftpd.master.RemoteSlave;
28: import org.drftpd.master.RemoteTransfer;
29:
30: import org.drftpd.slave.Transfer;
31: import org.drftpd.tests.DummyRemoteSlave;
32:
33: import java.util.Arrays;
34: import java.util.Properties;
35:
36: /**
37: * @author mog
38: * @version $Id: MintimeonlineFilterTest.java 936 2005-01-31 22:25:52Z mog $
39: */
40: public class MintimeonlineFilterTest extends TestCase {
41: public MintimeonlineFilterTest(String name) {
42: super (name);
43: }
44:
45: public void setUp() {
46: BasicConfigurator.configure();
47: }
48:
49: public void testSimple() throws NoAvailableSlaveException {
50: Properties p = new Properties();
51: p.put("1.multiplier", "1");
52: p.put("1.mintime", "2m");
53:
54: long time = System.currentTimeMillis();
55: RemoteSlave[] rslaves = { new RS("slave1", time) };
56: ScoreChart sc = new ScoreChart(Arrays.asList(rslaves));
57: MintimeonlineFilter f = new MintimeonlineFilter(null, 1, p);
58: f
59: .process(sc, null, null, Transfer.TRANSFER_UNKNOWN,
60: null, time);
61: assertEquals(-Time.parseTime("1m"), sc.getBestSlaveScore()
62: .getScore());
63: }
64:
65: public static class RS extends DummyRemoteSlave {
66: private long _time;
67:
68: public RS(String name, long time) {
69: super (name, null);
70: _time = time;
71: }
72:
73: public long getLastTransferForDirection(char dir) {
74: return _time - Time.parseTime("1m");
75: }
76: }
77: }
|