use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class TruthMaintenanceTest method testTMSWithEquivalentSubclasses.
@Test(timeout = 10000)
public void testTMSWithEquivalentSubclasses() {
String droolsSource = "package project_java_rules2_xxx \n" + "import " + HashBrown.class.getCanonicalName() + "; \n" + "declare Foo id : int @key end \n\n" + "rule Zero \n" + "when \n" + " $s : String( this == \"go\" ) \n" + "then \n" + " insertLogical( new HashBrown(1) ); \n" + "end \n" + "rule Init \n" + "when \n" + "then \n" + " insertLogical( new HashBrown(7) ); \n" + "end \n";
// ///////////////////////////////////
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(new ByteArrayResource(droolsSource.getBytes()), ResourceType.DRL);
assertFalse(kBuilder.getErrors().toString(), kBuilder.hasErrors());
final RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);
conf.setSequentialAgenda(RuleBaseConfiguration.SequentialAgenda.SEQUENTIAL);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
kbase.addPackages(kBuilder.getKnowledgePackages());
KieSession session = kbase.newKieSession();
session.fireAllRules();
FactHandle handle = session.insert(new HashBlack(1));
session.insert("go");
session.fireAllRules();
assertNotNull(((DefaultFactHandle) handle).getEqualityKey());
session.dispose();
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class ProtobufMarshaller method unmarshall.
public StatefulKnowledgeSession unmarshall(final InputStream stream, KieSessionConfiguration config, Environment environment) throws IOException, ClassNotFoundException {
if (config == null) {
config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
}
if (environment == null) {
environment = KieServices.get().newEnvironment();
}
MarshallerReaderContext context = new MarshallerReaderContext(stream, (KnowledgeBaseImpl) kbase, RuleBaseNodes.getNodeMap((KnowledgeBaseImpl) kbase), this.strategyStore, TIMER_READERS, this.marshallingConfig.isMarshallProcessInstances(), this.marshallingConfig.isMarshallWorkItems(), environment);
int id = ((KnowledgeBaseImpl) this.kbase).nextWorkingMemoryCounter();
RuleBaseConfiguration conf = ((KnowledgeBaseImpl) this.kbase).getConfiguration();
StatefulKnowledgeSessionImpl session = ProtobufInputMarshaller.readSession(context, id, environment, (SessionConfiguration) config, initializer);
context.close();
if (((SessionConfiguration) config).isKeepReference()) {
((KnowledgeBaseImpl) this.kbase).addStatefulSession(session);
}
return session;
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method bindRuleBase.
protected void bindRuleBase(InternalKnowledgeBase kBase, InternalAgenda agenda, boolean initInitFactHandle) {
this.kBase = kBase;
this.nodeMemories = new ConcurrentNodeMemories(kBase, DEFAULT_RULE_UNIT);
this.pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
if (agenda == null) {
this.agenda = kBase.getConfiguration().getComponentFactory().getAgendaFactory().createAgenda(kBase);
} else {
this.agenda = agenda;
}
this.agenda.setWorkingMemory(this);
RuleBaseConfiguration conf = kBase.getConfiguration();
this.sequential = conf.isSequential();
initDefaultEntryPoint();
updateEntryPointsCache();
if (initInitFactHandle) {
this.initialFactHandle = initInitialFact(kBase, null);
}
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testProgrammaticPropertiesFile.
@Test
public void testProgrammaticPropertiesFile() {
RuleBaseConfiguration cfg = new RuleBaseConfiguration();
assertEquals(true, cfg.isIndexLeftBetaMemory());
Properties properties = new Properties();
properties.setProperty("drools.indexLeftBetaMemory", "false");
cfg = new RuleBaseConfiguration(properties);
assertEquals(false, cfg.isIndexLeftBetaMemory());
System.getProperties().remove("drools.indexLeftBetaMemory");
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testSequential.
@Test
public void testSequential() {
Properties properties = new Properties();
properties.setProperty("drools.sequential", "false");
RuleBaseConfiguration cfg = new RuleBaseConfiguration(properties);
assertFalse(cfg.isSequential());
assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
properties = new Properties();
properties.setProperty("drools.sequential.agenda", "sequential");
properties.setProperty("drools.sequential", "true");
cfg = new RuleBaseConfiguration(properties);
assertTrue(cfg.isSequential());
assertEquals(SequentialAgenda.SEQUENTIAL, cfg.getSequentialAgenda());
properties = new Properties();
properties.setProperty("drools.sequential.agenda", "dynamic");
properties.setProperty("drools.sequential", "true");
cfg = new RuleBaseConfiguration(properties);
assertTrue(cfg.isSequential());
assertEquals(SequentialAgenda.DYNAMIC, cfg.getSequentialAgenda());
assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
}
Aggregations