6685209: (test) Improve performance of event-checking tests
authorbristor
Thu Apr 17 15:26:01 2008 -0700 (23 months ago)
changeset 128c422d299123d
parent 127a9aaea10a96d
child 132e164135ec908
6685209: (test) Improve performance of event-checking tests
Summary: Refactors some helper code out of <test>.java files into EventChecker.java, improves test performance, and removes the cause of some test failures (see EventChecker.sleep()).
Reviewed-by: ksrini
test/java/module/repository/EventChecker.java
test/java/module/repository/LocalRepositoryTest.java
test/java/module/repository/RepositoryTest.java
test/java/module/repository/URLRepoInstallTest.java
test/java/module/repository/URLRepositoryReloadTest.java
test/java/module/repository/URLRepositoryTest.java
--- a/test/java/module/repository/LocalRepositoryTest.java Fri Apr 11 08:27:13 2008 -0700
+++ b/test/java/module/repository/LocalRepositoryTest.java Thu Apr 17 15:26:01 2008 -0700
@@ -37,7 +37,6 @@ import java.util.List;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.*;
import sun.module.JamUtils;
import sun.module.repository.RepositoryUtils;
@@ -45,21 +44,13 @@ import sun.module.repository.RepositoryU
* @test LocalRepositoryTest.java
* @summary Test LocalRepository.
* @library ../tools
- * @compile -XDignore.symbol.file LocalRepositoryTest.java ../tools/JamBuilder.java
+ * @compile -XDignore.symbol.file LocalRepositoryTest.java EventChecker.java ../tools/JamBuilder.java
* @run main LocalRepositoryTest
* */
public class LocalRepositoryTest {
static final boolean debug = System.getProperty("module.debug") != null;
- // Setup repository listener
- static final BlockingQueue<RepositoryEvent> initEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> shutdownEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> installEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> uninstallEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
+ static EventChecker ec = new EventChecker();
private static void println(String s) {
if (debug) System.err.println(s);
@@ -98,24 +89,6 @@ public class LocalRepositoryTest {
Repository systemRepo = Repository.getSystemRepository();
check(systemRepo != null);
- RepositoryListener repositoryListener = new RepositoryListener() {
- public void handleEvent(RepositoryEvent e) {
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- initEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- shutdownEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.MODULE_INSTALLED) {
- installEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.MODULE_UNINSTALLED) {
- uninstallEventQueue.add(e);
- }
- }
- };
- Repository.addRepositoryListener(repositoryListener);
-
Map<String, String> config = new HashMap<String, String>();
config.put("sun.module.repository.LocalRepository.cacheDirectory",
expandDir.getAbsolutePath());
@@ -124,10 +97,10 @@ public class LocalRepositoryTest {
"test", srcDir, config);
// Only REPOSITORY_INITIALIZED event should be fired.
- check(initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// In a different repository, verify we get an exception if we require
// the source dir to exist, but it does not.
@@ -145,10 +118,10 @@ public class LocalRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(r2));
- check(!shutdownEventExists(r2));
- check(!installEventExists(r2, null));
- check(!uninstallEventExists(r2, null));
+ check(!ec.initializeEventExists(r2));
+ check(!ec.shutdownEventExists(r2));
+ check(!ec.installEventExists(r2, null));
+ check(!ec.uninstallEventExists(r2, null));
// Verify the repository is active and reloadable
check(repo.isActive());
@@ -167,10 +140,10 @@ public class LocalRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Check that find() and list() return nothing from repo, since the
// its source dir does not exist.
@@ -181,10 +154,10 @@ public class LocalRepositoryTest {
repo.reload();
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Verify that repository is now *not* read-only
check(repo.isReadOnly() == false);
@@ -216,10 +189,10 @@ public class LocalRepositoryTest {
check(mai.getName().equals("LocalRepoModuleA"));
// MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, mai));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, mai));
+ check(!ec.uninstallEventExists(repo, null));
// Verify module is runnable from read-only source location
runModule(repo, "LocalRepoModuleA");
@@ -238,10 +211,10 @@ public class LocalRepositoryTest {
check(installed.get(0).getName().equals("LocalRepoModuleA"));
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Create platform-specific JAM
final String platform = RepositoryUtils.getPlatform();
@@ -255,10 +228,10 @@ public class LocalRepositoryTest {
println("LocalRepoModuleB mai: " + mai);
// MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, mai));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, mai));
+ check(!ec.uninstallEventExists(repo, null));
// Verify that same module cannot be over itself
try {
@@ -270,10 +243,10 @@ public class LocalRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Check that all modules are installed
installed = repo.list();
@@ -293,10 +266,10 @@ public class LocalRepositoryTest {
repo.uninstall(mai);
// MODULE_UNINSTALLED should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(uninstallEventExists(repo, mai));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(ec.uninstallEventExists(repo, mai));
installed = repo.list();
check(installed.size() == 1);
@@ -320,10 +293,10 @@ public class LocalRepositoryTest {
println("LocalRepoModuleC mai: " + mai);
// MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, mai));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, mai));
+ check(!ec.uninstallEventExists(repo, null));
installed = repo.list();
check(installed.size() == 2);
@@ -347,10 +320,10 @@ public class LocalRepositoryTest {
check(repo.find(mai.getName()) == null);
// MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(uninstallEventExists(repo, deleteMe));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(ec.uninstallEventExists(repo, deleteMe));
// Verify that updating a module works
JamBuilder jb = new JamBuilder(
@@ -362,10 +335,10 @@ public class LocalRepositoryTest {
runModule(repo, "LocalRepoModuleD", "foo");
// MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, mai));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, mai));
+ check(!ec.uninstallEventExists(repo, null));
// Wait a bit before overwriting the just-created JAM
Thread.currentThread().sleep(1000);
@@ -377,10 +350,10 @@ public class LocalRepositoryTest {
repo.reload();
// Both MODULE_UNINSTALLED and MODULE_INSTALLED events should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, null));
- check(uninstallEventExists(repo, mai));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, null));
+ check(ec.uninstallEventExists(repo, mai));
runModule(repo, "LocalRepoModuleD", "bar");
@@ -479,18 +452,15 @@ public class LocalRepositoryTest {
check (md == null);
// Clear event queues for the tests afterwards
- initEventQueue.clear();
- shutdownEventQueue.clear();
- installEventQueue.clear();
- uninstallEventQueue.clear();
+ ec.clear();
repo.shutdown();
// REPOSITORY_SHUTDOWN event should be fired.
- check(!initializeEventExists(repo));
- check(shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Verify cannot initialize() after shutdown()
try {
@@ -501,10 +471,10 @@ public class LocalRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// When not debugging and there are no failures, remove test dirs
if (!debug && failed == 0) {
@@ -515,10 +485,10 @@ public class LocalRepositoryTest {
repo.shutdown(); // sic: multiple shutdowns are OK
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
}
}
@@ -554,80 +524,6 @@ public class LocalRepositoryTest {
check(methodName.equals(rc));
}
pass();
- }
-
- static boolean initializeEventExists(Repository repo) throws Exception {
- // Poll REPOSITORY_INITIALIZED event
- //
- RepositoryEvent evt = initEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean shutdownEventExists(Repository repo) throws Exception {
- // Poll REPOSITORY_SHUTDOWN event
- //
- RepositoryEvent evt = shutdownEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean installEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
- // Poll MODULE_INSTALLED event
- //
- RepositoryEvent evt = installEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.MODULE_INSTALLED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- if (mai != null && evt.getModuleArchiveInfo() != mai) {
- throw new Exception("Unexpected repository event for: " + evt.getModuleArchiveInfo());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean uninstallEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
- // Poll MODULE_UNINSTALLED event
- //
- RepositoryEvent evt = uninstallEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.MODULE_UNINSTALLED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- if (mai != null && evt.getModuleArchiveInfo() != mai) {
- throw new Exception("Unexpected repository event for: " + evt.getModuleArchiveInfo());
- }
- return true;
- } else {
- return false;
- }
}
static List<ModuleDefinition> findModuleDefsInRepository(Repository r) {
--- a/test/java/module/repository/RepositoryTest.java Fri Apr 11 08:27:13 2008 -0700
+++ b/test/java/module/repository/RepositoryTest.java Thu Apr 17 15:26:01 2008 -0700
@@ -24,34 +24,17 @@ import java.io.*;
import java.io.*;
import java.module.*;
import java.net.URL;
-import java.util.concurrent.*;
import sun.module.repository.RepositoryConfig;
/**
* @test RepositoryTest
* @summary Test various Repository methods
- * @compile -XDignore.symbol.file RepositoryTest.java
+ * @compile -XDignore.symbol.file RepositoryTest.java EventChecker.java
* @run main RepositoryTest
*/
public class RepositoryTest {
public static void realMain(String args[]) throws Throwable {
-
- // Setup repository listener
- final BlockingQueue<RepositoryEvent> initEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- final BlockingQueue<RepositoryEvent> shutdownEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- RepositoryListener repositoryListener = new RepositoryListener() {
- public void handleEvent(RepositoryEvent e) {
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- initEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- shutdownEventQueue.add(e);
- }
- }
- };
- Repository.addRepositoryListener(repositoryListener);
+ EventChecker ec = new EventChecker();
// Create a new repository.
File src = new File(".").getCanonicalFile();
@@ -64,20 +47,7 @@ public class RepositoryTest {
check(rep.getSourceLocation().equals(src.toURI().toURL()));
check(rep.getModuleSystem() == ModuleSystem.getDefault());
- // Poll REPOSITORY_INITIALIZED event
- //
- RepositoryEvent evt = initEventQueue.poll(5L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != rep) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- pass();
- } else {
- fail();
- }
+ check(ec.initializeEventExists(rep));
Repository bsRep = Repository.getBootstrapRepository();
check(bsRep.getParent() == null);
@@ -90,23 +60,9 @@ public class RepositoryTest {
rep.shutdown();
- // Poll REPOSITORY_SHUTDOWN event
- //
- evt = shutdownEventQueue.poll(5L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != rep) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- pass();
- } else {
- fail();
- }
+ check(ec.shutdownEventExists(rep));
- initEventQueue.clear();
- shutdownEventQueue.clear();
+ ec.clear();
// Verify null arg checking
try {
@@ -119,8 +75,8 @@ public class RepositoryTest {
}
// No event should be fired
- check(initEventQueue.size() == 0);
- check(shutdownEventQueue.size() == 0);
+ check(!ec.initializeEventExists(rep));
+ check(!ec.shutdownEventExists(rep));
try {
rep = Modules.newLocalRepository(null, src);
@@ -132,8 +88,8 @@ public class RepositoryTest {
}
// No event should be fired
- check(initEventQueue.size() == 0);
- check(shutdownEventQueue.size() == 0);
+ check(!ec.initializeEventExists(rep));
+ check(!ec.shutdownEventExists(rep));
try {
rep = Modules.newLocalRepository(name, null);
@@ -145,33 +101,23 @@ public class RepositoryTest {
}
// No event should be fired
- check(initEventQueue.size() == 0);
- check(shutdownEventQueue.size() == 0);
+ check(!ec.initializeEventExists(rep));
+ check(!ec.shutdownEventExists(rep));
// Remove repository listener
- Repository.removeRepositoryListener(repositoryListener);
+ ec.end();
// Creates a new repository
rep = Modules.newLocalRepository(
RepositoryConfig.getSystemRepository(), name, src);
// No event should be sent to an already-removed repository listener
- evt = initEventQueue.poll(5L, TimeUnit.SECONDS);
- if (evt != null) {
- throw new Exception("Unexpected repository event: " + evt);
- } else {
- pass();
- }
+ check(!ec.initializeEventExists(rep));
rep.shutdown();
// No event should be sent to an already-removed repository listener
- evt = shutdownEventQueue.poll(5L, TimeUnit.SECONDS);
- if (evt != null) {
- throw new Exception("Unexpected repository event: " + evt);
- } else {
- pass();
- }
+ check(!ec.shutdownEventExists(rep));
}
--- a/test/java/module/repository/URLRepoInstallTest.java Fri Apr 11 08:27:13 2008 -0700
+++ b/test/java/module/repository/URLRepoInstallTest.java Thu Apr 17 15:26:01 2008 -0700
@@ -31,7 +31,6 @@ import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.*;
import sun.module.JamUtils;
import sun.module.repository.RepositoryConfig;
import sun.module.repository.RepositoryUtils;
@@ -39,7 +38,7 @@ import sun.module.repository.RepositoryU
/**
* @summary Test URLRepository.install on a file: - based URLRepository.
* @library ../tools
- * @compile -XDignore.symbol.file URLRepoInstallTest.java ../tools/JamBuilder.java
+ * @compile -XDignore.symbol.file URLRepoInstallTest.java EventChecker.java ../tools/JamBuilder.java
* @run main URLRepoInstallTest
*/
public class URLRepoInstallTest {
@@ -62,15 +61,7 @@ public class URLRepoInstallTest {
public static final String repoName = "testinstallrepo";
- // Setup repository listener
- static final BlockingQueue<RepositoryEvent> initEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> shutdownEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> installEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> uninstallEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
+ static final EventChecker ec = new EventChecker();
private static void println(String s) {
if (debug) System.err.println(s);
@@ -112,26 +103,6 @@ public class URLRepoInstallTest {
}
void runTest() throws Throwable {
-
- // Add repository listener
- RepositoryListener repositoryListener = new RepositoryListener() {
- public void handleEvent(RepositoryEvent e) {
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- initEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- shutdownEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.MODULE_INSTALLED) {
- installEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.MODULE_UNINSTALLED) {
- uninstallEventQueue.add(e);
- }
- }
- };
- Repository.addRepositoryListener(repositoryListener);
-
Map<String, String> config = new HashMap<String, String>();
config.put("sun.module.repository.URLRepository.cacheDirectory", repoDownloadDir.getAbsolutePath());
@@ -142,10 +113,10 @@ public class URLRepoInstallTest {
config);
// Only REPOSITORY_INITIALIZED event should be fired.
- check(initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Check install
ModuleArchiveInfo installedMAI = null;
@@ -157,10 +128,10 @@ public class URLRepoInstallTest {
}
// Only MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, installedMAI));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, installedMAI));
+ check(!ec.uninstallEventExists(repo, null));
// Check list(): should contain only the one module just installed
List<ModuleArchiveInfo> installed = repo.list();
@@ -213,10 +184,10 @@ public class URLRepoInstallTest {
pass();
// Only MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(uninstallEventExists(repo, installedMAI));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(ec.uninstallEventExists(repo, installedMAI));
} else {
fail("Could not uninstall " + installedMAI.getName());
}
@@ -317,88 +288,11 @@ public class URLRepoInstallTest {
check (md == null);
// Clear event queues for the tests afterwards
- initEventQueue.clear();
- shutdownEventQueue.clear();
- installEventQueue.clear();
- uninstallEventQueue.clear();
+ ec.clear();
if (failed == 0) {
repo.shutdown();
check(repoDownloadDir.list().length == 0);
- }
- }
-
- static boolean initializeEventExists(Repository repo) throws Exception {
- // Poll REPOSITORY_INITIALIZED event
- //
- RepositoryEvent evt = initEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean shutdownEventExists(Repository repo) throws Exception {
- // Poll REPOSITORY_SHUTDOWN event
- //
- RepositoryEvent evt = shutdownEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean installEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
- // Poll MODULE_INSTALLED event
- //
- RepositoryEvent evt = installEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.MODULE_INSTALLED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- if (mai != null && evt.getModuleArchiveInfo() != mai) {
- throw new Exception("Unexpected repository event for: " + evt.getModuleArchiveInfo());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean uninstallEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
- // Poll MODULE_UNINSTALLED event
- //
- RepositoryEvent evt = uninstallEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.MODULE_UNINSTALLED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- if (mai != null && evt.getModuleArchiveInfo() != mai) {
- throw new Exception("Unexpected repository event for: " + evt.getModuleArchiveInfo());
- }
- return true;
- } else {
- return false;
}
}
--- a/test/java/module/repository/URLRepositoryReloadTest.java Fri Apr 11 08:27:13 2008 -0700
+++ b/test/java/module/repository/URLRepositoryReloadTest.java Thu Apr 17 15:26:01 2008 -0700
@@ -42,7 +42,7 @@ import sun.module.repository.URLReposito
* @test URLRepositoryReloadTest.java
* @summary Test URLRepository reloading.
* @library ../tools
- * @compile -XDignore.symbol.file URLRepositoryReloadTest.java URLRepositoryTest.java URLRepositoryServer.java ../tools/JamBuilder.java
+ * @compile -XDignore.symbol.file URLRepositoryReloadTest.java URLRepositoryTest.java URLRepositoryServer.java EventChecker.java ../tools/JamBuilder.java
* @run main/othervm/timeout=600 URLRepositoryReloadTest
*/
public class URLRepositoryReloadTest extends URLRepositoryTest {
@@ -83,20 +83,20 @@ public class URLRepositoryReloadTest ext
fileBasedRepo.getSourceLocation(), repoConfig);
// Only REPOSITORY_INITIALIZED event should be fired.
- check(initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(!installEventExists(repoWork, null));
- check(!uninstallEventExists(repoWork, null));
+ check(ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(!ec.installEventExists(repoWork, null));
+ check(!ec.uninstallEventExists(repoWork, null));
Repository repoTest = Modules.newURLRepository(
RepositoryConfig.getSystemRepository(), "repoTest",
repo.getSourceLocation(), repoConfig);
// Only REPOSITORY_INITIALIZED event should be fired.
- check(initializeEventExists(repoTest));
- check(!shutdownEventExists(repoTest));
- check(!installEventExists(repoTest, null));
- check(!uninstallEventExists(repoTest, null));
+ check(ec.initializeEventExists(repoTest));
+ check(!ec.shutdownEventExists(repoTest));
+ check(!ec.installEventExists(repoTest, null));
+ check(!ec.uninstallEventExists(repoTest, null));
/*
* Check three cases of reload() [spec 6.2.6]
@@ -120,10 +120,10 @@ public class URLRepositoryReloadTest ext
check(repoWork.find("ModuleJamNew") != null);
// Only MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(installEventExists(repoWork, maiNew));
- check(!uninstallEventExists(repoWork, null));
+ check(!ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(ec.installEventExists(repoWork, maiNew));
+ check(!ec.uninstallEventExists(repoWork, null));
// Since repoTest and repoWork share the same filesytem structures, this
// works:
@@ -131,10 +131,10 @@ public class URLRepositoryReloadTest ext
check(repoTest.find("ModuleJamNew") != null);
// Only MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repoTest));
- check(!shutdownEventExists(repoTest));
- check(installEventExists(repoTest, null));
- check(!uninstallEventExists(repoTest, null));
+ check(!ec.initializeEventExists(repoTest));
+ check(!ec.shutdownEventExists(repoTest));
+ check(ec.installEventExists(repoTest, null));
+ check(!ec.uninstallEventExists(repoTest, null));
// (2) Existing module definition removed from source location
// Uninstall from repoWork...
@@ -143,10 +143,10 @@ public class URLRepositoryReloadTest ext
check(repoWork.find("ModuleJamNew") == null);
// Only MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(!installEventExists(repoWork, null));
- check(uninstallEventExists(repoWork, maiNew));
+ check(!ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(!ec.installEventExists(repoWork, null));
+ check(ec.uninstallEventExists(repoWork, maiNew));
// ... and as with case (1), this works due to shared filesystem
// structures.
@@ -154,10 +154,10 @@ public class URLRepositoryReloadTest ext
check(repoTest.find("ModuleJamNew") == null);
// Only MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repoTest));
- check(!shutdownEventExists(repoTest));
- check(!installEventExists(repoTest, null));
- check(uninstallEventExists(repoTest, null));
+ check(!ec.initializeEventExists(repoTest));
+ check(!ec.shutdownEventExists(repoTest));
+ check(!ec.installEventExists(repoTest, null));
+ check(ec.uninstallEventExists(repoTest, null));
// (3) Existing module definition replaced in source location
// Create a module in repoTest, make sure it operates as expected
@@ -172,10 +172,10 @@ public class URLRepositoryReloadTest ext
runModule(repoWork, "ModuleJamReplace", "foo");
// Only MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(installEventExists(repoWork, maiReplace));
- check(!uninstallEventExists(repoWork, null));
+ check(!ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(ec.installEventExists(repoWork, maiReplace));
+ check(!ec.uninstallEventExists(repoWork, null));
// Now reload repoTest: as with (1), the module should be available
repoTest.reload();
@@ -183,20 +183,20 @@ public class URLRepositoryReloadTest ext
runModule(repoTest, "ModuleJamReplace", "foo");
// Only MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repoTest));
- check(!shutdownEventExists(repoTest));
- check(installEventExists(repoTest, null));
- check(!uninstallEventExists(repoTest, null));
+ check(!ec.initializeEventExists(repoTest));
+ check(!ec.shutdownEventExists(repoTest));
+ check(ec.installEventExists(repoTest, null));
+ check(!ec.uninstallEventExists(repoTest, null));
// Now remove ModuleJamReplace from repoWork, create a new JAM for a
// module of the same name, and install it in repoWork
check(repoWork.uninstall(maiReplace));
// Only MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(!installEventExists(repoWork, null));
- check(uninstallEventExists(repoWork, maiReplace));
+ check(!ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(!ec.installEventExists(repoWork, null));
+ check(ec.uninstallEventExists(repoWork, maiReplace));
check(repoWork.find("ModuleJamReplace") == null);
jb.setMethod("bar");
@@ -208,10 +208,10 @@ public class URLRepositoryReloadTest ext
runModule(repoWork, "ModuleJamReplace", "bar");
// Only MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(installEventExists(repoWork, maiReplace));
- check(!uninstallEventExists(repoWork, null));
+ check(!ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(ec.installEventExists(repoWork, maiReplace));
+ check(!ec.uninstallEventExists(repoWork, null));
// Now reload repoTest. Insofar as it is concerned, ModuleJamReplace has
// been replaced.
@@ -220,43 +220,43 @@ public class URLRepositoryReloadTest ext
runModule(repoTest, "ModuleJamReplace", "bar");
// MODULE_UNINSTALLED and MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repoTest));
- check(!shutdownEventExists(repoTest));
- check(installEventExists(repoTest, null));
- check(uninstallEventExists(repoTest, null));
+ check(!ec.initializeEventExists(repoTest));
+ check(!ec.shutdownEventExists(repoTest));
+ check(ec.installEventExists(repoTest, null));
+ check(ec.uninstallEventExists(repoTest, null));
ModuleArchiveInfo mai = repoWork.list().get(0);
check(repoWork.uninstall(mai));
// MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repoWork));
- check(!shutdownEventExists(repoWork));
- check(!installEventExists(repoWork, null));
- check(uninstallEventExists(repoWork, mai));
+ check(!ec.initializeEventExists(repoWork));
+ check(!ec.shutdownEventExists(repoWork));
+ check(!ec.installEventExists(repoWork, null));
+ check(ec.uninstallEventExists(repoWork, mai));
repoTest.reload();
// MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repoTest));
- check(!shutdownEventExists(repoTest));
- check(!installEventExists(repoTest, null));
- check(uninstallEventExists(repoTest, null));
+ check(!ec.initializeEventExists(repoTest));
+ check(!ec.shutdownEventExists(repoTest));
+ check(!ec.installEventExists(repoTest, null));
+ check(ec.uninstallEventExists(repoTest, null));
repoTest.shutdown();
// REPOSITORY_SHUTDOWN event should be fired.
- check(!initializeEventExists(repoTest));
- check(shutdownEventExists(repoTest));
- check(!installEventExists(repoTest, null));
- check(!uninstallEventExists(repoTest, null));
+ check(!ec.initializeEventExists(repoTest));
+ check(ec.shutdownEventExists(repoTest));
+ check(!ec.installEventExists(repoTest, null));
+ check(!ec.uninstallEventExists(repoTest, null));
repoWork.shutdown();
// REPOSITORY_SHUTDOWN event should be fired.
- check(!initializeEventExists(repoWork));
- check(shutdownEventExists(repoWork));
- check(!installEventExists(repoWork, null));
- check(!uninstallEventExists(repoWork, null));
+ check(!ec.initializeEventExists(repoWork));
+ check(ec.shutdownEventExists(repoWork));
+ check(!ec.installEventExists(repoWork, null));
+ check(!ec.uninstallEventExists(repoWork, null));
}
//--------------------- Infrastructure ---------------------------
--- a/test/java/module/repository/URLRepositoryTest.java Fri Apr 11 08:27:13 2008 -0700
+++ b/test/java/module/repository/URLRepositoryTest.java Thu Apr 17 15:26:01 2008 -0700
@@ -34,7 +34,6 @@ import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.jar.JarFile;
-import java.util.concurrent.*;
import sun.module.JamUtils;
import sun.module.repository.MetadataXMLWriter;
import sun.module.repository.RepositoryConfig;
@@ -45,10 +44,10 @@ import sun.module.repository.URLReposito
* @test URLRepositoryTest.java
* @summary Test URLRepository via file: and http: protocols.
* @library ../tools
- * @compile -XDignore.symbol.file URLRepositoryTest.java URLRepositoryServer.java ../tools/JamBuilder.java
+ * @compile -XDignore.symbol.file URLRepositoryTest.java EventChecker.java URLRepositoryServer.java ../tools/JamBuilder.java
* @run main/othervm/timeout=600 URLRepositoryTest
*/
-public class URLRepositoryTest {
+public class URLRepositoryTest {
static final boolean debug = System.getProperty("repository.debug") != null;
// Directory for repository's source
@@ -69,22 +68,13 @@ public class URLRepositoryTest {
// Configuration of the URLRepository.
Map<String, String> repoConfig;
- // Setup repository listener
- static final BlockingQueue<RepositoryEvent> initEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> shutdownEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> installEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
- static final BlockingQueue<RepositoryEvent> uninstallEventQueue =
- new LinkedBlockingQueue<RepositoryEvent>();
+ final EventChecker ec = new EventChecker();
static public void realMain(String[] args) throws Throwable {
new URLRepositoryTest().runMain(args);
}
void runMain(String[] args) throws Throwable {
-
// Enables shadow file copies in the repository if we're running
// on Windows. This is to prevent file locking in the
// source location.
@@ -122,25 +112,6 @@ public class URLRepositoryTest {
// These configs are so that this test will run on any platform
repoConfig.put("sun.module.repository.URLRepository.test.platform", "windows");
repoConfig.put("sun.module.repository.URLRepository.test.arch", "i586");
-
- // Add repository listener
- RepositoryListener repositoryListener = new RepositoryListener() {
- public void handleEvent(RepositoryEvent e) {
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- initEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- shutdownEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.MODULE_INSTALLED) {
- installEventQueue.add(e);
- }
- if (e.getType() == RepositoryEvent.Type.MODULE_UNINSTALLED) {
- uninstallEventQueue.add(e);
- }
- }
- };
- Repository.addRepositoryListener(repositoryListener);
// Running the file-based test first creates the filesystem layout of
// JAM, metadata, and repository-metadata.xml files required by an
@@ -210,10 +181,10 @@ public class URLRepositoryTest {
RepositoryConfig.getSystemRepository(), "test", url, repoConfig);
// Only REPOSITORY_INITIALIZED event should be fired.
- check(initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
if (fileBased) {
fileBasedRepo = (URLRepository) repo;
@@ -245,10 +216,10 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(r2));
- check(!shutdownEventExists(r2));
- check(!installEventExists(r2, null));
- check(!uninstallEventExists(r2, null));
+ check(!ec.initializeEventExists(r2));
+ check(!ec.shutdownEventExists(r2));
+ check(!ec.installEventExists(r2, null));
+ check(!ec.uninstallEventExists(r2, null));
// Verify the repository is active and reloadable
check(repo.isActive());
@@ -263,10 +234,10 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Check that find() and list() return nothing from repo since, the
// repository's source dir does not exist. Do this only for fileBased
@@ -298,10 +269,10 @@ public class URLRepositoryTest {
check(mai != null);
// MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(workRepo));
- check(!shutdownEventExists(workRepo));
- check(installEventExists(workRepo, mai));
- check(!uninstallEventExists(workRepo, null));
+ check(!ec.initializeEventExists(workRepo));
+ check(!ec.shutdownEventExists(workRepo));
+ check(ec.installEventExists(workRepo, mai));
+ check(!ec.uninstallEventExists(workRepo, null));
}
if (!fileBased) {
@@ -309,11 +280,11 @@ public class URLRepositoryTest {
// MODULE_UNINSTALLED and MODULE_INSTALLED events
// should be fired for the existing modules
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventQueue.size() == jamFiles.size());
- check(!uninstallEventExists(repo, null));
- installEventQueue.clear();
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.getInstallEventQueueSize() == jamFiles.size());
+ check(!ec.uninstallEventExists(repo, null));
+ ec.clear();
}
List<ModuleArchiveInfo> installed = repo.list();
@@ -327,21 +298,21 @@ public class URLRepositoryTest {
check(workRepo.uninstall(mai));
// MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(workRepo));
- check(!shutdownEventExists(workRepo));
- check(!installEventExists(workRepo, null));
- check(uninstallEventExists(workRepo, mai));
+ check(!ec.initializeEventExists(workRepo));
+ check(!ec.shutdownEventExists(workRepo));
+ check(!ec.installEventExists(workRepo, null));
+ check(ec.uninstallEventExists(workRepo, mai));
}
if (!fileBased) {
repo.reload();
// MODULE_UNINSTALLED and MODULE_INSTALLED events
// should be fired for the existing modules
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(uninstallEventQueue.size() == jamFiles.size());
- uninstallEventQueue.clear();
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(ec.getUninstallEventQueueSize() == jamFiles.size());
+ ec.clear();
}
List<ModuleArchiveInfo> installed = repo.list();
@@ -395,10 +366,10 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Check that one more module is listed, but the same number
// is findable.
@@ -412,10 +383,10 @@ public class URLRepositoryTest {
check(mai != null);
// MODULE_INSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(installEventExists(repo, mai));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(ec.installEventExists(repo, mai));
+ check(!ec.uninstallEventExists(repo, null));
check(repo.list().size() == numInstalled + 1);
check(repo.findAll().size() == numFound);
@@ -440,10 +411,10 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Non-existent file URL should fail
try {
@@ -466,10 +437,10 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
}
void checkUninstall(Repository repo, boolean fileBased) throws Throwable {
@@ -489,10 +460,10 @@ public class URLRepositoryTest {
check(repo.uninstall(mai));
// MODULE_UNINSTALLED event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(uninstallEventExists(repo, mai));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(ec.uninstallEventExists(repo, mai));
break;
}
@@ -508,10 +479,10 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
}
List<ModuleDefinition> bootDefns = Repository.getBootstrapRepository().findAll();
@@ -543,10 +514,10 @@ public class URLRepositoryTest {
repo.shutdown();
// REPOSITORY_SHUTDOWN event should be fired.
- check(!initializeEventExists(repo));
- check(shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
// Verify cannot initialize() after shutdown()
try {
@@ -557,18 +528,18 @@ public class URLRepositoryTest {
}
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
repo.shutdown(); // sic: multiple shutdowns are OK
// No event should be fired.
- check(!initializeEventExists(repo));
- check(!shutdownEventExists(repo));
- check(!installEventExists(repo, null));
- check(!uninstallEventExists(repo, null));
+ check(!ec.initializeEventExists(repo));
+ check(!ec.shutdownEventExists(repo));
+ check(!ec.installEventExists(repo, null));
+ check(!ec.uninstallEventExists(repo, null));
}
}
@@ -576,80 +547,6 @@ public class URLRepositoryTest {
println(msg + ": ");
for (ModuleArchiveInfo mai : maiInfos) {
println("=mai: " + mai);
- }
- }
-
- static boolean initializeEventExists(Repository repo) throws Exception {
- // Poll REPOSITORY_INITIALIZED event
- //
- RepositoryEvent evt = initEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean shutdownEventExists(Repository repo) throws Exception {
- // Poll REPOSITORY_SHUTDOWN event
- //
- RepositoryEvent evt = shutdownEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean installEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
- // Poll MODULE_INSTALLED event
- //
- RepositoryEvent evt = installEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.MODULE_INSTALLED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- if (mai != null && evt.getModuleArchiveInfo() != mai) {
- throw new Exception("Unexpected repository event for: " + evt.getModuleArchiveInfo());
- }
- return true;
- } else {
- return false;
- }
- }
-
- static boolean uninstallEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
- // Poll MODULE_UNINSTALLED event
- //
- RepositoryEvent evt = uninstallEventQueue.poll(2L, TimeUnit.SECONDS);
- if (evt != null) {
- if (evt.getType() != RepositoryEvent.Type.MODULE_UNINSTALLED) {
- throw new Exception("Unexpected repository event type: " + evt.getType());
- }
- if (evt.getSource() != repo) {
- throw new Exception("Unexpected repository event from: " + evt.getSource());
- }
- if (mai != null && evt.getModuleArchiveInfo() != mai) {
- throw new Exception("Unexpected repository event for: " + evt.getModuleArchiveInfo());
- }
- return true;
- } else {
- return false;
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/module/repository/EventChecker.java Thu Apr 17 15:26:01 2008 -0700
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.module.*;
+import java.util.concurrent.*;
+
+/**
+ * Provides a means of checking that events are received within a certain
+ * period of time.
+ */
+public class EventChecker {
+ private final long timeout;
+
+ private final RepositoryListener repositoryListener;
+
+ private final BlockingQueue<RepositoryEvent> initEventQueue =
+ new LinkedBlockingQueue<RepositoryEvent>();
+ private final BlockingQueue<RepositoryEvent> shutdownEventQueue =
+ new LinkedBlockingQueue<RepositoryEvent>();
+ private final BlockingQueue<RepositoryEvent> installEventQueue =
+ new LinkedBlockingQueue<RepositoryEvent>();
+ private final BlockingQueue<RepositoryEvent> uninstallEventQueue =
+ new LinkedBlockingQueue<RepositoryEvent>();
+
+ EventChecker() {
+ this(100L);
+ }
+
+ EventChecker(long timeout) {
+ this.timeout = timeout;
+
+ repositoryListener = new RepositoryListener() {
+ public void handleEvent(RepositoryEvent e) {
+ if (e.getType() == RepositoryEvent.Type.REPOSITORY_INITIALIZED) {
+ initEventQueue.add(e);
+ }
+ if (e.getType() == RepositoryEvent.Type.REPOSITORY_SHUTDOWN) {
+ shutdownEventQueue.add(e);
+ }
+ if (e.getType() == RepositoryEvent.Type.MODULE_INSTALLED) {
+ installEventQueue.add(e);
+ }
+ if (e.getType() == RepositoryEvent.Type.MODULE_UNINSTALLED) {
+ uninstallEventQueue.add(e);
+ }
+ }
+ };
+ Repository.addRepositoryListener(repositoryListener);
+ }
+
+ void clear() {
+ // Hope 10 seconds is long enough for outstanding events to arrive.
+ sleep(1000L * 10);
+
+ initEventQueue.clear();
+ shutdownEventQueue.clear();
+ installEventQueue.clear();
+ uninstallEventQueue.clear();
+ }
+
+ int getInstallEventQueueSize() {
+ sleep(timeout);
+ return installEventQueue.size();
+ }
+
+ int getUninstallEventQueueSize() {
+ sleep(timeout);
+ return uninstallEventQueue.size();
+ }
+
+ void end() {
+ Repository.removeRepositoryListener(repositoryListener);
+ }
+
+ boolean initializeEventExists(Repository repo) throws Exception {
+ return eventExists(initEventQueue, RepositoryEvent.Type.REPOSITORY_INITIALIZED, repo, null);
+ }
+
+ boolean shutdownEventExists(Repository repo) throws Exception {
+ return eventExists(shutdownEventQueue, RepositoryEvent.Type.REPOSITORY_SHUTDOWN, repo, null);
+ }
+
+ boolean installEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
+ return eventExists(installEventQueue, RepositoryEvent.Type.MODULE_INSTALLED, repo, mai);
+ }
+
+ boolean uninstallEventExists(Repository repo, ModuleArchiveInfo mai) throws Exception {
+ return eventExists(uninstallEventQueue, RepositoryEvent.Type.MODULE_UNINSTALLED, repo, mai);
+ }
+
+ boolean eventExists(
+ BlockingQueue<RepositoryEvent> q,
+ RepositoryEvent.Type t,
+ Repository repo,
+ ModuleArchiveInfo mai) throws Exception {
+
+ RepositoryEvent evt = q.poll(timeout, TimeUnit.MILLISECONDS);
+ if (evt != null) {
+ if (evt.getType() != t) {
+ throw new Exception("Expected event type: " + t + " but got " + evt.getType());
+ }
+ if (evt.getSource() != repo) {
+ throw new Exception("Unexpected " + t + " event from: " + evt.getSource());
+ }
+ if (mai != null && evt.getModuleArchiveInfo() != mai) {
+ throw new Exception("Unexpected " + t + " event for: " + evt.getModuleArchiveInfo());
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ void sleep(long timeout) {
+ try {
+ Thread.sleep(timeout);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("clear interrupted");
+ }
+ }
+}