Nicolas Duminil created KARAF-6717:
--------------------------------------
Summary: Using PaxExam for integration tests
Key: KARAF-6717
URL: https://issues.apache.org/jira/browse/KARAF-6717
Project: Karaf
Issue Type: Test
Components: karaf
Affects Versions: 4.2.8
Reporter: Nicolas Duminil
Hello,
I'm using PaxExam for integration testing purposes with Karaf 4.2.8 and a
couple of shell commands. The idea being that the services expose a command
layer where testing may be conducted from the Karaf console. Then, integration
tests, made by the failsafe maven plugin, invoke these commands to
automatically assure the code validity.
I came to the following configuration code:
{color:#9e880d} @Inject
{color}{color:#0033b3} private {color}{color:#000000}SessionFactory
{color}{color:#871094}sessionFactory{color};
....
{color:#9e880d} @Configuration
{color}{color:#0033b3} public {color}{color:#000000}Option{color}[]
{color:#00627a}config{color}()
{
{color:#0033b3}return new {color}Option[]
{
karafDistributionConfiguration().useDeployFolder({color:#0033b3}false{color})
.frameworkUrl({color:#067d17}"mvn:org.apache.karaf/apache-karaf/4.2.8/tar.gz"{color})
.karafVersion({color:#067d17}"4.2.8"{color}),
logLevel({color:#000000}LogLevelOption{color}.{color:#000000}LogLevel{color}.{color:#871094}INFO{color}),
wrappedBundle(maven().groupId({color:#067d17}"com.oracle.jdbc"{color})
.artifactId({color:#067d17}"ojdbc8"{color}).version({color:#067d17}"12.2.0.1"{color})),
features({color:#067d17}"mvn:fr.simplex-software.red-hat.fuse.osgi/customers-features/0.0.1-
SNAPSHOT/xml"{color},
{color:#067d17}"customers-datasource"{color},
{color:#067d17}"customers-service"{color}),
mavenBundle().groupId({color:#067d17}"org.ops4j.pax.jdbc"{color})
.artifactId({color:#067d17}"pax-jdbc-oracle"{color}).version({color:#067d17}"1.4.5"{color}),
features({color:#067d17}"mvn:fr.simplex-software.red-hat.fuse.osgi/customers-features/0.0.1-SNAPSHOT/xml"{color},
{color:#067d17}"customers-command"{color}),
configureConsole().ignoreLocalConsole(), junitBundles()
};
}
Here above I'm creating a new dedicated instance of Karaf 4.2.8 and I deploy to
it a couple of bundles, like the Oracle JDBC driver and pax-jdbc-oracle, as
well as a couple of features like customers-datasource, customers-service and
customers-command.
Then, in a test method, I'm doing:
{color:#000000} ...
{color}{color:#000000}System{color}.{color:#871094}out{color}.println(executeCommand({color:#067d17}"feature:list"{color}));
{color:#000000}
System{color}.{color:#871094}out{color}.println(executeCommand({color:#067d17}"bundle:list"{color}));
result = executeCommand({color:#067d17}"customers:create-coorporate
..."{color});
assertNotNull(result);
result = executeCommand({color:#067d17}"customers:create-individual
...{color}{color:#067d17}"{color});
assertNotNull(result);
result = executeCommand({color:#067d17}"customers:findAll"{color});
assertNotNull(result);
...
The code above displays the list of features and bundles, after which it uses
the shell commands to creat a coorporate and an individula customer. After
that, the list of the customers is displayed.
This code works sometimes, but sometimes not. When it works, it correctly
displayed the list of the features and bundles and I can check that mine are
installed and active. It also correctly creates the required records and
displays the result of the findAll() method. However, any other command after
the findAll(), for example:
...
result = executeCommand({color:#067d17}"customers:findCustomerById
1"{color});
assertNotNull(result);
{color:#000000} System{color}.{color:#871094}out{color}.println(result);
result = executeCommand({color:#067d17}"customers:findCustomerById
2"{color});
assertNotNull(result);
{color:#000000} System{color}.{color:#871094}out{color}.println(result);
result = executeCommand({color:#067d17}"customers:removeCustomer 1"{color});
assertNotNull(result);
...
don't return any result.
When it doesn't work, the customers-command feature is an a status of Resolved,
instead of Active, while the customers-service is in a status of Starting. Then
the following exceptions are raised:
The following is displayed:
org.apache.felix.gogo.runtime.CommandNotFoundException: Command not found:
customers:create-coorporate
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:596)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:526)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:415)
at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:416)
at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229)
at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
result = executeCommand({color:#067d17}"customers:removeCustomer 2"{color});
So the same code works differently in successive runs without any modification
and in a random manner. But independently of the fact that it works or it
doesn't it systematically displays the following:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running
fr.simplex_software.red_hat.osgi.standalone.customers.rest.command.integration_tests.CustomerCommandIT
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/home/nicolas/.m2/repository/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/home/nicolas/.m2/repository/org/apache/karaf/org.apache.karaf.client/4.2.6.fuse-750016-redhat-00001/org.apache.karaf.client-4.2.6.fuse-750016-redhat-00001.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/home/nicolas/.m2/repository/org/ops4j/pax/logging/pax-logging-api/1.11.2/pax-logging-api-1.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
The maven POM includes SLF4J and Lombock but I'm not able to effectivelly use
them, hence the System.out.println in the code above.
And of course, I need to mention that using manually the commands, by typing
them to the Karaf console, works as expected, and doesn't raise any exception
or warning.
Many thanks in advance for any help.
Kind regards,
Nicolas DUMINIL
--
This message was sent by Atlassian Jira
(v8.3.4#803005)