Plugin : how to know the InitialClientSetup is running?

40 views
Skip to first unread message

Nicolas Micoud

unread,
Jun 5, 2024, 10:54:31 AMJun 5
to iDempiere
Hi,

I have added some tests in a plugin (based on BPartners and Users) that are failing while executing the InitialClientSetup process (which is creating BP/Users).
That results in a failure of the process and a not created tenant.

In this case, the tests should not be conducted as several values are still not filled.
I wanted to add some conditions to allow not to conduct those tests.

My first idea was to use the transaction name/displayname.
if trxName starts with 'Setup_' and display name is 'org.compiere.model.MSetup_createClient', then tests are not conducted.
But I don't find this clean (that can be changed without I noticed it).

So wondering if the following change would be acceptable (haven't tested yet, but I think it should work)

In the InitialClientSetup.java class, right after the try { (line 274), add
something like
Env.setContext(getCtx(), "INITIAL_CLIENT_SETUP_RUNNING", "Y");

and add a finally block with this content
Env.setContext(getCtx(), "INITIAL_CLIENT_SETUP_RUNNING", "");

And then I can test this value in the plugin.

I think that can be achieved directly in the plugin using BEFORE_PROCESS/AFTER_PROCESS events, but that may have sense to make it available in trunk.

wdyt?

Thanks,

Nicolas

Heng Sin Low

unread,
Jun 5, 2024, 11:16:44 AMJun 5
to idem...@googlegroups.com
Are you referring to unit test errors caused by InitialClientSetupTest and parallel test execution ?

If yes, you just need to add "@Isolated" annotation to the InitialClientSetupTest class.

--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/c99d4171-f72c-4e35-87ab-c0103fe727a0n%40googlegroups.com.

Heng Sin Low

unread,
Jun 5, 2024, 11:22:31 AMJun 5
to idem...@googlegroups.com
If you mean validation that shouldn't be run while a new client/tenant is being created, there's one easy way to determine that - the client record doesn't exist without using the running transaction.

Nicolas Micoud

unread,
Jun 5, 2024, 11:37:46 AMJun 5
to iDempiere
Yes, shouldn't be run while a new tenant is being created.
Testing the id in DB will work for sure, but is not good for performance as this will be run everytime before executing tests (and as tests are conducted before saving bp and users) that will make a lot of un-necessary queries.

Calling MClient.get(currentlyCreatedClientID) and test if the value is null should work (and be better for performance), but that will probably generate some
MClient.loadPO -> no data found for AD_Client_ID = currentlyCreatedClientID

So would be better but still not a clean solution (ie without warning, is always 'terrific' when reading logs with "No Data found for...")

wdyt?

Heng Sin Low

unread,
Jun 5, 2024, 11:56:59 AMJun 5
to idem...@googlegroups.com
Actually, checking transaction name is fine, it is very unlikely that we will change that.

Nicolas Micoud

unread,
Jun 5, 2024, 11:59:18 AMJun 5
to iDempiere
Ok, I'll do this then
Anyway, to make it better, I would prefer to add some static public variables so it can be used by both MSetup and my plugin.
Would it be acceptable?

Thanks

Heng Sin Low

unread,
Jun 5, 2024, 12:17:05 PMJun 5
to idem...@googlegroups.com
Yeah, that sounds fine to me.

Nicolas Micoud

unread,
Jun 5, 2024, 12:28:31 PMJun 5
to iDempiere
Reply all
Reply to author
Forward
0 new messages