Tracing a class in WAR file deployed in Wildfly 18 - wildfly

I wanted to add some tracing on a method within our application deployed in Wildfly 18.
I could see only the first rule was loaded and printed from Console output (not server.log though) from Windows command prompt but the other Rule was never printed.
RULE show byteman is loaded
CLASS Main
METHOD main
AT ENTRY
IF TRUE
DO trace("Byteman at start");
traceln("Hey Byteman ");
ENDRULE
RULE Check Method1
CLASS com.xxx.xxx.MyClass
METHOD method1
AT ENTRY
IF true
DO trace("Method1 was called");
traceln("Method1 was called");
ENDRULE
RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into org.jboss.as.server.Main.main(java.lang.String[]) void for rule show byteman is loaded
org.jboss.byteman.agent.Transformer : inserted trigger for show byteman is loaded in class org.jboss.as.server.Main
Rule.execute called for show byteman is loaded_0:1
HelperManager.install for helper class org.jboss.byteman.rule.helper.Helper
calling installed(show byteman is loaded) for helper classorg.jboss.byteman.rule.helper.Helper
Installed rule using default helper : show byteman is loaded
show byteman is loaded execute
Byteman at startHey Byteman

The problem here appears to be that your second rule has not been injected. The Byteman trace only shows the first rule being injected. Are you sure you have the correct details in your rule?
RULE Check Method1
CLASS com.xxx.xxx.MyClass
METHOD method1
...
Does the class com.xxx.xxx.MyClass actually exist?
Does it have a method with name method1?
Does that class ever get loaded?
Does that method ever get called?
It certainly doesn't look like the answers to those last 2 questions can be yes because you would see inject and trigger messages if that were so.

Related

How to write the test method for the following code?

I have code for this before update trigger and I have to write the test method for it. I am completely new to apex and this is the first trigger I wrote but not getting how to write test method for it.
Code
The screenshot doesn't provide much of the details, but I am writing the test class based on the info you have shared.
Tweak the code based on how you have implemented the trigger.
#isTest
private class StatusCloseDateTest {
#isTest static void testStatusCloseDate() {
yourObjAPIName__c rectoupdate = new yourObjAPIName__c();
rectoupdate.name = 'testValue';
/* based on the type of trigger (insert,update,delete) you wrote
perform the dml action.
EG:insert rectoupdate/update rectoupdate/delete rectoupdate
*/
insert rectoupdate;
/* when you perform this dml operation, the trigger will get
invoked and the code you have written in the trigger will
be covered by this test class method.
*/
}
}
Run the test methods in this class.
In the Developer Console, click Test | New Run.
Under Test Classes, click "StatusCloseDateTest".
To add all the test methods in the "StatusCloseDateTest" class to the test run, click Add Selected.
Click Run.
For more details refer : Trailhead

Custom moodle completion rule does not work

I am developing a mod_plugin for Moodle and want to support the automatic activity completion with a custom rule. I followed the official documentation and implemented all necessary functions. In the lib.php [pluginname]_supports method I have registered, FEATURE_GRADE_HAS_GRADE, FEATURE_COMPLETION_TRACKS_VIEWS, FEATURE_COMPLETION_HAS_RULES.
The \mod_[pluginname]\completion\custom_completion class defines a custom rule named "completiontest" in get_defined_custom_rules(). During my tests I found out that the methods get_state(), get_sort_order() and get_custom_rule_descriptions() are never executed. Also I don't see any output via activity_information().
I have cleared all caches, created new instances of my activity module, with no result. My development environment uses Moodle 3.11.7 (Build: 20220509).
My custom_completion.php script:
<?php
declare(strict_types=1);
namespace mod_cwr\completion;
use core_completion\activity_custom_completion;
class custom_completion extends activity_custom_completion {
public function get_state(string $rule): int {
return COMPLETION_INCOMPLETE;
}
public static function get_defined_custom_rules(): array {
return [
'completiontest'
];
}
public function get_custom_rule_descriptions(): array {
return [
'completiontest' => 'testout'
];
}
public function get_sort_order(): array {
return [
'completionview',
'completiontest',
'completionusegrade'
];
}
}
Test at the view.php:
$completion = new completion_info($course);
$completion->set_module_viewed($coursemodule);
if($completion->is_enabled($coursemodule) == COMPLETION_TRACKING_AUTOMATIC){
$completion->update_state($coursemodule, COMPLETION_INCOMPLETE, $USER->id);
}
$completiondetails = \core_completion\cm_completion_details::get_instance($coursemodule, $USER->id);
$activitydates = \core\activity_dates::get_dates_for_module($coursemodule, $USER->id);
echo $OUTPUT->activity_information($coursemodule, $completiondetails, $activitydates);
At the mod_form.php I check with completion_rule_enabled() if a custom rule is activated by the settings.
Does anyone have any idea what the problem could be?
Looking at the mod_forum plugin code showed me, that the get_state($rule) method does not observe all custom rules, only those selected in the settings. How do I tell Moodle to use a specific custom rule?
You appear to be calling update_state() and passing in the possible state change as COMPLETION_INCOMPLETE.
This is a way of telling Moodle "if the state is already incomplete, don't bother doing any expensive completion calculations to check if it should change state".
If you want Moodle to check and then (potentially) change the state to "complete", then pass COMPLETION_COMPLETE. If you really don't know which way it could be switching, then leave the param at the default COMPLETION_UNKNOWN (a good example would be forum completion - if you have just created a forum post, then you might cause the forum to be marked as "complete", but you certainly can't cause the forum to be marked as "incomplete", so you can pass the COMPLETION_COMPLETE parameter, so Moodle knows it only needs to check for changes if the forum is not already "complete").
Also, don't bother passing $USER->id as the third parameter - that's the default which is used of you don't pass anything.
As for telling Moodle which rules to use - it is up to you, when your function is called, to check your plugins settings to determine which rules are in use (and any other relevant configuration - e.g. with mod_forum, it needs to check how many posts are required for completion).
Thank you for the support. Got it running.
I now use $completion->update_state($coursemodule, COMPLETION_COMPLETE); and also had to fix [pluginname]_get_coursemodule_info() with $result->customdata['customcompletionrules']['completiontest'] = $cwr->completiontest; and totally forgot the return $result;.

Why does Drools re-evaluate and re-trigger rule actions after a persistent session is reloaded?

I have a simple rule like the one below:
package rules
dialect "mvel"
declare MyEvent
#role( event )
#expires( 2d )
id String
value: Double
end
rule "My Rule"
when
MyEvent($value : value)
then
System.out.println("My event with value: " + $value);
end
I create a persistent session and call fireAllRules() on it. Then, I insert a MyEvent fact, and as expected the rule is evaluated, matched and the action is executed. If I call fireAllRules() again the rule is not matched, as expected because it has already matched for the same fact. At this point everything is fine.
Then I kill the JVM and run the app again. At startup the app loads the session like this:
kieSession = kieServices.getStoreServices().loadKieSession(KIE_SESSION_ID, kieBase, kieSessionConfiguration, kieEnvironment);
The session gets loaded successfully, and then fireAllRules() is called again. Since the rule has already matched for the inserted event, I am expecting that it does not match again. However I can see the message in the rule action is printed again. Why does Drools match the rule for the same eventagaian? To me it looks like the session state is not properly saved to database. I mean, the event is saved, but Drools can not recogonize that it has already matched the rule. When I load a persistent session I expect to recover exactly the same state that the session had in the previous running instance. Is my assumption wrong? or Am I doing something wrong for the expected behaviour?
Running:
JavaSE 11
SpringBoot 2.3
Drools 7.53.0

Jbehave : GivenStories in the end of execution

I'm using a GivenStories for executing Login scenario which is located in different story.
I was wondering if there is a way to use something similar in order to execute a logout story which is also located in different story than one I actually executing.
I know that I can do some tricks with #before/after annotations , but the question is if I can execute a "post" story
Thanks
Based on the jBehave annotation documentation a post story step can be implemented by annotating a step class method with #AfterStory (or #AfterStories if you want to execute only after all stories complete). The #AfterStory method will execute regardless of whether your executing story contains a step from the related step class (i.e. is guaranteed to execute after every story - see below for restricting to given stories).
The #BeforeStory and #AfterStory annotations allow the corresponding
methods to be executed before and after each story, either a
GivenStory or not:
#AfterStory // equivalent to #AfterStory(uponGivenStory=false)
public void afterStory() {
// ...
}
#AfterStory(uponGivenStory=true)
public void afterGivenStory() {
// ...
}
This is the answer I got from the jbehave dev channel.
Hi,
there is no such mechanism, but you could:
use the Lifecycle to execute steps (not stories) after the execution
of a scenario (executed after each scenario) have a final scenario
which invokes the given stories

oracle jdbc jface wizardpage

I want to create a jface wizard and collect credentials as I go along - password and username on page 1 and then on page 2 I want to display a list I get from an oracle database.
I am using eclipse, and have all the controls in the places I want. On page 2 I put the oracle connection details and sql statement in the createControl method of wizardpage. This seems to fail with a class not found (ojdbc6.jar included in my build path) which I can't decide whether this is an eclipse issue or my code (my code works when it is standalone, not in a wizard)
The failure happens when I start the wizardpage, which it probably will do as I havent got the correct credentials at that point. I couldn't find a method in the wizardpage documentation for running stuff when you enter that wizardpage. Is there a method that runs on entry?
I want to connect to the database to pull down a list to populate a table.
Cheers
David
The createControl method gets called on all pages when the Wizard is opened. You should use createControl only to layout SWT or JFace objects.
You probably want to initialize the JDBC connection when the second page becomes visible. At that point you would then load your list on the page. To do that, override the setVisible method on the second page as follows:
/* (non-Javadoc)
* #see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
*/
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if(visible){
// initialize the jdbc connection here - use a data access object
// use the connection or the DAO to populate your list
}
}
This way the connection will be initialized when the second page becomes visible. Another useful thing to do from the setVisible method is to assign the focus to the right control by calling forceFocus() on the relevant control.