<commit_before>package com.camunda.fox.platform.test.functional.ejb.remote;

import org.activiti.engine.runtime.ProcessInstance;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.camunda.fox.platform.test.functional.ejb.remote.bean.BusinessInterface;
import com.camunda.fox.platform.test.functional.ejb.remote.bean.RemoteSingletonBean;
import com.camunda.fox.platform.test.functional.ejb.remote.bean.RemoteSingletonBeanClientDelegateBean;
import com.camunda.fox.platform.test.util.AbstractFoxPlatformIntegrationTest;



/**
 * This test verifies that a CDI Java Bean Delegate is able to inject and invoke the 
 * remote business interface of a SingletonBean from a different application
 * 
 * Note:
 * - works on Jboss 
 * - works on Glassfish
 * 
 * @author <NAME>
 *
 */
@RunWith(Arquillian.class)
public class RemoteSingletonBeanInvocationTest extends AbstractFoxPlatformIntegrationTest {
 
  @Deployment(name="pa", order=2)
  public static WebArchive processArchive() {    
    return initWebArchiveDeployment()
      .addClass(RemoteSingletonBeanClientDelegateBean.class)        
      .addClass(BusinessInterface.class) // the business interface
      .addAsResource("com/camunda/fox/platform/test/functional/ejb/remote/RemoteSingletonBeanInvocationTest.testInvokeBean.bpmn20.xml");      
  }
  
  @Deployment(order=1)
  public static WebArchive delegateDeployment() {    
    return ShrinkWrap.create(WebArchive.class, "service.war")
      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
      .addClass(AbstractFoxPlatformIntegrationTest.class)
      .addClass(RemoteSingletonBean.class) // the EJB 
      .addClass(BusinessInterface.class); // the business interface
  }
    
  @Test
  @OperateOnDeployment("pa")
  public void testInvokeBean() throws Exception{
    
    // this testcase first resolves the Bean synchronously and then from the JobExecutor
    
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testInvokeBean");
    
    Assert.assertEquals(runtimeService.getVariable(pi.getId(), "result"), true);
    
    runtimeService.setVariable(pi.getId(), "result", false);
    
    taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
    
    waitForJobExecutorToProcessAllJobs(6000, 300);
    
    Assert.assertEquals(runtimeService.getVariable(pi.getId(), "result"), true);
    
    taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
  }
  
  @Test
  public void testMultipleInvocations() {
    
    // this is greater than any Datasource / EJB / Thread Pool size -> make sure all resources are released properly.
    int instances = 100;    
    String[] ids = new String[instances];
    
    for(int i=0; i<instances; i++) {    
      ids[i] = runtimeService.startProcessInstanceByKey("testInvokeBean").getId();    
      Assert.assertEquals(runtimeService.getVariable(ids[i], "result"), true);      
      runtimeService.setVariable(ids[i], "result", false);
      taskService.complete(taskService.createTaskQuery().processInstanceId(ids[i]).singleResult().getId());
    }
        
    waitForJobExecutorToProcessAllJobs(60*1000, 300);
    <commit_msg>Increased time for JobExecutor<commit_after>package com.camunda.fox.platform.test.functional.ejb.remote;

import org.activiti.engine.runtime.ProcessInstance;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.camunda.fox.platform.test.functional.ejb.remote.bean.BusinessInterface;
import com.camunda.fox.platform.test.functional.ejb.remote.bean.RemoteSingletonBean;
import com.camunda.fox.platform.test.functional.ejb.remote.bean.RemoteSingletonBeanClientDelegateBean;
import com.camunda.fox.platform.test.util.AbstractFoxPlatformIntegrationTest;



/**
 * This test verifies that a CDI Java Bean Delegate is able to inject and invoke the 
 * remote business interface of a SingletonBean from a different application
 * 
 * Note:
 * - works on Jboss 
 * - works on Glassfish
 * 
 * @author <NAME>
 *
 */
@RunWith(Arquillian.class)
public class RemoteSingletonBeanInvocationTest extends AbstractFoxPlatformIntegrationTest {
 
  @Deployment(name="pa", order=2)
  public static WebArchive processArchive() {    
    return initWebArchiveDeployment()
      .addClass(RemoteSingletonBeanClientDelegateBean.class)        
      .addClass(BusinessInterface.class) // the business interface
      .addAsResource("com/camunda/fox/platform/test/functional/ejb/remote/RemoteSingletonBeanInvocationTest.testInvokeBean.bpmn20.xml");      
  }
  
  @Deployment(order=1)
  public static WebArchive delegateDeployment() {    
    return ShrinkWrap.create(WebArchive.class, "service.war")
      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
      .addClass(AbstractFoxPlatformIntegrationTest.class)
      .addClass(RemoteSingletonBean.class) // the EJB 
      .addClass(BusinessInterface.class); // the business interface
  }
    
  @Test
  @OperateOnDeployment("pa")
  public void testInvokeBean() throws Exception{
    
    // this testcase first resolves the Bean synchronously and then from the JobExecutor
    
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testInvokeBean");
    
    Assert.assertEquals(runtimeService.getVariable(pi.getId(), "result"), true);
    
    runtimeService.setVariable(pi.getId(), "result", false);
    
    taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
    
    waitForJobExecutorToProcessAllJobs(60000, 300);
    
    Assert.assertEquals(runtimeService.getVariable(pi.getId(), "result"), true);
    
    taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
  }
  
  @Test
  public void testMultipleInvocations() {
    
    // this is greater than any Datasource / EJB / Thread Pool size -> make sure all resources are released properly.
    int instances = 100;    
    String[] ids = new String[instances];
    
    for(int i=0; i<instances; i++) {    
      ids[i] = runtimeService.startProcessInstanceByKey("testInvokeBean").getId();    
      Assert.assertEquals(runtimeService.getVariable(ids[i], "result"), true);      
      runtimeService.setVariable(ids[i], "result", false);
      taskService.complete(taskService.createTaskQuery().processInstanceId(ids[i]).singleResult().getId());
    }
        
    waitForJobExecutorToProcessAllJobs(180*1000, 300);
    
{'fraction_non_alphanumeric': 0.10988396477002656, 'fraction_numerical': 0.006990074094785405, 'mean_word_length': 4.370870870870871, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '989599', 'n_tokens_mistral': 2183, 'n_tokens_neox': 2074, 'n_words': 365}