A simple cross-isolate synchronization mechanism.
Handles the simple case of synchronizing between two
isolates, performing "master" and "slave" roles.
This is useful for cross-isolate unit testing.
This is a utility class, containing only static methods.
No instances of this class are ever created.
This class must be initialized once (presumably the by master),
by calling init(), before starting the slave isolate. The master isolate
can call awaitReady() to wait for the slave isolate to become ready.
The slave isolate performs whatever initialization and testing it wants and
then calls pause(). This blocks the slave and
unblocks the master's call to awaitReady(), giving the master the
opportunity to inspect the slave's state. The master can then call
signalContinue() to unblock the slave. Finally, the fini() call will
destroy the shared objects created by init().
Example code for master isolate:
void testAnotherIsolate() {
IsolateSynch.init();
Isolate iso = new Isolate(start_class, args);
iso.start();
IsolateSynch.awaitReady();
// assertions can be made safely here about the state of the slave
IsolateSynch.signalContinue();
IsolateSynch.fini();
}
Example code for slave isolate:
public static void main(Strings args[]) {
// perform initialization and execute code under test
IsolateSynch.pause();
// perform any cleanup here
}
|