public void testGetRepositoryList() throws Exception {
   assertEmpty(mgr.getRepositoryList());
   String tempDirPath = setUpDiskSpace();
   assertEquals(ListUtil.list("local:" + tempDirPath), mgr.getRepositoryList());
   String tempdir2 = getTempDir().getAbsolutePath() + File.separator;
   ConfigurationUtil.setFromArgs(
       "org.lockss.platform.diskSpacePaths", tempdir2 + ";" + tempDirPath);
   assertEquals(
       ListUtil.list("local:" + tempdir2, "local:" + tempDirPath), mgr.getRepositoryList());
 }
  public void testFindLeastFullRepository() throws Exception {
    Map repoMap =
        MapUtil.map(
            "local:one",
            new MyDF("/one", 1000),
            "local:two",
            new MyDF("/two", 3000),
            "local:three",
            new MyDF("/three", 2000));
    mgr.setRepoMap(repoMap);

    assertEquals("local:two", mgr.findLeastFullRepository());
  }
 public void setUp() throws Exception {
   super.setUp();
   theDaemon = getMockLockssDaemon();
   mgr = new MyRepositoryManager();
   theDaemon.setRepositoryManager(mgr);
   mgr.initService(theDaemon);
 }
  public void testConfig() throws Exception {
    MyMockLockssRepositoryImpl repo1 = makeRepo("foo");
    assertEquals(RepositoryManager.DEFAULT_MAX_PER_AU_CACHE_SIZE, repo1.nodeCacheSize);

    ConfigurationUtil.setFromArgs(RepositoryManager.PARAM_MAX_PER_AU_CACHE_SIZE, "4");
    MyMockLockssRepositoryImpl repo2 = makeRepo("bar");
    assertEquals(4, repo1.nodeCacheSize);
    assertEquals(4, repo2.nodeCacheSize);

    repo1.cnt = 0;
    ConfigurationUtil.setFromArgs(RepositoryManager.PARAM_MAX_PER_AU_CACHE_SIZE, "37");
    assertEquals(37, repo1.nodeCacheSize);
    assertEquals(37, repo2.nodeCacheSize);
    assertEquals(1, repo1.cnt);
    // ensure setNodeCacheSize doesn't get called if param doesn't change
    ConfigurationUtil.setFromArgs(
        RepositoryManager.PARAM_MAX_PER_AU_CACHE_SIZE, "37", "org.lockss.somethingElse", "bar");
    assertEquals(1, repo1.cnt);

    PlatformUtil.DF warn = mgr.getDiskWarnThreshold();
    PlatformUtil.DF full = mgr.getDiskFullThreshold();
    assertEquals(5000 * 1024, warn.getAvail());
    assertEquals(0.98, warn.getPercent(), .00001);
    assertEquals(100 * 1024, full.getAvail());
    assertEquals(0.99, full.getPercent(), .00001);

    Properties p = new Properties();
    p.put(RepositoryManager.PARAM_DISK_WARN_FRRE_MB, "17");
    p.put(RepositoryManager.PARAM_DISK_WARN_FRRE_PERCENT, "20");
    p.put(RepositoryManager.PARAM_DISK_FULL_FRRE_MB, "7");
    p.put(RepositoryManager.PARAM_DISK_FULL_FRRE_PERCENT, "10");
    ConfigurationUtil.setCurrentConfigFromProps(p);
    warn = mgr.getDiskWarnThreshold();
    full = mgr.getDiskFullThreshold();
    assertEquals(17 * 1024, warn.getAvail());
    assertEquals(0.80, warn.getPercent(), .00001);
    assertEquals(7 * 1024, full.getAvail());
    assertEquals(0.90, full.getPercent(), .00001);
  }
 public void testSizeCalc() throws Exception {
   SimpleBinarySemaphore sem = new SimpleBinarySemaphore();
   mgr.setSem(sem);
   RepositoryNode node1 = new RepositoryNodeImpl("url1", "testDir", null);
   RepositoryNode node2 = new RepositoryNodeImpl("url2", "testDir", null);
   RepositoryNode node3 = new RepositoryNodeImpl("url3", "testDir", null);
   mgr.queueSizeCalc(node1);
   assertTrue(sem.take(TIMEOUT_SHOULDNT));
   assertEquals(ListUtil.list(node1), mgr.getNodes());
   mgr.queueSizeCalc(node2);
   mgr.queueSizeCalc(node3);
   assertTrue(sem.take(TIMEOUT_SHOULDNT));
   if (mgr.getNodes().size() < 3) {
     assertTrue(sem.take(TIMEOUT_SHOULDNT));
   }
   assertSameElements(ListUtil.list(node1, node2, node3), mgr.getNodes());
 }
 public void testSleepCalc() throws Exception {
   assertEquals(90, mgr.sleepTimeToAchieveLoad(10L, .1F));
   assertEquals(40, mgr.sleepTimeToAchieveLoad(10L, .2F));
   assertEquals(10, mgr.sleepTimeToAchieveLoad(10L, .5F));
   assertEquals(50, mgr.sleepTimeToAchieveLoad(150L, .75F));
 }
 public void testGetRepositoryDF() throws Exception {
   PlatformUtil.DF df = mgr.getRepositoryDF("local:.");
   assertNotNull(df);
 }