use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class InstrumentationTest method testMultipleInstruments.
/*
* Test onCreate and onDispose invocations for multiple instrument instances.
*/
@Test
public void testMultipleInstruments() throws IOException {
// initialize
run("");
MultipleInstanceInstrument.onCreateCounter = 0;
MultipleInstanceInstrument.onDisposeCounter = 0;
MultipleInstanceInstrument.constructor = 0;
Instrument instrument1 = engine.getInstruments().get("testMultipleInstruments");
// enabled
instrument1.lookup(Object.class);
Assert.assertEquals(1, MultipleInstanceInstrument.constructor);
Assert.assertEquals(1, MultipleInstanceInstrument.onCreateCounter);
Assert.assertEquals(0, MultipleInstanceInstrument.onDisposeCounter);
Instrument instrument2 = engine.getInstruments().get("testMultipleInstruments");
// the same enabled
instrument2.lookup(Object.class);
Assert.assertEquals(1, MultipleInstanceInstrument.constructor);
Assert.assertEquals(1, MultipleInstanceInstrument.onCreateCounter);
Assert.assertEquals(0, MultipleInstanceInstrument.onDisposeCounter);
engine.close();
engine = null;
Assert.assertEquals(1, MultipleInstanceInstrument.constructor);
Assert.assertEquals(1, MultipleInstanceInstrument.onCreateCounter);
Assert.assertEquals(1, MultipleInstanceInstrument.onDisposeCounter);
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class InstrumentationTest method testAccessLanguages.
@Test
public void testAccessLanguages() {
Instrument instrument = engine.getInstruments().get("testAccessInstruments");
TestAccessInstruments access = instrument.lookup(TestAccessInstruments.class);
LanguageInfo info = access.env.getLanguages().get(InstrumentationTestLanguage.ID);
assertNotNull(info);
assertTrue(info.getMimeTypes().contains(InstrumentationTestLanguage.MIME_TYPE));
assertEquals("InstrumentTestLang", info.getName());
assertEquals("2.0", info.getVersion());
assertNotNull(access.env.lookup(info, SpecialService.class));
assertEquals(InstrumentationTestLanguage.FILENAME_EXTENSION, access.env.lookup(info, SpecialService.class).fileExtension());
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class InstrumentationTest method testQueryTags1.
/*
* Test behavior of queryTags when used with instruments
*/
@Test
public void testQueryTags1() throws IOException {
Instrument instrument = engine.getInstruments().get("testIsNodeTaggedWith1");
Instrumenter instrumenter = instrument.lookup(Instrumenter.class);
TestIsNodeTaggedWith1.expressionNode = null;
TestIsNodeTaggedWith1.statementNode = null;
Assert.assertTrue(instrumenter.queryTags(new Node() {
}).isEmpty());
run("STATEMENT(EXPRESSION)");
assertTags(instrumenter.queryTags(TestIsNodeTaggedWith1.expressionNode), InstrumentationTestLanguage.EXPRESSION);
assertTags(instrumenter.queryTags(TestIsNodeTaggedWith1.statementNode), InstrumentationTestLanguage.STATEMENT);
try {
instrumenter.queryTags(null);
Assert.fail();
} catch (NullPointerException e) {
}
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class InstrumentationTest method forgetsToRegisterADeclaredService.
@Test
public void forgetsToRegisterADeclaredService() throws Exception {
Instrument handle = engine.getInstruments().get("testBrokenRegistration");
assertNotNull(handle);
Runnable r = handle.lookup(Runnable.class);
assertNull("The service isn't there", r);
if (!err.toString().contains("declares service java.lang.Runnable but doesn't register it")) {
fail(err.toString());
}
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class InstrumentationTest method queryInstrumentsAfterDisposeDoesnotEnable.
// IllegalStateException: Engine is already closed
@Test(expected = IllegalStateException.class)
public void queryInstrumentsAfterDisposeDoesnotEnable() throws Exception {
engine = Engine.newBuilder().err(err).build();
engine.close();
Runnable start = null;
for (Instrument instr : engine.getInstruments().values()) {
assertFalse("Instrument is disabled", isInitialized(instr));
Runnable r = instr.lookup(Runnable.class);
if (r != null) {
start = r;
start.run();
assertTrue("Now enabled: " + instr, isCreated(instr));
}
assertFalse("Instrument left disabled", isInitialized(instr));
}
assertNull("No Runnable found", start);
}
Aggregations