Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions platform/masterfs/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ test.config.stableBTD.excludes=\
**/FileObjSymlinkTest.class,\
**/FolderObjTest.class,\
**/ChildrenSupportTest.class,\
**/ProvidedExtensionsTest.class,\
**/SlowRefreshAndPriorityIOTest.class,\
**/ProvidedExtensionsTest.class

test.unit.excludes=\
**/SlowRefreshSuspendableTest.class,\
**/StatFilesTest.class
spec.version.base=2.90.0
**/TwoFileNamesForASingleFileTest.class,\
**/FolderObjCacheTest.class

# TODO remove SM usage in tests
test.jms.flags=-Djava.security.manager=allow
spec.version.base=2.90.0
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ protected void setUp() throws Exception {
testFolder = FileUtil.toFileObject(dir);
assertNotNull("Test folder created", testFolder);

System.setSecurityManager(new FileChangedManager());
}

public void testRefreshCanBeSuspendedByPriorityIO() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ protected void setUp() throws Exception {
testFolder = FileUtil.toFileObject(dir);
assertNotNull("Test folder created", testFolder);

System.setSecurityManager(new FileChangedManager());
}

public void testChangesDeliveredSoonerThanEverythingIsChecked() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ protected void setUp() throws Exception {
testFolder = FileUtil.toFileObject(dir);
assertNotNull("Test folder created", testFolder);

System.setSecurityManager(new FileChangedManager());
}

@RandomlyFails // jglick: "No change detected expected:<0> but was:<1>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ protected void setUp() throws Exception {
dir.mkdirs();
testFolder = FileUtil.toFileObject(dir);
assertNotNull("Test folder created", testFolder);

System.setSecurityManager(new FileChangedManager());
}

public void testRefreshPrefersSuggestedFolders() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ protected void setUp() throws Exception {
testFolder = FileUtil.toFileObject(dir);
assertNotNull("Test folder created", testFolder);

System.setSecurityManager(new FileChangedManager());
}

@RandomlyFails // NB-Core-Build #4386: Background I/O access needs to stop before we finish our task
Expand Down Expand Up @@ -169,6 +168,7 @@ void doWork() {
LOG.log(Level.INFO, "Created {0}", busyFile);
for (int i = 0; i < 2000; i ++) {
assertTrue("Can be read", busyFile.canRead());
FileChangedManager.getInstance().checkRead(busyFile.getPath());
LOG.log(Level.INFO, "Touched {0}", i);
if (i > 100) {
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public TwoFileNamesForASingleFileTest(String name) {
@Override
protected void setUp() throws Exception {
clearWorkDir();
System.setSecurityManager(FileChangedManager.getInstance());
}

public void testTwoFileNames() throws Exception {
Expand All @@ -57,6 +56,7 @@ public void testTwoFileNames() throws Exception {
assertEquals("Empty is empty", 0, empty.length);

final File n = new File(f, "x.txt");
FileChangedManager.getInstance().checkWrite(n.getPath());
n.createNewFile();
FileObject fn = FileUtil.toFileObject(f);
assertNotNull("File object found", fn);
Expand All @@ -71,8 +71,10 @@ class R implements Runnable {
@Override
public void run() {
refresh();
FileChangedManager.getInstance().checkDelete(n.getPath());
n.delete();
none = fo.getChildren();
FileChangedManager.getInstance().checkWrite(n.getPath());
assertTrue("Directory creation succeeds", n.mkdirs());
refresh();
one = fo.getChildren();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
* @author Radek Matous
*/
public class FolderObjCacheTest extends NbTestCase {
static {
System.setSecurityManager(FileChangedManager.getInstance());
}

Logger LOG;

public FolderObjCacheTest(String testName) {
Expand Down Expand Up @@ -92,6 +88,7 @@ private void doWork(boolean gc) throws IOException {
assertNull(FileBasedFileSystem.getFileObject(fold));
assertNull(workDirFo.getFileObject(fold.getName()));
assertFalse(existsChild(workDirFo, fold.getName()));
FileChangedManager.getInstance().checkWrite(fold.getPath());
fold.mkdir();
assertNotNull((workDirFo.getFileSystem()).findResource(workDirFo.getPath()+"/"+fold.getName()));
assertNotNull(workDirFo.getFileObject(fold.getName()));
Expand All @@ -101,6 +98,7 @@ private void doWork(boolean gc) throws IOException {
assertTrue(existsChild(workDirFo, fold.getName()));
FileObject gcFo = workDirFo.getFileObject(fold.getName());
assertNotNull("One exists", gcFo);
FileChangedManager.getInstance().checkDelete(fold.getPath());
fold.delete();
assertNull("Immediatelly invalidated thanks to FileChangedManager", workDirFo.getFileObject(fold.getName()));
assertFalse(existsChild(workDirFo, fold.getName()));
Expand All @@ -113,6 +111,7 @@ private void doWork(boolean gc) throws IOException {
}

LOG.info("Before mkdir: " + fold);
FileChangedManager.getInstance().checkWrite(fold.getPath());
fold.mkdir();
LOG.info("After mkdir: " + fold);
final FileObject okFn = workDirFo.getFileObject(fold.getName());
Expand All @@ -128,6 +127,7 @@ private void doWork(boolean gc) throws IOException {
foldFo.delete();
assertNull(workDirFo.getFileObject(fold.getName()));
assertFalse(existsChild(workDirFo, fold.getName()));
FileChangedManager.getInstance().checkWrite(fold.getPath());
fold.mkdir();
//assertNull(((FileBasedFileSystem)workDirFo.getFileSystem()).findFileObject(fold));
//assertNull(MasterFileSystem.getFileObject(fold));
Expand All @@ -136,6 +136,7 @@ private void doWork(boolean gc) throws IOException {
workDirFo.getFileSystem().refresh(false);
assertNotNull(workDirFo.getFileObject(fold.getName()));
assertTrue(existsChild(workDirFo, fold.getName()));
FileChangedManager.getInstance().checkDelete(fold.getPath());
fold.delete();
assertNull(workDirFo.getFileObject(fold.getName()));
assertFalse(existsChild(workDirFo, fold.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void testRefreshOfAFolder() throws IOException {
FileObject fo = FileUtil.toFileObject(getWorkDir());
FileObject dir = fo.getFileObject("dir");
assertNotNull("dir found", dir);
System.setSecurityManager(new AssertNoLockManager(getWorkDirPath()));
List<FileObject> arr = Arrays.asList(dir.getChildren());
dir.refresh();
List<FileObject> arr2 = Arrays.asList(dir.getChildren());
Expand All @@ -92,37 +91,7 @@ public void testGetChild() throws IOException {
FileObject fo = FileUtil.toFileObject(getWorkDir());
FileObject dir = fo.getFileObject("dir");
assertNotNull("dir found", dir);
System.setSecurityManager(new AssertNoLockManager(getWorkDirPath()));
FileObject fileObject = dir.getFileObject("x50.txt");
assertNotNull(fileObject);
}

private static class AssertNoLockManager extends SecurityManager {
final String prefix;

public AssertNoLockManager(String p) {
prefix = p;
}

@Override
public void checkRead(String string) {
if (string.startsWith(prefix)) {
assertFalse("No lock", ChildrenSupport.isLock());
}
}

@Override
public void checkRead(String string, Object o) {
checkRead(string);
}

@Override
public void checkPermission(Permission prmsn) {
}

@Override
public void checkPermission(Permission prmsn, Object o) {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected void setUp() throws java.lang.Exception {
//init
FileUtil.toFileObject(testFile);
monitor = new StatFiles();
System.setSecurityManager(monitor);
monitor.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public NamingFactoryTest(String n) {
public static Test suite() {
NbTestSuite s = new NbTestSuite();
s.addTestSuite(NamingFactoryTest.class);
s.addTest(new NamingFactoryTest("registerSecurityManager"));
s.addTest(new NamingFactoryTest("NamingFactoryTest"));
s.addTestSuite(NamingFactoryTest.class);
return s;
}
Expand All @@ -55,10 +55,6 @@ protected void setUp() throws Exception {
assertTrue("Contains Fixed: " + res.getClass(), res.getClass().getName().contains("Fixed"));
}

public void registerSecurityManager() {
System.setSecurityManager(new AssertNoLockManager(NamingFactory.class));
}

public void testDontForciblyUnregisterFileName() throws Exception {
File f = new File(getWorkDir(), "child.txt");
f.createNewFile();
Expand Down Expand Up @@ -167,31 +163,5 @@ public void testInvalidatePrevFolder() throws Exception {
assertFalse("Oldest file object is no longer valid", dir.isValid());
assertFalse("Middle file object is no longer valid", file.isValid());
assertTrue("Newest is valid", newDir.isValid());

}

private static class AssertNoLockManager extends SecurityManager {
private final Object LOCK;

public AssertNoLockManager(Object lock) {
LOCK = lock;
}
@Override
public void checkRead(String string) {
assertFalse("No lock", Thread.holdsLock(LOCK));
}

@Override
public void checkRead(String string, Object o) {
checkRead(string);
}

@Override
public void checkPermission(Permission prmsn) {
}

@Override
public void checkPermission(Permission prmsn, Object o) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
*/
public abstract class TestBaseHid extends MultiThreadedTestCaseHid {
/** Support for events*/
protected List<FileEvent> fileChangedL = new ArrayList<FileEvent> ();
protected List<FileEvent> fileDCreatedL = new ArrayList<FileEvent> ();
protected List<FileEvent> fileFCreatedL = new ArrayList<FileEvent> ();
protected List<FileEvent> fileDeletedL = new ArrayList<FileEvent> ();
protected List<FileRenameEvent> fileRenamedL = new ArrayList<FileRenameEvent> ();
protected List<FileAttributeEvent> fileAttrChangedL = new ArrayList<FileAttributeEvent> ();
protected List<FileEvent> fileChangedL = new ArrayList<>();
protected List<FileEvent> fileDCreatedL = new ArrayList<>();
protected List<FileEvent> fileFCreatedL = new ArrayList<>();
protected List<FileEvent> fileDeletedL = new ArrayList<>();
protected List<FileRenameEvent> fileRenamedL = new ArrayList<>();
protected List<FileAttributeEvent> fileAttrChangedL = new ArrayList<>();

private FileChangeListener defListener;
private String resourcePrefix = "";
Expand All @@ -57,8 +57,7 @@ public TestBaseHid(String name) {
/** array of filesystems that can be used for tests. All filesystems should
* satisfy requirements for resources @see getResources () */
protected FileSystem allTestedFS[];
private static SecurityManager defaultSecurityManager;
/** If not null, file accesses are counted through custom SecurityManager. */

public static StatFiles accessMonitor;

@Override
Expand All @@ -74,22 +73,10 @@ protected void setUp() throws Exception {
allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this);
}
if (allTestedFS != null) testedFS = allTestedFS[0];
// If not null, file accesses are counted through custom SecurityManager.
if(accessMonitor != null) {
if(defaultSecurityManager == null) {
defaultSecurityManager = System.getSecurityManager();
}
System.setSecurityManager(accessMonitor);
}
}

@Override
protected void tearDown() throws Exception {
// restore SecurityManager if previously changed
if(accessMonitor != null) {
System.setSecurityManager(defaultSecurityManager);
}

if (testedFS instanceof JarFileSystem) {
testedFS.removeNotify();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,9 @@ public StatFiles() {
}

public void register() {
if (defaultSecurityManager == null) {
defaultSecurityManager = System.getSecurityManager();
}
System.setSecurityManager(this);
}

public void unregister() {
if (defaultSecurityManager == null) {
System.setSecurityManager(defaultSecurityManager);
}
}

public void reset() {
Expand Down
Loading