Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBRULES-2940: Knowledge Agent puts all assets in just one package #23

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.drools.runtime.rule.FactHandle;
import org.drools.runtime.rule.QueryResultsRow;

import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -492,7 +491,7 @@ public void testModifyPackageUrlIncremental() throws Exception {
kagent.dispose();
}

@Test @Ignore
@Test
public void testUpdatePackageUrlIncremental() throws Exception {

// Add Rule1 and Rule2 in the first package
Expand Down Expand Up @@ -544,9 +543,11 @@ public void testUpdatePackageUrlIncremental() throws Exception {
list.clear();

kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( createDefaultRule( "rule2" ).getBytes() ),
kbuilder.add( ResourceFactory.newByteArrayResource( createLhsRule( "rule2",
"String()\n" ).getBytes() ),
ResourceType.DRL );
kbuilder.add( ResourceFactory.newByteArrayResource( createDefaultRule( "rule3" ).getBytes() ),
kbuilder.add( ResourceFactory.newByteArrayResource( createLhsRule( "rule3",
"String()\n" ).getBytes() ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
fail( kbuilder.getErrors().toString() );
Expand All @@ -558,7 +559,6 @@ public void testUpdatePackageUrlIncremental() throws Exception {
scan( kagent );
ksession.fireAllRules();

// !!! MDP rule2 is not new, it should not have fired
assertEquals( 1,
list.size() );
assertTrue( list.contains( "rule3" ) );
Expand Down Expand Up @@ -678,7 +678,7 @@ public void testUpdatePackageUrlOverwriteIncremental() throws Exception {
kagent.dispose();
}

@Test @Ignore
@Test
public void testCompleteRuleScenario() throws Exception {
File f1 = fileManager.write( "rule1.drl",
createLhsRule( new String[]{"rule1", "rule2"},
Expand Down Expand Up @@ -796,15 +796,15 @@ public void testCompleteRuleScenario() throws Exception {
scan( kagent );

// Check as a result of old data against new rules
// Even if rule3 and rule3-V2 are defined in different resources, both
// are the same rule (they have the same name ('rule3') and are defined
// in the same package), so in the kbase, rule3 is overwiritten by rule3-V2
ksession.fireAllRules();
assertEquals( 1,
list.size() );
assertTrue( list.contains( "rule3-V2" ) );
list.clear();

// !!! MDP this logic is wrong rule3 and rule3-v2 should both exist
// rule3 is in rule2.drl and rule3-V2 is in rules3.drl

// Check all rules are still there with new data
ksession.retract( h1 );
h1 = ksession.insert( "String4" );
Expand Down Expand Up @@ -849,57 +849,46 @@ public void testCompleteRuleScenario() throws Exception {
str );
scan( kagent );

// Check remaining rules are still there with new data
ksession.retract( h1 );
h1 = ksession.insert( "String6" );
ksession.fireAllRules();

System.out.println( list );

// MDP the logic from this point is wrong. Rule3 was removed when added, so it should be in the list

// File f3 = fileManager.write( "rule3.drl",
// createVersionedRule( null,
// new String[]{"rule1"},
// null,
// "String()\n",
// "2" ) );
//
// //adds rules1-V3 definition to rules2.drl
// output = new BufferedWriter(new FileWriter(f2));
// output.write(header);
// output.write(rule1V3);
// output.write(rule3);
// output.write(rule4);
// output.close();
// System.gc();
// Thread.sleep(3000);
//
// ksession = kbase.newStatefulKnowledgeSession();
// list = new ArrayList<String>();
// ksession.setGlobal("list", list);
// ksession.fireAllRules();
// ksession.dispose();
//
assertEquals( 2,
assertEquals( 3,
list.size() );
assertTrue( list.contains( "rule1-V3" ) );
assertTrue( list.contains( "rule3" ) );
assertTrue( list.contains( "rule2" ) );
//Rule3 doesn't appear again because a new version was defined earleir
//in rule3.drl. So, from the Agent's point of view, the deffinition of
//Rule3 didn't change in this file
//assertTrue( list.contains( "rule3" ) );
assertTrue( list.contains( "rule4" ) );
list.clear();

ksession.retract( h1 );
h1 = ksession.insert( "String5" );
ksession.fireAllRules();

//rule3 doesn't reapear because it was not modified in the resource
//assertTrue(list.contains("rule3"));
//Add a new version of Rule1 in rule3.drl
f3 = fileManager.write( "rule3.drl",
createVersionedRule( null,
new String[]{"rule1"},
null,
"String()\n",
"4" ) );

//rule3.drl was removed, so we need to force the agent to start
//monitoring it again.
applyChangeSet(kagent, ResourceFactory.newUrlResource( fxml.toURI().toURL() ));

// Check remaining rules are still there with new data
ksession.retract( h1 );
h1 = ksession.insert( "String7" );
ksession.fireAllRules();

assertEquals( 4,
assertEquals( 3,
list.size() );
assertTrue( list.contains( "rule1-V3" ) );
assertTrue( list.contains( "rule1-V4" ) );
assertTrue( list.contains( "rule2" ) );
assertTrue( list.contains( "rule3" ) );
assertTrue( list.contains( "rule4" ) );
//
// kagent.monitorResourceChangeEvents(false);
list.clear();

ksession.dispose();
kagent.dispose();

Expand Down