use of org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler.InfoTracker in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method testScheduleCheckForUpdates.
public void testScheduleCheckForUpdates() throws Exception {
setupEnv();
Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfo = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
SyncSystemModulesManagerScheduler scheduler = new SyncSystemModulesManagerScheduler();
final Set changes = Collections.synchronizedSet(new HashSet<>());
try {
Set<Entry<IInterpreterManager, Map<String, IInterpreterInfo>>> entrySet = managerToNameToInfo.entrySet();
SyncSystemModulesManagerScheduler.IInfoTrackerListener listener = new IInfoTrackerListener() {
@Override
public void onChangedIInterpreterInfo(InfoTracker infoTracker, File file) {
changes.add(file);
}
};
for (Entry<IInterpreterManager, Map<String, IInterpreterInfo>> entry : entrySet) {
Map<String, IInterpreterInfo> value = entry.getValue();
scheduler.afterSetInfos(entry.getKey(), value.values().toArray(new IInterpreterInfo[value.size()]), listener);
}
final File module4File = new File(libDir, "module4.py");
FileUtils.writeStrToFile("class Module3:pass", module4File);
TestUtils.waitUntilCondition(new ICallback<String, Object>() {
@Override
public String call(Object arg) {
if (changes.contains(module4File)) {
return null;
}
return "Changes not found.";
}
});
changes.clear();
final File myPthFile = new File(libDir, "my.pth");
FileUtils.writeStrToFile("./setuptools-1.1.6-py2.6.egg", myPthFile);
TestUtils.waitUntilCondition(new ICallback<String, Object>() {
@Override
public String call(Object arg) {
if (changes.contains(myPthFile)) {
return null;
}
return "Changes not found.";
}
});
synchronized (this) {
// Wait a bit as we may have 2 notifications (for creation and modification of the pth).
this.wait(250);
}
// Now, add an unrelated directory: no notifications are expected then.
changes.clear();
final File myUnrelatedDir = new File(libDir, "unrelatedDir");
myUnrelatedDir.mkdir();
synchronized (this) {
this.wait(250);
}
// no changes expected
assertEquals(new HashSet<>(), changes);
} finally {
scheduler.stop();
}
changes.clear();
final File myPthFile2 = new File(libDir, "my2.pth");
FileUtils.writeStrToFile("./setuptools-1.1.7-py2.6.egg", myPthFile2);
synchronized (this) {
this.wait(250);
}
assertEquals(new HashSet<>(), changes);
}
Aggregations