001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.slaveselection.filter;
019:
020: import junit.framework.TestCase;
021:
022: import net.sf.drftpd.NoAvailableSlaveException;
023: import net.sf.drftpd.ObjectNotFoundException;
024:
025: import org.drftpd.master.RemoteSlave;
026: import org.drftpd.master.RemoteTransfer;
027: import org.drftpd.master.SlaveManager;
028: import org.drftpd.remotefile.AbstractLinkedRemoteFile;
029: import org.drftpd.remotefile.CaseInsensitiveHashtable;
030: import org.drftpd.remotefile.LinkedRemoteFileInterface;
031: import org.drftpd.slave.DiskStatus;
032: import org.drftpd.slave.SlaveStatus;
033: import org.drftpd.slave.Transfer;
034:
035: import org.drftpd.tests.DummyRemoteSlave;
036:
037: import java.io.IOException;
038:
039: import java.rmi.RemoteException;
040:
041: import java.util.Arrays;
042: import java.util.Collection;
043: import java.util.Collections;
044: import java.util.List;
045: import java.util.Properties;
046: import java.util.Set;
047:
048: /**
049: * @author zubov
050: * @version $Id: MaxbandwidthFilterTest.java 880 2004-12-29 04:24:27Z mog $
051: */
052: public class MaxbandwidthFilterTest extends TestCase {
053: RemoteSlave[] rslaves = { new RS("slave1", Collections.EMPTY_LIST),
054: new RS("slave2", Collections.EMPTY_LIST) };
055:
056: /**
057: * Constructor for MaxbandwidthFilterTest.
058: * @param arg0
059: */
060: public MaxbandwidthFilterTest(String arg0) {
061: super (arg0);
062: }
063:
064: public static void main(String[] args) {
065: junit.textui.TestRunner.run(MaxbandwidthFilterTest.class);
066: }
067:
068: public void testSimple() throws ObjectNotFoundException,
069: NoAvailableSlaveException {
070: Properties p = new Properties();
071: p.put("1.maxbandwidth", "800kb");
072:
073: Filter f = new MaxbandwidthFilter(new FC(), 1, p);
074: ScoreChart sc = new ScoreChart(Arrays.asList(rslaves));
075:
076: f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD,
077: new LinkedRemoteFilePath("/"), null);
078: assertEquals(sc.getBestSlave(), rslaves[1]);
079: }
080:
081: public static class LinkedRemoteFilePath extends
082: AbstractLinkedRemoteFile {
083: private String _path;
084:
085: public LinkedRemoteFilePath(String path) {
086: _path = path;
087: }
088:
089: public String getPath() {
090: return _path;
091: }
092:
093: public void deleteOthers(Set destSlaves) {
094: }
095:
096: public void remerge(CaseInsensitiveHashtable lightRemoteFiles,
097: RemoteSlave rslave) throws IOException {
098: }
099: }
100:
101: public class FC extends FilterChain {
102: public SlaveManager getSlaveManager() {
103: try {
104: return new SM();
105: } catch (RemoteException e) {
106: throw new RuntimeException(e);
107: }
108: }
109: }
110:
111: public class SM extends SlaveManager {
112: public SM() throws RemoteException {
113: super ();
114: }
115:
116: public RemoteSlave getSlave(String s)
117: throws ObjectNotFoundException {
118: if (s == null) {
119: throw new RuntimeException();
120: }
121:
122: if (rslaves[0] == null) {
123: throw new RuntimeException();
124: }
125:
126: if (s.equals(rslaves[0].getName())) {
127: return rslaves[0];
128: }
129:
130: if (s.equals(rslaves[1].getName())) {
131: return rslaves[1];
132: }
133:
134: throw new ObjectNotFoundException();
135: }
136: }
137:
138: public class RS extends DummyRemoteSlave {
139: public RS(String name, Collection duh) {
140: super (name, null);
141: }
142:
143: public SlaveStatus getSlaveStatusAvailable() {
144: if (getName().equals("slave2")) {
145: return new SlaveStatus(new DiskStatus(0, 0), 0, 0, 0,
146: 0, 0, 0);
147: }
148:
149: return new SlaveStatus(new DiskStatus(0, 0), 0, 0, 9999999,
150: 1, 9999999, 1);
151: }
152: }
153: }
|