Re: Debugging karaf feature pax exam test in eclipse, possible?

2023-06-06 Thread Eric Lilja
Yeah, as JB mentioned, Karaf mode in Pax Exam is forked so the classpath
from the test bootstrap itself does not spill over into the container (for
native pax exam, you can choose between forked mode or not).

Anyway, remote debugging seems to be a bit easier in Intellij (I stopped
using Eclipse several years ago). Remote debugging is turned on by adding
the following VM option (regardless of IDE, obviously):

vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")

Then when the test is launched in debug mode, Intellij emits:
Listening for transport dt_socket at address: 5005

And next to that log statement, there is something akin to a button that
says "Attach debugger", which I can just click to be able to debug the
container (it takes a few seconds to attach).

No need to create a special debug configuration

However, I did notice that all log output from then on doesn't seem to
appear anywhere, which is a bit annoying, but I'm sure that can be
resolved. Inspecting all objects etc, which is the important stuff, works
fine, however.

- Eric L


On Tue, Jun 6, 2023 at 7:27 PM Steinar Bang  wrote:

> > Jean-Baptiste Onofré :
>
> > As pax-exam can fork the JVM to start Karaf, you need remote debugger.
>
> Hm... but does it fork the JUnit test also?
>
> That's where I'm trying to debug...?
>
> Ah, but you're right! To be able to run the way it does, i.e. access
> OSGi services created in karaf as Java objects, the JUnit test has to be
> in the same JVM as karaf is running.
>
> > Is it what you are doing ?
>
> No, I think that would be hard here.
>
> I use the remote debugger all the time with karaf proper, where it works
> perfectly, I might add.
>
> But in a pax exam karaf test I have time to set up remote debugging,
> from the time the test starts and it ends.
>
> I had hoped there was an eclipse run configuration that could be used,
> maybe...?
>
> I googled "pax exam eclipse run configuration" and found these two:
>  https://stackoverflow.com/a/43149241
>
> https://confluence.i2cat.net/m/mobile.action#page/17567089#HowtomakeanintegrationtestwithPaxExam-Debuggingyourtest
>
> I'll dig deeper into these two.
>
> Thanks!
>
>


Re: Debugging karaf feature pax exam test in eclipse, possible?

2023-06-06 Thread Steinar Bang
> Jean-Baptiste Onofré :

> As pax-exam can fork the JVM to start Karaf, you need remote debugger.

Hm... but does it fork the JUnit test also?

That's where I'm trying to debug...?

Ah, but you're right! To be able to run the way it does, i.e. access
OSGi services created in karaf as Java objects, the JUnit test has to be
in the same JVM as karaf is running.

> Is it what you are doing ?

No, I think that would be hard here.

I use the remote debugger all the time with karaf proper, where it works
perfectly, I might add.

But in a pax exam karaf test I have time to set up remote debugging,
from the time the test starts and it ends.

I had hoped there was an eclipse run configuration that could be used,
maybe...?

I googled "pax exam eclipse run configuration" and found these two:
 https://stackoverflow.com/a/43149241 
 
https://confluence.i2cat.net/m/mobile.action#page/17567089#HowtomakeanintegrationtestwithPaxExam-Debuggingyourtest

I'll dig deeper into these two.

Thanks!



Re: same configuration registered with multiple PIDs in ManagedServiceFactory

2023-06-06 Thread Jesse White
Awesome. Thanks everyone!

Great writeup Grzegorz - clearly non-trivial and very subtle.

Best,
Jesse

From: Grzegorz Grzybek 
Sent: Thursday, June 1, 2023 5:44 AM
To: user@karaf.apache.org 
Subject: Re: same configuration registered with multiple PIDs in 
ManagedServiceFactory


EXTERNAL EMAIL DON'T BE QUICK TO CLICK

If you believe this email is suspicious, report via ‘Phish Alert Report’ button


Hello

I've added quite a long comment under 
https://issues.apache.org/jira/browse/KARAF-6074 showing my investigation.

So this is actually NOT a race condition - feature configs with dash in name 
will ALWAYS create two configurations from the factory PID.

And yes - reverting 
https://github.com/apache/karaf/commit/1221b0158d2494523cf94cc3f223bd552a2467c7 
helps with duplicate PID, but actually gives you REAL race condition (happening 
intermittently) described at https://issues.apache.org/jira/browse/KARAF-7389.

What actually is needed is:

-if (pid.contains("~")) {
-cid.name = pid.substring(n + 1);
-}
+cid.name = pid.substring(n + 1);

which ensures that both Karaf and felix.fileinstall operate on the same PID 
(and not only factory PID).

let me prepare a PR.

regards
Grzegorz Grzybek

śr., 31 maj 2023 o 17:47 Grzegorz Grzybek 
mailto:gr.grzy...@gmail.com>> napisał(a):
I personally didn't check with factory pids (dash in the name).
I remember I spotted the problem when dealing with FeatureDeployer (deploy/ 
folder) for Fuse - https://issues.apache.org/jira/browse/KARAF-6074 (but not 
necessarily related to this config problem).

Also from quick search of my history, 
https://issues.apache.org/jira/browse/KARAF-7389 was needed to prevent reading 
half-written file.

More - tomorrow (CEST) ;)

regards
Grzegorz Grzybek

śr., 31 maj 2023 o 17:25 Jean-Baptiste Onofré 
mailto:j...@nanthrax.net>> napisał(a):
Good catch.

I remember we investigated some race condition issues with Greg.

Let me check if the name matches.

Regards
JB

On Wed, May 31, 2023 at 4:45 PM Jesse White 
mailto:je...@opennms.com>> wrote:
>
> Good find Ben, and thanks Grzegorz.
>
> Reverting that commit does solve the problem, so it must be related.
>
> I also found that this change does the trick:
>
> diff --git 
> a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
>  
> b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
> index 40bb666a34..fce2c1221c 100644
> --- 
> a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
> +++ 
> b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
> @@ -68,9 +68,7 @@ public class FeatureConfigInstaller {
>  if (n > 0) {
>  cid.isFactoryPid = true;
>  cid.factoryPid = pid.substring(0, n);
> -if (pid.contains("~")) {
> -cid.name = pid.substring(n + 1);
> -}
> +cid.name = pid.substring(n + 1);
>  }
>  return cid;
>  }
>
> I guess there's some mismatch about the "name" of the config, so it gets 
> treated as two distinct objects.
>
> Best,
> Jesse
> 
> From: Grzegorz Grzybek mailto:gr.grzy...@gmail.com>>
> Sent: Wednesday, May 31, 2023 10:33 AM
> To: user@karaf.apache.org 
> mailto:user@karaf.apache.org>>
> Subject: Re: same configuration registered with multiple PIDs in 
> ManagedServiceFactory
>
>
> EXTERNAL EMAIL DON'T BE QUICK TO CLICK
>
> If you believe this email is suspicious, report via ‘Phish Alert Report’ 
> button
>
> 
> Hello
>
> I remember adding some safety logic related to feature-embedded 
> configuration. Because you're using dash ("-") in the PID, you're actually 
> adding a factory PID. And there may be some hidden race condition here.
>
> Let me check this problem tomorrow.
>
> regards
> Grzegorz Grzybek
>
> śr., 31 maj 2023 o 16:29 ran...@opennms.org 
> mailto:ran...@opennms.org>> napisał(a):
>
> Looking at a diff between 4.3.6 and 4.3.7, the only thing that seems relevant 
> is this change, maybe the issue with multiple threads writing the config at 
> the same time needs to be solved in a different way?
>
>
>
> My guess is this fixed the race condition by making it atomic, but it doesn’t 
> stop it from happening twice in quick succession.
>
> commit 1221b0158d2494523cf94cc3f223bd552a2467c7
>
> Author: Grzegorz Grzybek gr.grzy...@gmail.com
>
> Date:   Wed Feb 9 11:53:33 2022 +0100
>
>
>
> [KARAF-7389] Prevent two threads (feature installer, CM Event Dispatcher 
> through fileinstall) writing the same config file
>
>
>
> (cherry picked from commit f3260d5ab64

Re: Debugging karaf feature pax exam test in eclipse, possible?

2023-06-06 Thread Jean-Baptiste Onofré
Hi,

As pax-exam can fork the JVM to start Karaf, you need remote debugger.
Is it what you are doing ?

Regards
JB

On Sat, Jun 3, 2023 at 4:41 PM Steinar Bang  wrote:
>
> Platform: debian 11.7 "bullseye", amd64
>   openjdk-17-jdk:amd64 17.0.6+10-1~deb11u1 (ie. java 17)
>   karaf 4.4.3
>   pax-exam 4.13.5
>   eclipse  2023-03 (4.27.0)
>
> When I set breakpoints in a pax exam test and run the test in debug in
> eclipse, the breakpoints are never triggered.
>
> Is it possible to debug a pax exam test in eclipse?
>