TIBCO BusinessEvents engine threw ClassCastException when running in API mode and multiple JUnit test cases were running together.

TIBCO BusinessEvents engine threw ClassCastException when running in API mode and multiple JUnit test cases were running together.

book

Article ID: KB0091207

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition -
Not Applicable -

Description

Resolution:
Description:
==========

TIBCO BusinessEvents is running in API Mode using JUnit. Single test case runs without issue. If multiple test cases are running together, the first case runs without issue but later cases throw java.lang.ClassCastException &ltConcept Class A> cannot be cast to &ltConcept Class A>.

For example:  java.lang.ClassCastException: be.gen.Concepts.Account cannot be cast to be.gen.Concepts.Customer.Account.

Environment:
============
TIBCO BusinessEvents - 4.x
OS - all

Cause:
============
The following code maybe executed multiple times:
>>>>>>>>>>>
RuleServiceProvider provider;
provider = RuleServiceProviderManager.getInstance().newProvider("TestsBase", env);
provider.configure(MODE_API);
<<<<<<<<<<<

It is not allowed to create multiple RuleServiceProvider in the same JVM.

Resolution:
=============
In one JVM, RuleServiceProvider can only be configured once. If it is released, the JVM should be restarted too.

In JUnit, RuleServiceProviderManager.getInstance().newProvider() and RuleServiceProvider.configure() should be put in method beforeClass() in stead of method before().

Here are example code snippets:
>>>>>>>>>>>>>>>
    static RuleServiceProvider  provider;
    static RuleSession               ruleSession;
    static TypeManager              typeManager;
    static Properties                   env;

    @BeforeClass
    public static void beforeClass() throws Exception    {

        env = new Properties();
        env.put("tibco.be.APIMode", "true");
        env.put("tibco.repourl", repoUrl);
        env.put("be.bootstrap.property.file",traFile);
        env.put("com.tibco.be.config.path",cddFile);
        env.put("com.tibco.be.config.unit.id",procUnit);        

        provider = RuleServiceProviderManager.getInstance().newProvider( "your agent name", env);
          provider.configure( RuleServiceProvider.MODE_API );

        …
}
<<<<<<<<<<<<<<<<

Issue/Introduction

TIBCO BusinessEvents engine threw ClassCastException when running in API mode and multiple JUnit test cases were running together.