コード例 #1
0
 @Ignore("for performance testing purpose")
 @Test
 public void testPerf() throws ScriptException, OperationException {
   long start = System.currentTimeMillis();
   for (int i = 0; i < 500; i++) {
     scriptingService.run(scriptingService.getJSWrapper(), session);
   }
   long end = System.currentTimeMillis();
   System.err.println("DEBUG: Logic A toke " + (end - start) + " " + "MilliSeconds");
 }
コード例 #2
0
  @Test
  public void testAutomationCtxSharing() throws Exception {
    org.junit.Assert.assertNotNull(scriptingService);

    InputStream stream = this.getClass().getResourceAsStream("/shareAutomationContext.js");
    org.junit.Assert.assertNotNull(stream);
    scriptingService.run(stream, session);
    assertEquals("OK" + System.lineSeparator(), outContent.toString());
  }
コード例 #3
0
  @Test
  public void testIsolationScriptCtx() throws Exception {
    org.junit.Assert.assertNotNull(scriptingService);

    InputStream stream = this.getClass().getResourceAsStream("/scriptCtxIsolation.js");
    org.junit.Assert.assertNotNull(stream);
    scriptingService.run(stream, session);
    assertEquals("[object Object]" + System.lineSeparator(), outContent.toString());

    stream = this.getClass().getResourceAsStream("/scriptCtxIsolation.js");
    org.junit.Assert.assertNotNull(stream);
    scriptingService.run(stream, session);
    // Failing returning "[object Object]\n" + "toto\n"
    assertEquals(
        "[object Object]"
            + System.lineSeparator()
            + "[object "
            + "Object]"
            + System.lineSeparator(),
        outContent.toString());
  }
コード例 #4
0
  @Test
  public void serviceShouldBeDeclared() throws Exception {
    ScriptEngineManager engineManager = new ScriptEngineManager();
    ScriptEngine engine =
        engineManager.getEngineByName(AutomationScriptingConstants.NASHORN_ENGINE);
    assertNotNull(engine);

    InputStream stream = this.getClass().getResourceAsStream("/checkWrapper.js");
    assertNotNull(stream);
    engine.eval(scriptingService.getJSWrapper());
    engine.eval(IOUtils.toString(stream));
    assertEquals("Hello" + System.lineSeparator(), outContent.toString());
  }
コード例 #5
0
  @Ignore("for performance testing purpose")
  @Test
  public void checkScriptingEngineCostAndIsolation() throws Exception {

    InputStream stream = this.getClass().getResourceAsStream("/QuickScript.js");
    assertNotNull(stream);
    String js = IOUtils.toString(stream);

    // long t0 = System.currentTimeMillis();
    scriptingService.run(getScriptWithRandomContent(js), session);
    // long t1 = System.currentTimeMillis();
    // System.err.println("Initial Exec = " + (t1-t0));

    // t0 = System.currentTimeMillis();
    scriptingService.run(getScriptWithRandomContent(js), session);
    // t1 = System.currentTimeMillis();
    // System.err.println("Second Exec = " + (t1-t0));

    int nbIter = 50;

    // long t = t1 - t0;
    for (int i = 0; i < nbIter; i++) {
      // t0 = System.currentTimeMillis();
      scriptingService.run(getScriptWithRandomContent(js), session);
      // t1 = System.currentTimeMillis();
      // System.err.println("Exec = " + (t1-t0));
      // t += t1 - t0;
    }

    // System.err.println("AvgExec = " + (t/(nbIter + 1.0)));

    // now we check isolation

    stream = this.getClass().getResourceAsStream("/checkIsolation.js");
    assertNotNull(stream);
    String check = IOUtils.toString(stream);

    scriptingService.run(check, session);

    scriptingService.run(check, session);

    scriptingService.run("Document.Fetch=\"toto\";", session);

    scriptingService.run(check, session);
  }