public void testHandleEmptyFile() throws Exception { MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com", null); CachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); NodeStateImpl nodeState = new NodeStateImpl(mcus, -1, null, null, repository); nodeState.setPollHistoryList(new ArrayList()); // storing empty vector repository.storePollHistories(nodeState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation( filePath, "http://www.example.com/" + HistoryRepositoryImpl.HISTORY_FILE_NAME); File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); nodeState.setPollHistoryList(new ArrayList()); repository.loadPollHistories(nodeState); assertEquals(0, nodeState.pollHistories.size()); mspec = new MockCachedUrlSetSpec("http://www.example2.com", null); mcus = new MockCachedUrlSet(mau, mspec); nodeState = new NodeStateImpl(mcus, -1, null, null, repository); filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation(filePath, "http://www.example2.com/"); xmlFile = new File(filePath); assertFalse(xmlFile.exists()); xmlFile.mkdirs(); filePath += HistoryRepositoryImpl.HISTORY_FILE_NAME; xmlFile = new File(filePath); OutputStream os = new BufferedOutputStream(new FileOutputStream(xmlFile)); os.write(new byte[0]); os.close(); assertTrue(xmlFile.exists()); nodeState.setPollHistoryList(new ArrayList()); repository.loadPollHistories(nodeState); assertEquals(0, nodeState.pollHistories.size()); assertFalse(xmlFile.exists()); xmlFile = new File( filePath + CurrentConfig.getParam( ObjectSerializer.PARAM_FAILED_DESERIALIZATION_EXTENSION, ObjectSerializer.DEFAULT_FAILED_DESERIALIZATION_EXTENSION)); assertTrue(xmlFile.exists()); }
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."); } }