private FileDownloadInfo find(List<FileDownloadInfo> updates, File file) { for (FileDownloadInfo info : updates) { if (info.getLocalFile().equals(file)) { return info; } } return null; }
private void checkInfo( NameStatePair[] pairsToCheck, long timeout, FileObject privProjectStorageDir) throws IOException { List<NameStatePair> pairs = new ArrayList<NameStatePair>(Arrays.asList(pairsToCheck)); long stopTime = System.currentTimeMillis() + timeout; while (true) { List<FileDownloadInfo> updates = HostUpdates.testGetUpdates(getTestExecutionEnvironment(), privProjectStorageDir); boolean success = true; StringBuilder notFoundMessage = new StringBuilder(); StringBuilder wrongStateFoundMessage = new StringBuilder(); for (Iterator<NameStatePair> iter = pairs.iterator(); iter.hasNext(); ) { NameStatePair pair = iter.next(); FileDownloadInfo info = find(updates, pair.file); if (info == null) { success = false; if (notFoundMessage.length() == 0) { notFoundMessage.append("Can not find FileDownloadInfo for "); } else { notFoundMessage.append(", "); } notFoundMessage.append(pair.file.getName()); } else { FileDownloadInfo.State state = info.getState(); if (state.equals(pair.state)) { System.err.printf( "\tOK state %s for %s at %s\n", info.getState(), info.getLocalFile(), getTestExecutionEnvironment()); iter.remove(); } else { success = false; if (wrongStateFoundMessage.length() == 0) { wrongStateFoundMessage.append("Wrong state: "); } else { wrongStateFoundMessage.append(", "); } wrongStateFoundMessage .append(pair.file.getName()) .append(": expected ") .append(pair.state) .append(" found ") .append(state); } } } if (success) { return; } else { if (System.currentTimeMillis() < stopTime) { sleep(500); } else { StringBuilder message = new StringBuilder(notFoundMessage); if (message.length() > 0 && wrongStateFoundMessage.length() > 0) { message.append(";\n"); } message.append(wrongStateFoundMessage); assertTrue(message.toString(), false); } } } }