Does ‘StartupControlPanel#loadStartupLoaders’ really require introspection?

2018-10-21 Thread Mathieu Lirzin
Hello,

I have a question regarding the
‘org.apache.ofbiz.base.start.StartupControlPanel#loadStartupLoaders()’
current implementation:

--8<---cut here---start->8---
private static void loadStartupLoaders(Config config,
List loaders,
List ofbizCommands,
AtomicReference serverState) throws StartupException {

String startupLoaderName = 
"org.apache.ofbiz.base.container.ContainerLoader";
ClassLoader classloader = 
Thread.currentThread().getContextClassLoader();

synchronized (loaders) {
if (serverState.get() == ServerState.STOPPING) {
return;
}
try {
Class loaderClass = classloader.loadClass(startupLoaderName);
StartupLoader loader = (StartupLoader) 
loaderClass.newInstance();
loaders.add(loader); // add before loading, so unload can occur 
if error during loading
loader.load(config, ofbizCommands);
} catch (ReflectiveOperationException e) {
throw new StartupException(e);
}
}
serverState.compareAndSet(ServerState.STARTING, ServerState.RUNNING);
}
--8<---cut here---end--->8---

I don't understand the goal of using reflection for instantiating the
‘ContainerLoader’ class. Can't we just have something like the following
instead?

--8<---cut here---start->8---
private static void loadStartupLoaders(Config config,
List loaders,
List ofbizCommands,
AtomicReference serverState) throws StartupException {

ClassLoader classloader = 
Thread.currentThread().getContextClassLoader();

synchronized (loaders) {
if (serverState.get() == ServerState.STOPPING) {
return;
}
StartupLoader loader = new ContainerLoader();
loaders.add(loader); // add before loading, so unload can occur if 
error during loading
loader.load(config, ofbizCommands);
}
serverState.compareAndSet(ServerState.STARTING, ServerState.RUNNING);
}
--8<---cut here---end--->8---

If this is required, I will be happy if someone could add an inline
comment giving a rationale for the current implementation.  If that's
not the case, I can open a JIRA with a proper patch if needed.

Thanks.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37


Re: Using alternate dispatcher and delegator for integration tests

2018-10-21 Thread Mathieu Lirzin
Hello Taher,

Taher Alkhateeb  writes:

> An example could shed some light here perhaps?

What kind of examples would help you?

AIUI It would be for the people using this feature outside of the
framework to provide examples why we should keep it in.

> What do you want to remove from where?

Here is what I precisely want to remove.

>From 66150cc98d2b7b84ee5aa4dee1e25f60556577e6 Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin 
Date: Sun, 21 Oct 2018 16:02:38 +0200
Subject: [PATCH] Disallow using alternate dispatcher and delegator for
 integration tests

---
 framework/testtools/dtd/test-suite.xsd|  2 --
 .../ofbiz/testtools/ModelTestSuite.java   | 23 +--
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git framework/testtools/dtd/test-suite.xsd framework/testtools/dtd/test-suite.xsd
index ee1767aa2f..76cdf1a523 100644
--- framework/testtools/dtd/test-suite.xsd
+++ framework/testtools/dtd/test-suite.xsd
@@ -45,8 +45,6 @@ under the License.
 
 
 
-
-
 
 
 
diff --git framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java
index 5c166beb5d..e666e4451a 100644
--- framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java
+++ framework/testtools/src/main/java/org/apache/ofbiz/testtools/ModelTestSuite.java
@@ -50,31 +50,20 @@ import junit.framework.TestSuite;
  * Use this class in a JUnit test runner to bootstrap the Test Suite runner.
  */
 public class ModelTestSuite {
-
 public static final String module = ModelTestSuite.class.getName();
+public static final String DELEGATOR_NAME = "test";
+public static final String DISPATCHER_NAME = "test-dispatcher";
 
 protected String suiteName;
-protected String originalDelegatorName;
-protected String originalDispatcherName;
-
 protected Delegator delegator;
 protected LocalDispatcher dispatcher;
-
-protected List testList = new ArrayList();
+protected List testList = new ArrayList<>();
 
 public ModelTestSuite(Element mainElement, String testCase) {
-this.suiteName = mainElement.getAttribute("suite-name");
-
-this.originalDelegatorName = mainElement.getAttribute("delegator-name");
-if (UtilValidate.isEmpty(this.originalDelegatorName)) this.originalDelegatorName = "test";
-
-this.originalDispatcherName = mainElement.getAttribute("dispatcher-name");
-if (UtilValidate.isEmpty(this.originalDispatcherName)) this.originalDispatcherName = "test-dispatcher";
-
 String uniqueSuffix = "-" + RandomStringUtils.randomAlphanumeric(10);
-
-this.delegator = DelegatorFactory.getDelegator(this.originalDelegatorName).makeTestDelegator(this.originalDelegatorName + uniqueSuffix);
-this.dispatcher = ServiceContainer.getLocalDispatcher(originalDispatcherName + uniqueSuffix, delegator);
+this.suiteName = mainElement.getAttribute("suite-name");
+this.delegator = DelegatorFactory.getDelegator(DELEGATOR_NAME).makeTestDelegator(DELEGATOR_NAME + uniqueSuffix);
+this.dispatcher = ServiceContainer.getLocalDispatcher(DISPATCHER_NAME+ uniqueSuffix, delegator);
 
 for (Element testCaseElement : UtilXml.childElementList(mainElement, UtilMisc.toSet("test-case", "test-group"))) {
 String caseName = testCaseElement.getAttribute("case-name");
-- 
2.19.1


> How is it complex?

Basically each time an option is provided it adds complexity.  In this
particular case, perhaps a comparaison between the two models of test
execution can help describing the added complexity:

Current model:
   1. Launch OFBiz
   2. Fetch all the tests from the components
   3. Keep track which delegator/dispatcher correspond to each test suite
   4. Run each test by setting its corresponding delegator/dispatcher

Model without option:
   1. Launch OFBiz with the test delegator/dispatcher
   2. Fetch all the tests from the components
   3. Run the tests.

Does it help?

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37


Re: log4j:WARN

2018-10-21 Thread Jacques Le Roux

Just found that it's related to 
FreeMarkerWorkerTests.java::renderTemplateFromString

Not sure why this happens then in the log


Le 21/10/2018 à 18:50, Jacques Le Roux a écrit :

Hi,

I'm not sure if we should worry but I sometimes see these log4j:WARN in the log

   log4j:WARN No appenders could be found for logger (freemarker.cache).
   log4j:WARN Please initialize the log4j system properly.
   log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for 
more info.

I checked log4j2.xml and we define

        
        
        
        
        

        
        
        
        

So I don't see the reason. Maybe it's because it's loaded later?

Jacques
PS: below is a more complete log extract with a complete request context

2018-10-21 10:42:06,293 |jsse-nio-8443-exec-4 |ControlEventListener  
|I| Creating session:  hidden sessionId by default.
2018-10-21 10:42:06,298 |jsse-nio-8443-exec-4 |ControlServlet    |T| [[[main(Domain:https://localhost)] Request Begun, encoding=[UTF-8]- 
total:0.0,since last(Begin):0.0]]

2018-10-21 10:42:06,302 |jsse-nio-8443-exec-4 |VisitHandler  
|I| Found visitorId [1] in cookie
2018-10-21 10:42:06,317 |jsse-nio-8443-exec-4 |TransactionUtil   
|W| No transaction in place, so not suspending.
2018-10-21 10:42:06,329 |jsse-nio-8443-exec-4 |SequenceUtil  |I| Got bank of sequenced IDs for [Visit]; curSeqId=10100, 
maxSeqId=10200, bankSize=100
2018-10-21 10:42:06,367 |jsse-nio-8443-exec-4 |ConfigXMLReader   |I| controller loaded: 0.001s, 50 requests, 34 views in 
file:/C:/projectsASF/ofbiz/plugins/example/webapp/example/WEB-INF/controlle

r.xml
2018-10-21 10:42:06,385 |jsse-nio-8443-exec-4 |ConfigXMLReader   |I| controller loaded: 0.0s, 51 requests, 23 views in 
file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/common-controll

er.xml
2018-10-21 10:42:06,397 |jsse-nio-8443-exec-4 |ConfigXMLReader   |I| controller loaded: 0.0s, 0 requests, 0 views in 
file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/handlers-controll

er.xml
2018-10-21 10:42:06,409 |jsse-nio-8443-exec-4 |ConfigXMLReader   |I| controller loaded: 0.0s, 26 requests, 10 views in 
file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/portal-controll

er.xml
2018-10-21 10:42:06,444 |jsse-nio-8443-exec-4 |ConfigXMLReader   |I| controller loaded: 0.0s, 2 requests, 2 views in 
file:/C:/projectsASF/ofbiz/plugins/example/widget/example/ExampleCompoundWidget

s.xml
2018-10-21 10:42:06,447 |jsse-nio-8443-exec-4 |RequestHandler    
|I| This is the first request in this visit. Hidden sessionId by default.
2018-10-21 10:42:06,454 |jsse-nio-8443-exec-4 |ExternalLoginKeysManager  |W| Could not find userLogin for external login key: 
EL00e7af53-b4b5-40d8-bec2-56ea21563066
2018-10-21 10:42:08,294 |jsse-nio-8443-exec-4 |UtilXml   |E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. Line: 169. Error message: cv

c-complex-type.2.4.d: Invalid content was found starting with element 
'common-menus'. No child element is expected at this point.
2018-10-21 10:42:08,294 |jsse-nio-8443-exec-4 |UtilXml   |E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. Line: 171. Error message: cv

c-complex-type.2.4.a: Invalid content was found starting with element 'menu'. One of 
'{"http://ofbiz.apache.org/Widget-Theme":screen}' is expected.
2018-10-21 10:42:08,308 |jsse-nio-8443-exec-4 |UtilXml   |E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. Line: 169. Error message: cv

c-complex-type.2.4.d: Invalid content was found starting with element 
'common-menus'. No child element is expected at this point.
2018-10-21 10:42:08,308 |jsse-nio-8443-exec-4 |UtilXml   |E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. Line: 171. Error message: cv

c-complex-type.2.4.a: Invalid content was found starting with element 'menu'. One of 
'{"http://ofbiz.apache.org/Widget-Theme":screen}' is expected.
2018-10-21 10:42:08,340 |jsse-nio-8443-exec-4 |RequestHandler    
|I| Rendering View [login].  Hidden sessionId by default.
2018-10-21 10:42:08,355 |jsse-nio-8443-exec-4 |ServiceDispatcher |T| Sync service [example/getUserPreferenceGroup] finished in [11] 
milliseconds

log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.
2018-10-21 10:42:09,020 |jsse-nio-8443-exec-4 |ScreenFactory |I| Got 28 screens in 0.439s from: 

log4j:WARN

2018-10-21 Thread Jacques Le Roux

Hi,

I'm not sure if we should worry but I sometimes see these log4j:WARN in the log

   log4j:WARN No appenders could be found for logger (freemarker.cache).
   log4j:WARN Please initialize the log4j system properly.
   log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for 
more info.

I checked log4j2.xml and we define

    
    
    
    
    

    
    
    
    

So I don't see the reason. Maybe it's because it's loaded later?

Jacques
PS: below is a more complete log extract with a complete request context

2018-10-21 10:42:06,293 |jsse-nio-8443-exec-4 |ControlEventListener  
|I| Creating session:  hidden sessionId by default.
2018-10-21 10:42:06,298 |jsse-nio-8443-exec-4 |ControlServlet
|T| [[[main(Domain:https://localhost)] Request Begun, encoding=[UTF-8]- 
total:0.0,since last(Begin):0.0]]
2018-10-21 10:42:06,302 |jsse-nio-8443-exec-4 |VisitHandler  
|I| Found visitorId [1] in cookie
2018-10-21 10:42:06,317 |jsse-nio-8443-exec-4 |TransactionUtil   
|W| No transaction in place, so not suspending.
2018-10-21 10:42:06,329 |jsse-nio-8443-exec-4 |SequenceUtil  
|I| Got bank of sequenced IDs for [Visit]; curSeqId=10100, maxSeqId=10200, 
bankSize=100
2018-10-21 10:42:06,367 |jsse-nio-8443-exec-4 |ConfigXMLReader   
|I| controller loaded: 0.001s, 50 requests, 34 views in 
file:/C:/projectsASF/ofbiz/plugins/example/webapp/example/WEB-INF/controlle
r.xml
2018-10-21 10:42:06,385 |jsse-nio-8443-exec-4 |ConfigXMLReader   
|I| controller loaded: 0.0s, 51 requests, 23 views in 
file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/common-controll
er.xml
2018-10-21 10:42:06,397 |jsse-nio-8443-exec-4 |ConfigXMLReader   
|I| controller loaded: 0.0s, 0 requests, 0 views in 
file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/handlers-controll
er.xml
2018-10-21 10:42:06,409 |jsse-nio-8443-exec-4 |ConfigXMLReader   
|I| controller loaded: 0.0s, 26 requests, 10 views in 
file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/portal-controll
er.xml
2018-10-21 10:42:06,444 |jsse-nio-8443-exec-4 |ConfigXMLReader   
|I| controller loaded: 0.0s, 2 requests, 2 views in 
file:/C:/projectsASF/ofbiz/plugins/example/widget/example/ExampleCompoundWidget
s.xml
2018-10-21 10:42:06,447 |jsse-nio-8443-exec-4 |RequestHandler
|I| This is the first request in this visit. Hidden sessionId by default.
2018-10-21 10:42:06,454 |jsse-nio-8443-exec-4 |ExternalLoginKeysManager  
|W| Could not find userLogin for external login key: 
EL00e7af53-b4b5-40d8-bec2-56ea21563066
2018-10-21 10:42:08,294 |jsse-nio-8443-exec-4 |UtilXml   
|E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. 
Line: 169. Error message: cv
c-complex-type.2.4.d: Invalid content was found starting with element 
'common-menus'. No child element is expected at this point.
2018-10-21 10:42:08,294 |jsse-nio-8443-exec-4 |UtilXml   
|E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. 
Line: 171. Error message: cv
c-complex-type.2.4.a: Invalid content was found starting with element 'menu'. One of 
'{"http://ofbiz.apache.org/Widget-Theme":screen}' is expected.
2018-10-21 10:42:08,308 |jsse-nio-8443-exec-4 |UtilXml   
|E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. 
Line: 169. Error message: cv
c-complex-type.2.4.d: Invalid content was found starting with element 
'common-menus'. No child element is expected at this point.
2018-10-21 10:42:08,308 |jsse-nio-8443-exec-4 |UtilXml   
|E| XmlFileLoader: File 
file:/C:/projectsASF/ofbiz/themes/common-theme/widget/Theme.xml process error. 
Line: 171. Error message: cv
c-complex-type.2.4.a: Invalid content was found starting with element 'menu'. One of 
'{"http://ofbiz.apache.org/Widget-Theme":screen}' is expected.
2018-10-21 10:42:08,340 |jsse-nio-8443-exec-4 |RequestHandler
|I| Rendering View [login].  Hidden sessionId by default.
2018-10-21 10:42:08,355 |jsse-nio-8443-exec-4 |ServiceDispatcher 
|T| Sync service [example/getUserPreferenceGroup] finished in [11] milliseconds
log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.
2018-10-21 10:42:09,020 |jsse-nio-8443-exec-4 |ScreenFactory 
|I| Got 28 screens in 0.439s from: 
file:/C:/projectsASF/ofbiz/framework/common/widget/CommonScreens.xml
2018-10-21 10:42:09,182 |jsse-nio-8443-exec-4 |FreeMarkerWorker  
|I| loading properties: 

Re: Using alternate dispatcher and delegator for integration tests

2018-10-21 Thread Taher Alkhateeb
An example could shed some light here perhaps? What do you want to
remove from where? How is it complex?
On Sun, Oct 21, 2018 at 5:17 PM Mathieu Lirzin
 wrote:
>
> Hello,
>
> I am trying to simplify the way integration tests are currently run.
> While looking at ‘org.apache.ofbiz.testtools.ModelTestSuite’ I have
> found that it is possible to define alternate dispatcher and delegator
> for specific tests.
>
> This feature is not used anywhere in the framework and introduces a ton
> of complexity since we can't assume that there is only one dispatcher
> and delegator shared by all the tests cases.
>
> As a consequence I would like to know if we could agree on removing this
> unused feature?
>
> Thanks.
>
> --
> Mathieu Lirzin
> GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37


Using alternate dispatcher and delegator for integration tests

2018-10-21 Thread Mathieu Lirzin
Hello,

I am trying to simplify the way integration tests are currently run.
While looking at ‘org.apache.ofbiz.testtools.ModelTestSuite’ I have
found that it is possible to define alternate dispatcher and delegator
for specific tests.

This feature is not used anywhere in the framework and introduces a ton
of complexity since we can't assume that there is only one dispatcher
and delegator shared by all the tests cases.

As a consequence I would like to know if we could agree on removing this
unused feature?

Thanks.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37


Re: Groovy DSL runService Exception Management ?

2018-10-21 Thread Jacopo Cappellato
On Thu, Oct 18, 2018 at 10:45 AM Gil Portenseigne <
gil.portensei...@nereide.fr> wrote:

> Hello !
>
> While we are working on Groovy migration at Nereide, we figured out that
> using ‘run service’ DSL method instead of returning the errorMap, a
> ‘ExecutionServiceException’ is thrown

[...]
> I wonder if exception management is more costly than simple return.
> May the GroovyEngine should handle the exception ? I do not grasp yet
> the benenit of this implementation.
>

 Hi Gil,

if I recall correctly, the original goal was to implement a behavior
similar to the default one of Minilang: if an error is thrown during the
execution of the "call-service" directive in Minilang then the script
execution is halted (see the definition of the property "break-on-error").

I hope it makes sense,

Jacopo