public void setUp() throws Exception {
    super.setUp();
    tempDirPath = getTempDir().getAbsolutePath() + File.separator;

    theDaemon = getMockLockssDaemon();
    theDaemon.getAlertManager();
    theDaemon.getPluginManager().setLoadablePluginsReady(true);
    theDaemon.getHashService();
    MockSystemMetrics metrics = new MyMockSystemMetrics();
    metrics.initService(theDaemon);
    theDaemon.setSystemMetrics(metrics);

    theDaemon.setDaemonInited(true);

    Properties props = new Properties();
    props.setProperty(SystemMetrics.PARAM_HASH_TEST_DURATION, "1000");
    props.setProperty(SystemMetrics.PARAM_HASH_TEST_BYTE_STEP, "1024");
    props.setProperty(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, tempDirPath);
    ConfigurationUtil.setCurrentConfigFromProps(props);

    pluginMgr = theDaemon.getPluginManager();
    pluginMgr.startService();
    theDaemon.getHashService().startService();
    metrics.startService();
    metrics.setHashSpeed(100);

    simPlugin = PluginTestUtil.findPlugin(SimulatedPlugin.class);
  }
  public void testSkipsScriptTagsSpansRing() throws IOException {
    Properties p = new Properties();
    p.setProperty(GoslingHtmlLinkExtractor.PARAM_BUFFER_CAPACITY, "90");
    ConfigurationUtil.setCurrentConfigFromProps(p);
    extractor = new GoslingHtmlLinkExtractor();

    doScriptSkipTest("<script>", "</script>");
  }
 static Properties getAuIdProperties(String location) {
   File propFile = new File(location + File.separator + AU_ID_FILE);
   try {
     InputStream is = new BufferedInputStream(new FileInputStream(propFile));
     Properties idProps = new Properties();
     idProps.load(is);
     is.close();
     return idProps;
   } catch (Exception e) {
     logger.warning("Error loading au id from " + propFile.getPath() + ".");
     return null;
   }
 }
Example #4
0
 protected Properties filterResponseProps(Properties props) {
   Properties res = new Properties();
   for (Map.Entry ent : props.entrySet()) {
     String key = (String) ent.getKey();
     if (StringUtil.startsWithIgnoreCase(key, "x-lockss")
         || StringUtil.startsWithIgnoreCase(key, "x_lockss")
         || key.equalsIgnoreCase("org.lockss.version.number")) {
       continue;
     }
     // We've lost the original case - capitalize them the way most people
     // expect
     res.put(StringUtil.titleCase(key, '-'), (String) ent.getValue());
   }
   return res;
 }
Example #5
0
 String inferHttpResponseCode(CachedUrl cu, Properties cuProps) {
   if (cuProps.get("location") == null) {
     return "HTTP/1.1 200 OK";
   } else {
     return "HTTP/1.1 302 Found";
   }
 }
 /**
  * Finds the directory for this AU. If none found in the map, designates a new dir for it.
  *
  * @param auid AU id representing the au
  * @param repoRoot path to the root of the repository
  * @return the dir String
  */
 static String getAuDir(String auid, String repoRoot, boolean create) {
   String repoCachePath = extendCacheLocation(repoRoot);
   LocalRepository localRepo = getLocalRepository(repoRoot);
   synchronized (localRepo) {
     Map aumap = localRepo.getAuMap();
     String auPathSlash = (String) aumap.get(auid);
     if (auPathSlash != null) {
       return auPathSlash;
     }
     if (!create) {
       return null;
     }
     logger.debug3("Creating new au directory for '" + auid + "'.");
     String auDir = localRepo.getPrevAuDir();
     for (int cnt = RepositoryManager.getMaxUnusedDirSearch(); cnt > 0; cnt--) {
       // loop through looking for an available dir
       auDir = getNextDirName(auDir);
       File testDir = new File(repoCachePath, auDir);
       if (logger.isDebug3()) logger.debug3("Probe for unused: " + testDir);
       if (!testDir.exists()) {
         if (RepositoryManager.isStatefulUnusedDirSearch()) {
           localRepo.setPrevAuDir(auDir);
         }
         String auPath = testDir.toString();
         logger.debug3("New au directory: " + auPath);
         auPathSlash = auPath + File.separator;
         // write the new au property file to the new dir
         // XXX this data should be backed up elsewhere to avoid single-point
         // corruption
         Properties idProps = new Properties();
         idProps.setProperty(AU_ID_PROP, auid);
         saveAuIdProperties(auPath, idProps);
         aumap.put(auid, auPathSlash);
         return auPathSlash;
       } else {
         if (logger.isDebug3()) {
           logger.debug3("Existing directory found at '" + auDir + "'.  Checking next...");
         }
       }
     }
   }
   throw new RuntimeException(
       "Can't find unused repository dir after "
           + RepositoryManager.getMaxUnusedDirSearch()
           + " tries in "
           + repoCachePath);
 }
  public void testSkipsScriptTagsWhiteSpace() throws IOException {
    Properties p = new Properties();
    p.setProperty(GoslingHtmlLinkExtractor.PARAM_BUFFER_CAPACITY, "90");
    ConfigurationUtil.setCurrentConfigFromProps(p);
    extractor = new GoslingHtmlLinkExtractor();

    for (int ix = 1; ix < 200; ix += 5) {
      String whiteSpace = mkStr(' ', ix);
      doScriptSkipTest("<script" + whiteSpace + ">", "</script>", "Failed during iteration " + ix);
      doScriptSkipTest("<" + whiteSpace + "script>", "</script>", "Failed during iteration " + ix);
      doScriptSkipTest("<script>", "<" + whiteSpace + "/script>", "Failed during iteration " + ix);
      doScriptSkipTest(
          "<script" + whiteSpace + "blah=blah>", "</script>", "Failed during iteration " + ix);
      //      doScriptSkipTest("<script>", "</script"+whiteSpace+">",
      //                       "Failed during iteration "+ix);
    }
  }
  public void testParseJSIfConf() throws IOException {
    Properties p = new Properties();
    p.setProperty(GoslingHtmlLinkExtractor.PARAM_PARSE_JS, "true");
    ConfigurationUtil.setCurrentConfigFromProps(p);
    extractor = new GoslingHtmlLinkExtractor();

    String url = "http://www.example.com/link3.html";
    String url2 = "http://www.example.com/link2.html";
    String url3 = "http://www.example.com/link1.html";

    String source =
        "<html><head><title>Test</title></head><body>"
            + "<a href = javascript:newWindow('http://www.example.com/link3.html')</a>"
            + "<a href = javascript:popup('http://www.example.com/link2.html')</a>"
            + "<img src = javascript:popup('"
            + url3
            + "') </img>";
    assertEquals(SetUtil.set(url, url2, url3), parseSingleSource(source));
  }
  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);
  }
    /**
     * Return the auid -> au-subdir-path mapping. Enumerating the directories if necessary to
     * initialize the map
     */
    Map getAuMap() {
      if (auMap == null) {
        logger.debug3("Loading name map for '" + repoCacheFile + "'.");
        auMap = new HashMap();
        if (!repoCacheFile.exists()) {
          logger.debug3("Creating cache dir:" + repoCacheFile + "'.");
          if (!repoCacheFile.mkdirs()) {
            logger.critical("Couldn't create directory, check owner/permissions: " + repoCacheFile);
            // return empty map
            return auMap;
          }
        } else {
          // read each dir's property file and store mapping auid -> dir
          File[] auDirs = repoCacheFile.listFiles();
          for (int ii = 0; ii < auDirs.length; ii++) {
            String dirName = auDirs[ii].getName();
            //       if (dirName.compareTo(lastPluginDir) == 1) {
            //         // adjust the 'lastPluginDir' upwards if necessary
            //         lastPluginDir = dirName;
            //       }

            String path = auDirs[ii].getAbsolutePath();
            Properties idProps = getAuIdProperties(path);
            if (idProps != null) {
              String auid = idProps.getProperty(AU_ID_PROP);
              StringBuilder sb = new StringBuilder(path.length() + File.separator.length());
              sb.append(path);
              sb.append(File.separator);
              auMap.put(auid, sb.toString());
              logger.debug3("Mapping to: " + auMap.get(auid) + ": " + auid);
            } else {
              logger.debug3("Not mapping " + path + ", no auid file.");
            }
          }
        }
      }
      return auMap;
    }
Example #11
0
  private void initRequiredServices() {
    theDaemon = getMockLockssDaemon();
    pollmanager = new LocalPollManager();
    pollmanager.initService(theDaemon);
    theDaemon.setPollManager(pollmanager);

    theDaemon.getPluginManager();
    testau = PollTestPlugin.PTArchivalUnit.createFromListOfRootUrls(rootV1urls);
    PluginTestUtil.registerArchivalUnit(testau);

    String tempDirPath = null;
    try {
      tempDirPath = getTempDir().getAbsolutePath() + File.separator;
    } catch (IOException ex) {
      fail("unable to create a temporary directory");
    }

    Properties p = new Properties();
    p.setProperty(IdentityManager.PARAM_IDDB_DIR, tempDirPath + "iddb");
    p.setProperty(LockssRepositoryImpl.PARAM_CACHE_LOCATION, tempDirPath);
    p.setProperty(ConfigManager.PARAM_PLATFORM_DISK_SPACE_LIST, tempDirPath);
    p.setProperty(IdentityManager.PARAM_LOCAL_IP, "127.0.0.1");
    p.setProperty(ConfigManager.PARAM_NEW_SCHEDULER, "false");
    // XXX we need to disable verification of votes because the
    // voter isn't really there
    p.setProperty(V1Poll.PARAM_AGREE_VERIFY, "0");
    p.setProperty(V1Poll.PARAM_DISAGREE_VERIFY, "0");
    ConfigurationUtil.setCurrentConfigFromProps(p);
    idmgr = theDaemon.getIdentityManager();
    idmgr.startService();
    // theDaemon.getSchedService().startService();
    theDaemon.getHashService().startService();
    theDaemon.getDatagramRouterManager().startService();
    theDaemon.getRouterManager().startService();
    theDaemon.getSystemMetrics().startService();
    theDaemon.getActivityRegulator(testau).startService();
    theDaemon.setNodeManager(new MockNodeManager(), testau);
    pollmanager.startService();
  }
 static void saveAuIdProperties(String location, Properties props) {
   // XXX these AU_ID_FILE entries need to be backed up elsewhere to avoid
   // single-point corruption
   File propDir = new File(location);
   if (!propDir.exists()) {
     logger.debug("Creating directory '" + propDir.getAbsolutePath() + "'");
     propDir.mkdirs();
   }
   File propFile = new File(propDir, AU_ID_FILE);
   try {
     logger.debug3("Saving au id properties at '" + location + "'.");
     OutputStream os = new BufferedOutputStream(new FileOutputStream(propFile));
     props.store(os, "ArchivalUnit id info");
     os.close();
     propFile.setReadOnly();
   } catch (IOException ioe) {
     logger.error("Couldn't write properties for " + propFile.getPath() + ".", ioe);
     throw new LockssRepository.RepositoryStateException("Couldn't write au id properties file.");
   }
 }