MatchdirFilter extends Filter { public void process(ScoreChart scorechart, User user, InetAddress source, char direction, InodeHandleInterface file, RemoteSlave sourceSlave) { boolean validPath = _negateExpr != _p.matcher(file.getPath()).matches(); if (validPath) { AssignSlave.addScoresToChart(_assigns, scorechart); } } MatchdirFilter(int i, Properties p); void process(ScoreChart scorechart, User user, InetAddress source,
                        char direction, InodeHandleInterface file, RemoteSlave sourceSlave);  }
@Test public void testSimple() throws ObjectNotFoundException, NoAvailableSlaveException { Properties p = new Properties(); p.put("1.assign", "slave1+100, slave2-100"); p.put("1.match", "/path1/*"); Filter f = new MatchdirFilter(1, p); ScoreChart sc = new ScoreChart(Arrays.asList(rslaves)); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, new DirectoryHandle("/path2/dir/file.txt"), null); assertEquals(0, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[1]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[2]).getScore()); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, new DirectoryHandle("/"), null); assertEquals(0, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[1]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[2]).getScore()); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, new DirectoryHandle("/path1/dir/file.txt"), null); assertEquals(100, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(-100, sc.getScoreForSlave(rslaves[1]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[2]).getScore()); }
@Test public void testAll() throws ObjectNotFoundException, NoAvailableSlaveException { Properties p = new Properties(); p.put("1.assign", "ALL+100"); p.put("1.match", "/path2/*"); Filter f = new MatchdirFilter(1, p); ScoreChart sc = new ScoreChart(Arrays.asList(rslaves)); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, new DirectoryHandle("/path1/dir/file.txt"), null); assertEquals(0, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[1]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[2]).getScore()); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, new DirectoryHandle("/path2/dir/file.txt"), null); assertEquals(100, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(100, sc.getScoreForSlave(rslaves[1]).getScore()); assertEquals(100, sc.getScoreForSlave(rslaves[2]).getScore()); }
@Test public void testRemove() throws NoAvailableSlaveException, ObjectNotFoundException { Properties p = new Properties(); p.put("1.assign", "slave2-remove"); p.put("1.match", "/path1/*"); ScoreChart sc = new ScoreChart(Arrays.asList(rslaves)); Filter f = new MatchdirFilter(1, p); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, new DirectoryHandle("/path1/dir/file.txt"), null); assertEquals(0, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[2]).getScore()); try { sc.getScoreForSlave(rslaves[1]); Assertions.fail("should not be called"); } catch (ObjectNotFoundException success) { } }