Skip to content

Commit

Permalink
7.67.x blue fixes (#2249)
Browse files Browse the repository at this point in the history
* Adjust GHA concurrency (#2240)

* Use random porto for LDAP test server

* Add timeout to IT tests (#2243)

* Avoid timeout in test (#2246)

* Use date format for log cleanup command (#2245)
  • Loading branch information
cristianonicolai committed Dec 9, 2022
1 parent a3f88d7 commit f83186c
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
build-chain:
concurrency:
group: pull_request-${{ github.head_ref }}
group: jbpm-${{ matrix.java-version }}-pull_request-${{ github.head_ref }}
cancel-in-progress: true
strategy:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void stopRestService() {
RestService.stop();
}

@Test
@Test(timeout = 30000)
public void testTimerThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down Expand Up @@ -117,7 +117,7 @@ public void testTimerThreadInfo() throws Exception {
}


@Test
@Test(timeout = 30000)
public void testLogThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down Expand Up @@ -148,7 +148,7 @@ public void testLogThreadInfo() throws Exception {
Assertions.assertThat(threadNameHistory.iterator().next().getNewValue()).startsWith("EE");
}

@Test
@Test(timeout = 30000)
public void testRESTThreadInfo() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("url", RestService.PING_URL);
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testRESTThreadInfo() throws Exception {
Assertions.assertThat(threadNameHistory.iterator().next().getNewValue()).startsWith("EE");
}

@Test
@Test(timeout = 30000)
public void testScriptThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down Expand Up @@ -224,7 +224,7 @@ public void testScriptThreadInfo() throws Exception {
Assertions.assertThat(threadNameHistory.iterator().next().getNewValue()).startsWith("EE");
}

@Test
@Test(timeout = 30000)
public void testHumanTaskThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down Expand Up @@ -259,7 +259,7 @@ public void testHumanTaskThreadInfo() throws Exception {
Assertions.assertThat(threadNameHistory.iterator().next().getOldValue()).startsWith("EE");
}

@Test
@Test(timeout = 30000)
public void testRuleThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down Expand Up @@ -289,7 +289,7 @@ public void testRuleThreadInfo() throws Exception {
Assertions.assertThat(threadNameHistory.iterator().next().getNewValue()).startsWith("EE");
}

@Test
@Test(timeout = 30000)
public void testEmbeddedThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down Expand Up @@ -319,7 +319,7 @@ public void testEmbeddedThreadInfo() throws Exception {
Assertions.assertThat(threadNameHistory.iterator().next().getNewValue()).startsWith("EE");
}

@Test
@Test(timeout = 30000)
public void testSubProcessThreadInfo() throws Exception {
Long pid = startProcessInstance(THREAD_INFO_PROCESS_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
import com.unboundid.ldap.listener.InMemoryListenerConfig;
import com.unboundid.ldap.sdk.DN;
import com.unboundid.ldap.sdk.LDAPException;

import org.jbpm.test.util.SocketUtils;
import org.junit.After;
import org.junit.Before;

public abstract class LDAPBaseTest {

private static final int PORT = 10389;
private static final int PORT = SocketUtils.findAvailablePort();

protected static final String SERVER_URL = "ldap://localhost:" + PORT;
protected static final String BASE_DN = "dc=jbpm,dc=org";
Expand Down Expand Up @@ -56,7 +58,15 @@ public void startDirectoryServer() throws LDAPException {
@After
public void stopDirectoryServer() {
if (server != null) {
int listenPort = server.getListenPort();
server.shutDown(true);
while (!SocketUtils.isPortAvailable(listenPort)) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
//ignore
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private UserGroupCallback createLdapUserGroupCallback(Configuration config) {
case SYSTEM:
System.setProperty("jbpm.usergroup.callback.properties", "/jbpm.usergroup.callback.properties");
case DEFAULT:
return new LDAPUserGroupCallbackImpl(true);
return new RandomPortCallback(true);
default:
throw new IllegalArgumentException("unknown config type");
}
Expand Down Expand Up @@ -377,4 +377,22 @@ private void assertGroups(UserGroupCallback userGroupCallback, boolean manager,
assertions.assertAll();
}

public class RandomPortCallback extends LDAPUserGroupCallbackImpl {

public RandomPortCallback(boolean activate) {
super(activate);
}

public RandomPortCallback(Properties config) {
super(config);
}

@Override
protected Properties readProperties(String propertiesLocation, String defaultProperties) {
Properties properties = super.readProperties(propertiesLocation, defaultProperties);
properties.setProperty("java.naming.provider.url", SERVER_URL);
return properties;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ ldap.user.filter=(uid\={0})
ldap.role.filter=(cn\={0})
ldap.user.roles.filter=(member\={0})
#ldap.user.attr.id=
#ldap.roles.attr.id=

java.naming.provider.url=ldap://localhost:10389
#ldap.roles.attr.id=
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;

import javax.persistence.EntityManagerFactory;

Expand Down Expand Up @@ -67,6 +68,8 @@ public class CleanupExecutionErrorCommandWithProcessTest extends AbstractExecuto
private ExecutorService executorService;
private EntityManagerFactory emf = null;

private ExecutionErrorStorage errorStorage;

@Before
public void setup() {
ExecutorTestUtil.cleanupSingletonSessionId();
Expand All @@ -76,10 +79,16 @@ public void setup() {
properties.setProperty("john", "HR");
userGroupCallback = new JBossUserGroupCallbackImpl(properties);
executorService = buildExecutorService();
RuntimeEnvironment environment = configureEnvironment();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, UUID.randomUUID().toString());
assertNotNull(manager);
errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();
}

@After
public void teardown() {
executorService.clearAllRequests();
executorService.clearAllErrors();
executorService.destroy();
if (manager != null) {
RuntimeManagerRegistry.get().remove(manager.getIdentifier());
Expand All @@ -101,12 +110,6 @@ protected CountDownAsyncJobListener configureListener(int threads) {
@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingOlderThan() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = configureEnvironment();

manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);

ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();

RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
Expand All @@ -121,8 +124,8 @@ public void testRunProcessWithAsyncHandlerDeleteUsingOlderThan() throws Exceptio
List<ExecutionError> errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());

scheduleLogCleanup(startDate, null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd", manager.getIdentifier());
countDownListener.reset(1);
scheduleLogCleanup(startDate, null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd", manager.getIdentifier());
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
Expand All @@ -138,8 +141,8 @@ public void testRunProcessWithAsyncHandlerDeleteUsingOlderThan() throws Exceptio

Thread.sleep(1000);

scheduleLogCleanup(new Date(), null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
scheduleLogCleanup(new Date(), null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.waitTillCompleted();

errors = errorStorage.list(0, 10);
Expand All @@ -150,12 +153,6 @@ public void testRunProcessWithAsyncHandlerDeleteUsingOlderThan() throws Exceptio
@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = configureEnvironment();

manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);

ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();

RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
Expand All @@ -172,9 +169,9 @@ public void testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod() throws Ex
// advance time 1 second
Thread.sleep(1000);

countDownListener.reset(1);
// delete errors which happened 1s or more ago
scheduleLogCleanup(null, "1s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
Expand All @@ -188,18 +185,18 @@ public void testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod() throws Ex
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);

countDownListener.reset(1);
// delete errors which happened 5s or more ago
scheduleLogCleanup(null, "5s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();

// should not delete any errors as we wanted to delete errors from 5s ago
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());

countDownListener.reset(1);
// delete errors which happened 1s or more ago
scheduleLogCleanup(null, "0s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();

errors = errorStorage.list(0, 10);
Expand All @@ -210,12 +207,6 @@ public void testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod() throws Ex
@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingReoccurring() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = configureEnvironment();

manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);

ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();

RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
Expand All @@ -229,12 +220,12 @@ public void testRunProcessWithAsyncHandlerDeleteUsingReoccurring() throws Except
List<ExecutionError> errors = errorStorage.list(0, 10);
assertEquals(0, errors.size());

countDownListener.reset(1);
System.out.println("Process starting...");
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
System.out.println("Process started...");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
// wait for the process instance to generate an error
countDownListener.reset(1);
System.out.println("Waiting to generate an error...");
countDownListener.waitTillCompleted();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import com.unboundid.ldap.sdk.DN;
import com.unboundid.ldap.sdk.LDAPException;
import org.jbpm.services.task.identity.LDAPUserGroupCallbackImpl;
import org.jbpm.test.util.SocketUtils;
import org.junit.After;
import org.junit.Before;

public abstract class LdapJbpmTestCase extends JbpmTestCase {

private static InMemoryDirectoryServer server;
private static final int PORT = SocketUtils.findAvailablePort();

private final String ldif;

Expand All @@ -41,7 +43,7 @@ public LdapJbpmTestCase(String ldif) {

@Before
public void startDirectoryServer() throws LDAPException {
InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", 10389);
InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", PORT);

InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN("dc=jboss,dc=org"));
serverConfig.setListenerConfigs(listenerConfig);
Expand All @@ -62,7 +64,7 @@ public void stopDirectoryServer() {

protected Properties createUserGroupCallbackProperties() {
Properties properties = new Properties();
properties.setProperty(Context.PROVIDER_URL, "ldap://localhost:10389");
properties.setProperty(Context.PROVIDER_URL, "ldap://localhost:" + PORT);
properties.setProperty(LDAPUserGroupCallbackImpl.USER_CTX, "ou=People,dc=jboss,dc=org");
properties.setProperty(LDAPUserGroupCallbackImpl.ROLE_CTX, "ou=Roles,dc=jboss,dc=org");
properties.setProperty(LDAPUserGroupCallbackImpl.USER_FILTER, "(uid={0})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jbpm.test.functional.jobexec;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -323,7 +324,7 @@ private void scheduleLogCleanup(Date olderThan,
commandContext.setData("EmfName", "org.jbpm.test.persistence");
commandContext.setData("SingleRun", "true");
commandContext.setData("DateFormat", dateFormat);
commandContext.setData("OlderThan", LocalDateTime.now().toString());
commandContext.setData("OlderThan", LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateFormat)));

Iterator<Map.Entry<String, Object>> iterator = parameters.entrySet().iterator();
while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public NodeLeftCountDownProcessEventListener(String nodeName, int threads, boole
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (nodeName.equals(event.getNodeInstance().getNodeName())) {
countDown();
countAfter++;
countDown();
}
}

Expand Down

0 comments on commit f83186c

Please sign in to comment.