use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class FactHandleTest method testEqualsObject.
/*
* Class under test for boolean equals(Object)
*/
@Test
public void testEqualsObject() {
final DefaultFactHandle f0 = new DefaultFactHandle(134, "cheese");
final DefaultFactHandle f1 = new DefaultFactHandle(96, "cheese");
final DefaultFactHandle f3 = new DefaultFactHandle(96, "cheese");
assertFalse("f0 should not equal f1", f0.equals(f1));
assertEquals(f1, f3);
assertNotSame(f1, f3);
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class FactHandleTest method testInvalidate.
@Test
public void testInvalidate() {
final DefaultFactHandle f0 = new DefaultFactHandle(134, "cheese");
assertEquals(134, f0.getId());
f0.invalidate();
// invalidate no longer sets the id to -1
assertEquals(134, f0.getId());
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class RightTupleListTest method testEmptyIterator.
@Test
public void testEmptyIterator() {
final TupleList map = new TupleList();
final Cheese stilton1 = new Cheese("stilton", 35);
final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
assertNull(map.getFirst(new LeftTupleImpl(h1, null, true)));
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class DefaultFactHandleFactoryTest method testNewFactHandle.
/*
* Class under test for FactHandle newFactHandle()
*/
@Test
public void testNewFactHandle() {
final ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle("cheese", null, null, null);
assertEquals(1, handle.getId());
assertEquals(1, handle.getRecency());
// issue new handle
handle = (DefaultFactHandle) factory.newFactHandle("cheese", null, null, null);
assertEquals(2, handle.getId());
assertEquals(2, handle.getRecency());
// issue new handle, under a different reference so we can destroy later
final DefaultFactHandle handle2 = (DefaultFactHandle) factory.newFactHandle("cheese", null, null, null);
assertEquals(3, handle2.getId());
assertEquals(3, handle2.getRecency());
// Check recency increasion works
factory.increaseFactHandleRecency(handle);
assertEquals(4, handle.getRecency());
// issue new handle and make sure recency is still inline
handle = (DefaultFactHandle) factory.newFactHandle("cheese", null, null, null);
assertEquals(4, handle.getId());
assertEquals(5, handle.getRecency());
// destroy handle
factory.destroyFactHandle(handle2);
// @FIXME recycling is currently disabled
// // issue new fact handle and make sure it recycled the id=2
// handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
// assertEquals( 2,
// handle.getId() );
// assertEquals( 5,
// handle.getRecency() );
//
// // issue new handle making sure it correctly resumes ids and recency
// handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
// assertEquals( 4,
// handle.getId() );
// assertEquals( 6,
// handle.getRecency() );
}
use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.
the class InputMarshaller method readFactHandle.
public static InternalFactHandle readFactHandle(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
int type = context.readInt();
long id = context.readLong();
long recency = context.readLong();
long startTimeStamp = 0;
long duration = 0;
boolean expired = false;
long activationsCount = 0;
if (type == 2) {
startTimeStamp = context.readLong();
duration = context.readLong();
expired = context.readBoolean();
activationsCount = context.readLong();
}
int strategyIndex = context.readInt();
ObjectMarshallingStrategy strategy = null;
// This is the old way of de/serializing strategy objects
if (strategyIndex >= 0) {
strategy = context.getResolverStrategyFactory().getStrategy(strategyIndex);
} else // This is the new way
if (strategyIndex == -2) {
String strategyClassName = context.readUTF();
if (!StringUtils.isEmpty(strategyClassName)) {
strategy = context.getResolverStrategyFactory().getStrategyObject(strategyClassName);
if (strategy == null) {
throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
}
}
}
// If either way retrieves a strategy, use it
Object object = null;
if (strategy != null) {
object = strategy.read((ObjectInputStream) context);
}
EntryPoint entryPoint = null;
if (context.readBoolean()) {
String entryPointId = context.readUTF();
if (entryPointId != null && !entryPointId.equals("")) {
entryPoint = ((RuleRuntime) context.getWorkingMemory()).getEntryPoint(entryPointId);
}
}
EntryPointId confEP;
if (entryPoint != null) {
confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
} else {
confEP = context.getWorkingMemory().getEntryPoint();
}
ObjectTypeConf typeConf = context.getWorkingMemory().getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(confEP, object);
InternalFactHandle handle = null;
switch(type) {
case 0:
{
handle = new DefaultFactHandle(id, object, recency, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
break;
}
case 1:
{
handle = new QueryElementFactHandle(object, id, recency);
break;
}
case 2:
{
handle = new EventFactHandle(id, object, recency, startTimeStamp, duration, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
((EventFactHandle) handle).setExpired(expired);
((EventFactHandle) handle).setActivationsCount(activationsCount);
break;
}
default:
{
throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + type);
}
}
return handle;
}
Aggregations