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: import junit.framework.TestSuite;
22:
23: import net.sf.drftpd.NoAvailableSlaveException;
24: import net.sf.drftpd.ObjectNotFoundException;
25:
26: import org.drftpd.Bytes;
27: import org.drftpd.master.RemoteSlave;
28: import org.drftpd.master.RemoteTransfer;
29:
30: import org.drftpd.slave.DiskStatus;
31: import org.drftpd.slave.SlaveStatus;
32: import org.drftpd.slave.Transfer;
33: import org.drftpd.tests.DummyRemoteSlave;
34:
35: import java.util.Arrays;
36: import java.util.Collection;
37: import java.util.Collections;
38: import java.util.Properties;
39:
40: /**
41: * @author mog
42: * @version $Id: MinfreespaceFilterTest.java 823 2004-11-29 01:36:22Z mog $
43: */
44: public class MinfreespaceFilterTest extends TestCase {
45: public MinfreespaceFilterTest(String fName) {
46: super (fName);
47: }
48:
49: public static TestSuite suite() {
50: return new TestSuite(MinfreespaceFilterTest.class);
51: }
52:
53: public void testSimple() throws ObjectNotFoundException,
54: NoAvailableSlaveException {
55: Properties p = new Properties();
56: p.put("1.multiplier", "1");
57: p.put("1.minfreespace", "100MB");
58:
59: SlaveStatus s = new SlaveStatus(new DiskStatus(Bytes
60: .parseBytes("50MB"), Bytes.parseBytes("100GB")), 0, 0,
61: 0, 0, 0, 0);
62: RemoteSlave[] rslaves = { new RemoteSlaveTesting("slave1",
63: Collections.EMPTY_LIST, s) };
64: ScoreChart sc = new ScoreChart(Arrays.asList(rslaves));
65:
66: Filter f = new MinfreespaceFilter(null, 1, p);
67: f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD,
68: null, null);
69:
70: assertEquals(Bytes.parseBytes("-50MB"), sc.getSlaveScore(
71: rslaves[0]).getScore());
72: }
73:
74: public static class RemoteSlaveTesting extends DummyRemoteSlave {
75: private SlaveStatus _status;
76:
77: public RemoteSlaveTesting(String name, Collection masks,
78: SlaveStatus status) {
79: super (name, null);
80: _status = status;
81: }
82:
83: public SlaveStatus getSlaveStatusAvailable() {
84: return _status;
85: }
86: }
87: }
|