/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 4313887 6838333 7017446
* @summary Unit test for java.nio.file.WatchService
* @library ..
* @run main Basic
*/
/**
* Unit test for WatchService that exercises all methods in various scenarios.
*/
public class Basic {
throw new RuntimeException("Key is not valid");
throw new RuntimeException("Unexpected watchable");
}
try {
} catch (InterruptedException x) {
// not expected
throw new RuntimeException(x);
}
throw new RuntimeException("removed unexpected key");
}
{
throw new RuntimeException("unexpected event");
throw new RuntimeException("unexpected context");
}
/**
* Simple test of each of the standard events
*/
// --- ENTRY_CREATE ---
// register for event
// create file
// remove key and check that we got the ENTRY_CREATE event
throw new RuntimeException("key has been cancalled");
// --- ENTRY_DELETE ---
throw new RuntimeException("register did not return existing key");
throw new RuntimeException("key has been cancalled");
// create the file for the next test
// --- ENTRY_MODIFY ---
throw new RuntimeException("register did not return existing key");
}
// remove key and check that we got the ENTRY_MODIFY event
// done
}
}
/**
* Check that a cancelled key will never be queued
*/
// create a file in the directory
// poll for keys - there will be none
try {
throw new RuntimeException("key should not be queued");
} catch (InterruptedException x) {
throw new RuntimeException(x);
}
// done
}
}
/**
* Check that deleting a registered directory causes the key to be
* cancelled and queued.
*/
throw new RuntimeException("Key was not cancelled");
throw new RuntimeException("Key is still valid");
}
}
/**
* Asynchronous close of watcher causes blocked threads to wakeup
*/
public void run() {
try {
} catch (InterruptedException x) {
x.printStackTrace();
} catch (IOException x) {
x.printStackTrace();
}
}
};
// start thread to close watch service after delay
try {
throw new RuntimeException("ClosedWatchServiceException not thrown");
} catch (InterruptedException x) {
throw new RuntimeException(x);
} catch (ClosedWatchServiceException x) {
}
}
/**
* Simple test to check exceptions and other cases
*/
@SuppressWarnings("unchecked")
try {
// Poll tests
throw new RuntimeException("no keys registered");
try {
throw new RuntimeException("no keys registered");
if (waited < 2900)
throw new RuntimeException("poll was too short");
} catch (InterruptedException x) {
throw new RuntimeException(x);
}
// IllegalArgumentException
try {
throw new RuntimeException("IllegalArgumentException not thrown");
} catch (IllegalArgumentException x) {
}
try {
// OVERFLOW is ignored so this is equivalent to the empty set
throw new RuntimeException("IllegalArgumentException not thrown");
} catch (IllegalArgumentException x) {
}
// UnsupportedOperationException
try {
}});
} catch (UnsupportedOperationException x) {
}
try {
new WatchEvent.Modifier() {
});
throw new RuntimeException("UnsupportedOperationException not thrown");
} catch (UnsupportedOperationException x) {
}
// NullPointerException
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException x) {
}
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException x) {
}
try {
throw new RuntimeException("NullPointerException not thrown");
} catch (NullPointerException x) {
}
} finally {
}
// -- ClosedWatchServiceException --
try {
throw new RuntimeException("ClosedWatchServiceException not thrown");
} catch (ClosedWatchServiceException x) {
}
// assume that poll throws exception immediately
try {
throw new RuntimeException("ClosedWatchServiceException not thrown");
} catch (InterruptedException x) {
throw new RuntimeException(x);
} catch (ClosedWatchServiceException x) {
if (waited > 5000)
throw new RuntimeException("poll was too long");
}
try {
throw new RuntimeException("ClosedWatchServiceException not thrown");
} catch (InterruptedException x) {
throw new RuntimeException(x);
} catch (ClosedWatchServiceException x) {
}
try {
throw new RuntimeException("ClosedWatchServiceException not thrown");
} catch (ClosedWatchServiceException x) {
}
}
/**
* Test that directory can be registered with more than one watch service
* and that events don't interfere with each other
*/
try {
// create gus1
// register with both watch services (different events)
throw new RuntimeException("keys should be different");
// create gus2
// check that key1 got ENTRY_CREATE
// check that key2 got zero events
throw new RuntimeException("key not expected");
// delete gus1
// check that key2 got ENTRY_DELETE
// check that key1 got zero events
throw new RuntimeException("key not expected");
// reset for next test
// change registration with watcher2 so that they are both
// registered for the same event
// create file and key2 should be queued
} finally {
}
}
try {
} finally {
}
}
}