use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class XStreamXMLTest method testGetFactHandlesExecutionResults.
@Test
public void testGetFactHandlesExecutionResults() {
final Message msg = new Message("Hello World!");
final FactHandle msgHandle = new DefaultFactHandle(1, null, 10, 10, 20, msg);
final Message msg2 = new Message("Hello World again!");
final FactHandle msgHandle2 = new DefaultFactHandle(2, null, 10, 10, 20, msg2);
List<FactHandle> factHandleList = new ArrayList<FactHandle>();
factHandleList.add(msgHandle);
factHandleList.add(msgHandle2);
HashMap<String, Object> factHandles = new LinkedHashMap<String, Object>();
ExecutionResultImpl executionResult = new ExecutionResultImpl();
executionResult.setFactHandles(factHandles);
HashMap<String, Object> results = new LinkedHashMap<String, Object>();
results.put("facts", factHandleList);
executionResult.setResults(results);
String xmlString = xstream.toXML(executionResult);
Assert.assertEquals("<execution-results>\n" + " <result identifier=\"facts\">\n" + " <list>\n" + " <fact-handle external-form=\"0:1:10:10:20:null:NON_TRAIT:org.drools.core.runtime.help.impl.XStreamXMLTest$Message\"/>\n" + " <fact-handle external-form=\"0:2:10:10:20:null:NON_TRAIT:org.drools.core.runtime.help.impl.XStreamXMLTest$Message\"/>\n" + " </list>\n" + " </result>\n" + "</execution-results>", xmlString);
ExecutionResultImpl executionResult2 = (ExecutionResultImpl) xstream.fromXML(xmlString);
Assert.assertEquals(executionResult.getFactHandles().size(), executionResult2.getFactHandles().size());
Assert.assertEquals(executionResult.getResults().size(), executionResult2.getResults().size());
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class XStreamXMLTest method testExecutionResults.
@Test
public void testExecutionResults() {
final Message msg = new Message("Hello World!");
final FactHandle msgHandle = new DefaultFactHandle(1, null, 10, 10, 20, msg);
final Message msg2 = new Message("Hello World again!");
final FactHandle msgHandle2 = new DefaultFactHandle(2, null, 10, 10, 20, msg2);
HashMap<String, Object> factHandles = new LinkedHashMap<String, Object>();
factHandles.put("first", msgHandle);
factHandles.put("second", msgHandle2);
ExecutionResultImpl executionResult = new ExecutionResultImpl();
executionResult.setFactHandles(factHandles);
HashMap<String, Object> results = new LinkedHashMap<String, Object>();
results.put("message1", msg);
results.put("message2", msg2);
executionResult.setResults(results);
String xmlString = xstream.toXML(executionResult);
Assert.assertEquals("<execution-results>\n" + " <result identifier=\"message1\">\n" + " <org.drools.core.runtime.help.impl.XStreamXMLTest_-Message>\n" + " <msg>Hello World!</msg>\n" + " </org.drools.core.runtime.help.impl.XStreamXMLTest_-Message>\n" + " </result>\n" + " <result identifier=\"message2\">\n" + " <org.drools.core.runtime.help.impl.XStreamXMLTest_-Message>\n" + " <msg>Hello World again!</msg>\n" + " </org.drools.core.runtime.help.impl.XStreamXMLTest_-Message>\n" + " </result>\n" + " <fact-handle identifier=\"first\" external-form=\"0:1:10:10:20:null:NON_TRAIT:org.drools.core.runtime.help.impl.XStreamXMLTest$Message\"/>\n" + " <fact-handle identifier=\"second\" external-form=\"0:2:10:10:20:null:NON_TRAIT:org.drools.core.runtime.help.impl.XStreamXMLTest$Message\"/>\n" + "</execution-results>", xmlString);
ExecutionResultImpl executionResult2 = (ExecutionResultImpl) xstream.fromXML(xmlString);
Assert.assertEquals(executionResult.getFactHandles().size(), executionResult2.getFactHandles().size());
Assert.assertEquals(executionResult.getResults().size(), executionResult2.getResults().size());
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class FieldIndexEntryTest method testTwoEntries.
@Test
public void testTwoEntries() {
final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
final FieldIndex fieldIndex = new FieldIndex(extractor, null, MvelConstraint.INDEX_EVALUATOR);
final SingleIndex singleIndex = new SingleIndex(new FieldIndex[] { fieldIndex }, 1);
Tuple tuple = new RightTupleImpl(new DefaultFactHandle(1, new Cheese("stilton", 10)));
final TupleList index = new AbstractHashTable.SingleIndexTupleList(singleIndex, tuple, "stilton".hashCode(), false);
final Cheese stilton1 = new Cheese("stilton", 35);
final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
final Cheese stilton2 = new Cheese("stilton", 59);
final InternalFactHandle h2 = new DefaultFactHandle(2, stilton2);
RightTuple h1RightTuple = new RightTupleImpl(h1, null);
RightTuple h2RightTuple = new RightTupleImpl(h2, null);
// test add
index.add(h1RightTuple);
index.add(h2RightTuple);
assertEquals(h1, index.getFirst().getFactHandle());
assertEquals(h2, ((RightTuple) index.getFirst().getNext()).getFactHandle());
// test get
assertEquals(h1, index.get(h1).getFactHandle());
assertEquals(h2, index.get(h2).getFactHandle());
// test removal for combinations
// remove first
index.remove(h2RightTuple);
assertEquals(h1RightTuple.getFactHandle(), index.getFirst().getFactHandle());
// remove second
index.add(h2RightTuple);
index.remove(h1RightTuple);
assertEquals(h2RightTuple.getFactHandle(), index.getFirst().getFactHandle());
// check index type does not change, as this fact is removed
stilton1.setType("cheddar");
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class ReteooFactHandleFactory method newFactHandle.
/* (non-Javadoc)
* @see org.kie.reteoo.FactHandleFactory#newFactHandle(long)
*/
public InternalFactHandle newFactHandle(final int id, final Object object, final long recency, final ObjectTypeConf conf, final InternalWorkingMemory workingMemory, final WorkingMemoryEntryPoint wmEntryPoint) {
if (conf != null && conf.isEvent()) {
TypeDeclaration type = conf.getTypeDeclaration();
long timestamp;
if (type != null && type.getTimestampExtractor() != null) {
timestamp = type.getTimestampExtractor().getLongValue(workingMemory, object);
} else {
timestamp = workingMemory.getTimerService().getCurrentTime();
}
long duration = 0;
if (type != null && type.getDurationExtractor() != null) {
duration = type.getDurationExtractor().getLongValue(workingMemory, object);
}
return new EventFactHandle(id, object, recency, timestamp, duration, wmEntryPoint != null ? wmEntryPoint : workingMemory, conf != null && conf.isTrait());
} else {
return new DefaultFactHandle(id, object, recency, wmEntryPoint != null ? wmEntryPoint : workingMemory, conf != null && conf.isTrait());
}
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class StatefulSessionTest method testDisconnectedFactHandle.
@Test
public void testDisconnectedFactHandle() {
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration);
KieSession ksession = kbase.newKieSession();
final DefaultFactHandle helloHandle = (DefaultFactHandle) ksession.insert("hello");
final DefaultFactHandle goodbyeHandle = (DefaultFactHandle) ksession.insert("goodbye");
FactHandle key = DefaultFactHandle.createFromExternalFormat(helloHandle.toExternalForm());
assertEquals("hello", ksession.getObject(key));
key = DefaultFactHandle.createFromExternalFormat(goodbyeHandle.toExternalForm());
assertEquals("goodbye", ksession.getObject(key));
}
Aggregations