ResourceChangeScannerConfiguration config = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
config.setProperty("drools.resource.scanner.interval", "1");
ResourceFactory.getResourceChangeScannerService().configure(config);
// create knowledge agent
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("xls agent");
kagent.applyChangeSet(ResourceFactory.newFileResource(xlsChangeset));
KnowledgeBase kbase = kagent.getKnowledgeBase();
// ---------------------------------------------------------------
// start scanning service - scanner's thread throws exception here
// ---------------------------------------------------------------
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
assertEquals( 2, kbase.getKnowledgePackages().size() );
assertEquals( 3, kbase.getKnowledgePackage( "com.sample" ).getRules().size() );
// sleeping and modifying content
Thread.sleep(1500);
ruleFile.delete();
ruleFile = new File(TMP_DIR + "sample.xls");
copy(getClass().getResourceAsStream("sample2.xls"), new FileOutputStream(ruleFile));
Thread.sleep(1000);
assertEquals(kbase.getKnowledgePackages().size(), 2);
assertEquals( 3, kbase.getKnowledgePackage( "com.sample" ).getRules().size() );
// there should be just 2 rules now, but scanner didn't notice the change
kbase = kagent.getKnowledgeBase();
assertEquals(kbase.getKnowledgePackages().size(), 2);
assertEquals( 2, kbase.getKnowledgePackage( "com.sample" ).getRules().size() );
// stop scanning service
ResourceFactory.getResourceChangeNotifierService().stop();
ResourceFactory.getResourceChangeScannerService().stop();
// file could remain and we will see, that it has changed, but scanner didn't register that
//ruleFile.delete();
kagent.dispose();
}