Exemplo n.º 1
0
  private static void bigBlobCompile() throws DroolsParserException, IOException, Exception {
    StringBuilder buf = new StringBuilder();
    buf.append(getHeader());

    for (int i = 0; i < RULE_COUNT; i++) {
      String name = "x" + i;
      int status = i;

      String r = getTemplate1(name, status);
      buf.append(r);
    }

    /* love you */ long time = System.currentTimeMillis();

    DrlParser ps = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr pkg = ps.parse(new StringReader(buf.toString()));

    System.err.println("Time taken for parsing: " + (System.currentTimeMillis() - time));

    time = System.currentTimeMillis();
    PackageBuilder b = new PackageBuilder();
    b.addPackage(pkg);
    assertFalse(b.getErrors().toString(), b.hasErrors());

    System.err.println("Time taken for compiling: " + (System.currentTimeMillis() - time));
    time = System.currentTimeMillis();

    Package p = b.getPackage();
    RuleBase rb = RuleBaseFactory.newRuleBase();

    rb.addPackage(p);

    System.err.println("Time taken rete building: " + (System.currentTimeMillis() - time));

    File f = new File("foo.rulebase");
    if (f.exists()) f.delete();

    time = System.currentTimeMillis();
    ObjectOutput out = new DroolsObjectOutputStream(new FileOutputStream(f));
    out.writeObject(rb);
    out.flush();
    out.close();
    System.err.println("Time taken serializing rulebase: " + (System.currentTimeMillis() - time));

    time = System.currentTimeMillis();
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(f));
    RuleBase rb_ = (RuleBase) in.readObject();
    System.err.println(
        "Time taken de-serializing rulebase: " + (System.currentTimeMillis() - time));
  }
Exemplo n.º 2
0
 @Test
 public void testDebug() throws Exception {
   String rule =
       "package com.sample; dialect \"mvel\" rule myRule when then\n System.out.println( \"test\" ); end";
   PackageBuilder builder = new PackageBuilder();
   DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
   PackageDescr packageDescr = parser.parse(rule);
   RuleDescr ruleDescr = packageDescr.getRules().get(0);
   builder = new PackageBuilder();
   builder.addPackage(packageDescr);
   Package pkg = builder.getPackage();
   MVELConsequence consequence = (MVELConsequence) pkg.getRule("myRule").getConsequence();
   String sourceName = ((CompiledExpression) consequence.getCompExpr()).getSourceName();
   System.out.println(sourceName);
   String ruleName = ruleDescr.getNamespace() + "." + ruleDescr.getClassName();
   System.out.println(ruleName);
   assertEquals(sourceName, ruleName);
 }