Skip to content

Commit

Permalink
[JBPM-10217] Authentication fails on Oracle WLS in TaskAssigning
Browse files Browse the repository at this point in the history
IntegrationTest
  • Loading branch information
gmunozfe committed Jan 11, 2024
1 parent 1f901ca commit 95887a9
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void start() {
solutionProcessor = createSolutionProcessor(delegate, this::onSolutionProcessed, config.getTargetUserId(),
config.getPublishWindowSize());
executorService.execute(solverExecutor); //is started/stopped on demand by the SolutionSynchronizer.
executorService.execute(solutionSynchronizer);
executorService.schedule(solutionSynchronizer, config.getInitDelay(), TimeUnit.MILLISECONDS);
executorService.execute(solutionProcessor);
solutionSynchronizer.initSolverExecutor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public class SolverHandlerConfig {
private Duration usersSyncInterval;
private Duration waitForImprovedSolutionDuration;
private Duration improveSolutionOnBackgroundDuration;
private long initDelay;

public SolverHandlerConfig(String targetUserId,
int publishWindowSize,
Duration syncInterval,
Duration syncQueriesShift,
Duration usersSyncInterval,
Duration waitForImprovedSolutionDuration,
Duration improveSolutionOnBackgroundDuration) {
Duration improveSolutionOnBackgroundDuration,
long initDelay) {
if (targetUserId == null || targetUserId.isEmpty()) {
throw new IllegalArgumentException("A non empty targetUserId is expected.");
}
Expand All @@ -47,13 +49,15 @@ public SolverHandlerConfig(String targetUserId,
checkGreaterOrEqualTo("usersSyncInterval", usersSyncInterval, Duration.ZERO);
checkGreaterOrEqualTo("waitForImprovedSolutionDuration", waitForImprovedSolutionDuration, Duration.ZERO);
checkGreaterOrEqualTo("improveSolutionOnBackgroundDuration", improveSolutionOnBackgroundDuration, Duration.ZERO);
checkGreaterOrEqualTo("initDelay", initDelay, 0L);
this.targetUserId = targetUserId;
this.publishWindowSize = publishWindowSize;
this.syncInterval = syncInterval;
this.syncQueriesShift = syncQueriesShift;
this.usersSyncInterval = usersSyncInterval;
this.waitForImprovedSolutionDuration = waitForImprovedSolutionDuration;
this.improveSolutionOnBackgroundDuration = improveSolutionOnBackgroundDuration;
this.initDelay = initDelay;
}

public String getTargetUserId() {
Expand Down Expand Up @@ -83,4 +87,8 @@ public Duration getWaitForImprovedSolutionDuration() {
public Duration getImproveSolutionOnBackgroundDuration() {
return improveSolutionOnBackgroundDuration;
}

public long getInitDelay() {
return initDelay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ private TaskAssigningConstants() {
*/
public static final String TASK_ASSIGNING_IMPROVE_SOLUTION_ON_BACKGROUND_DURATION = "org.kie.server.taskAssigning.improveSolutionOnBackgroundDuration";

/**
* Property for configuring the initial delay (in milliseconds) to start the extension.
*/
public static final String TASK_ASSIGNING_INIT_DELAY = "org.kie.server.taskAssigning.initDelay";

/**
* Property for configuring the resource with the solver configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import static org.kie.server.services.taskassigning.planning.TaskAssigningConstants.TASK_ASSIGNING_SYNC_QUERIES_SHIFT;
import static org.kie.server.services.taskassigning.planning.TaskAssigningConstants.TASK_ASSIGNING_USERS_SYNC_INTERVAL;
import static org.kie.server.services.taskassigning.planning.TaskAssigningConstants.TASK_ASSIGNING_WAIT_FOR_IMPROVED_SOLUTION_DURATION;
import static org.kie.server.services.taskassigning.planning.TaskAssigningConstants.TASK_ASSIGNING_INIT_DELAY;
import static org.kie.server.services.taskassigning.planning.TaskAssigningPlanningKieServerExtensionMessages.PARAMETER_MUST_HAVE_A_GREATER_OR_EQUAL_TO_ZERO_DURATION_VALUE_ERROR;
import static org.kie.server.services.taskassigning.planning.TaskAssigningPlanningKieServerExtensionMessages.PARAMETER_MUST_HAVE_A_GREATER_THAN_ZERO_DURATION_VALUE_ERROR;
import static org.kie.server.services.taskassigning.planning.TaskAssigningPlanningKieServerExtensionMessages.PARAMETER_MUST_HAVE_A_GREATER_THAN_ZERO_INTEGER_VALUE_ERROR;
import static org.kie.server.services.taskassigning.planning.TaskAssigningPlanningKieServerExtensionMessages.PARAMETER_MUST_HAVE_A_NON_EMPTY_STRING_VALUE_ERROR;
import static org.kie.server.services.taskassigning.planning.TaskAssigningPlanningKieServerExtensionMessages.PARAMETER_MUST_BE_ZERO_OR_GREATER_THAN_ZERO_LONG_VALUE_ERROR;

public class TaskAssigningPlanningKieServerExtensionHelper {

Expand All @@ -42,9 +44,10 @@ public class TaskAssigningPlanningKieServerExtensionHelper {
static final String DEFAULT_USERS_SYNC_INTERVAL = "PT2H";
static final String DEFAULT_WAIT_FOR_IMPROVED_SOLUTION_DURATION = "PT0S";
static final String DEFAULT_IMPROVE_SOLUTION_ON_BACKGROUND_DURATION = "PT1M";
static final long DEFAULT_INIT_DELAY = 0L;

private static final String CAUSE = ", cause :";

private TaskAssigningPlanningKieServerExtensionHelper() {
}

Expand All @@ -56,6 +59,7 @@ public static TaskAssigningServiceConfig readAndValidateTaskAssigningServiceConf
Duration usersSyncInterval;
Duration waitForImprovedSolutionDuration;
Duration improveSolutionOnBackgroundDuration;
long initDelay;

targetUserId = trimToNull(System.getProperty(TASK_ASSIGNING_PROCESS_RUNTIME_TARGET_USER));
if (isNull(targetUserId)) {
Expand Down Expand Up @@ -86,8 +90,12 @@ public static TaskAssigningServiceConfig readAndValidateTaskAssigningServiceConf
String.format(PARAMETER_MUST_HAVE_A_GREATER_OR_EQUAL_TO_ZERO_DURATION_VALUE_ERROR,
TASK_ASSIGNING_IMPROVE_SOLUTION_ON_BACKGROUND_DURATION));

initDelay = parseAndValidateEqualsOrGreaterThanZeroLong(System.getProperty(TASK_ASSIGNING_INIT_DELAY, Long.toString(DEFAULT_INIT_DELAY)),
String.format(PARAMETER_MUST_BE_ZERO_OR_GREATER_THAN_ZERO_LONG_VALUE_ERROR,
TASK_ASSIGNING_INIT_DELAY));

return new TaskAssigningServiceConfig(targetUserId, publishWindowSize, syncInterval, syncQueriesShift,
usersSyncInterval, waitForImprovedSolutionDuration, improveSolutionOnBackgroundDuration);
usersSyncInterval, waitForImprovedSolutionDuration, improveSolutionOnBackgroundDuration, initDelay);
}

private static Duration parseAndValidateGreaterThanZeroDuration(String value, String validationErrorMessage) throws TaskAssigningValidationException {
Expand Down Expand Up @@ -125,4 +133,18 @@ private static int parseAndValidateGreaterThanZeroInteger(String value, String v
}
return result;
}

private static long parseAndValidateEqualsOrGreaterThanZeroLong(String value, String validationErrorMessage) throws TaskAssigningValidationException {
long result;
try {
result = Long.parseLong(value);
} catch (NumberFormatException e) {
String msg = validationErrorMessage + CAUSE + e.toString();
throw new TaskAssigningValidationException(msg);
}
if (result < 0) {
throw new TaskAssigningValidationException(validationErrorMessage);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private TaskAssigningPlanningKieServerExtensionMessages() {

static final String PARAMETER_MUST_HAVE_A_GREATER_OR_EQUAL_TO_ZERO_DURATION_VALUE_ERROR = "Parameter %s must be configured with a greater or equal to zero time duration";

static final String PARAMETER_MUST_BE_ZERO_OR_GREATER_THAN_ZERO_LONG_VALUE_ERROR = "Parameter %s must be configured with a greater or equal to zero long value";

static String addExtensionMessagePrefix(String msg) {
return String.format(PLANNER_EXTENSION_MESSAGE_PREFIX, msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ public TaskAssigningServiceConfig(String targetUserId,
Duration syncQueriesShift,
Duration usersSyncInterval,
Duration waitForImprovedSolutionDuration,
Duration improveSolutionOnBackgroundDuration) {
Duration improveSolutionOnBackgroundDuration,
long initDelay) {
solverHandlerConfig = new SolverHandlerConfig(targetUserId,
publishWindowSize,
syncInterval,
syncQueriesShift,
usersSyncInterval,
waitForImprovedSolutionDuration,
improveSolutionOnBackgroundDuration);
improveSolutionOnBackgroundDuration,
initDelay);
}

public SolverHandlerConfig getSolverHandlerConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SolverHandlerConfigTest {
public static final Duration USERS_SYNC_INTERVAL = Duration.parse("PT3H");
public static final Duration WAIT_FOR_IMPROVED_SOLUTION_DURATION = Duration.parse("PT1S");
public static final Duration IMPROVE_SOLUTION_ON_BACKGROUND_DURATION = Duration.parse("PT1M");
public static final long INIT_DELAY = 10000;

protected SolverHandlerConfig config;

Expand All @@ -43,7 +44,8 @@ public void setUp() {
SYNC_QUERIES_SHIFT,
USERS_SYNC_INTERVAL,
WAIT_FOR_IMPROVED_SOLUTION_DURATION,
IMPROVE_SOLUTION_ON_BACKGROUND_DURATION);
IMPROVE_SOLUTION_ON_BACKGROUND_DURATION,
INIT_DELAY);
}

@Test
Expand Down Expand Up @@ -80,4 +82,9 @@ public void getWaitForImprovedSolutionDuration() {
public void getImproveSolutionOnBackgroundDuration() {
assertThat(config.getImproveSolutionOnBackgroundDuration()).isEqualTo(IMPROVE_SOLUTION_ON_BACKGROUND_DURATION);
}

@Test
public void getInitDelay() {
assertThat(config.getInitDelay()).isEqualTo(INIT_DELAY);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,6 +55,7 @@
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.TARGET_USER;
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.USERS_SYNC_INTERVAL;
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.WAIT_FOR_IMPROVED_SOLUTION_DURATION;
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.INIT_DELAY;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
Expand Down Expand Up @@ -129,7 +129,8 @@ public void setUp() {
handlerConfig = spy(new SolverHandlerConfig(TARGET_USER, PUBLISH_WINDOW_SIZE, SYNC_INTERVAL,
SYNC_QUERIES_SHIFT, USERS_SYNC_INTERVAL,
WAIT_FOR_IMPROVED_SOLUTION_DURATION,
IMPROVE_SOLUTION_ON_BACKGROUND_DURATION));
IMPROVE_SOLUTION_ON_BACKGROUND_DURATION,
INIT_DELAY));
previousQueryTime = LocalDateTime.now();
nextQueryTime = previousQueryTime.plusMinutes(2);
this.handler = spy(new SolverHandler(solverDef, registry, delegate, userSystemService, executorService, handlerConfig));
Expand All @@ -152,7 +153,7 @@ public void hasImproveSolutionOnBackgroundDuration() {
public void start() {
prepareStart();
verify(executorService).execute(solverExecutor);
verify(executorService).execute(solutionSynchronizer);
verify(executorService).schedule(solutionSynchronizer, INIT_DELAY, TimeUnit.MILLISECONDS);
verify(executorService).execute(solutionProcessor);
verify(solutionSynchronizer).initSolverExecutor();
}
Expand Down Expand Up @@ -217,7 +218,7 @@ public void onBestSolutionChangeWithWaitForImprovedSolutionDurationWhenChangeSet
SolverHandlerContext context = contextCaptor.getValue();
context.setProcessedChangeSet(context.getCurrentChangeSetId());
listenerCaptor.getValue().bestSolutionChanged(event);
verify(executorService, never()).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
verify(executorService).schedule(solutionSynchronizer, INIT_DELAY, TimeUnit.MILLISECONDS);
}

private void prepareOnBestSolutionChangeWithWaitForImprovedSolutionDuration(Duration waitForImprovedSolutionDuration) {
Expand Down Expand Up @@ -252,7 +253,7 @@ public void onBestSolutionChangeWithWaitForImprovedSolutionDurationZero() {
context.setCurrentChangeSetId(changeSet);
listenerCaptor.getValue().bestSolutionChanged(event);
verify(solutionProcessor).process(event.getNewBestSolution());
verify(executorService, never()).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
verify(executorService).schedule(solutionSynchronizer, INIT_DELAY, TimeUnit.MILLISECONDS);
assertTrue(context.isProcessedChangeSet(changeSet));
}

Expand Down Expand Up @@ -413,7 +414,7 @@ private void onBestSolutionChangeEventNotProcessed(BestSolutionChangedEvent<Task
SolverHandlerContext context = contextCaptor.getValue();
long changeSet = context.nextChangeSetId();
listenerCaptor.getValue().bestSolutionChanged(event);
verify(executorService, never()).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
verify(executorService).schedule(solutionSynchronizer, INIT_DELAY, TimeUnit.MILLISECONDS);
verify(solutionProcessor, never()).process(any());
assertFalse(context.isProcessedChangeSet(changeSet));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.TARGET_USER;
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.USERS_SYNC_INTERVAL;
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.WAIT_FOR_IMPROVED_SOLUTION_DURATION;
import static org.kie.server.services.taskassigning.planning.SolverHandlerConfigTest.INIT_DELAY;

public class TaskAssigningServiceConfigTest {

Expand All @@ -37,7 +38,8 @@ public void getSolverHandlerConfig() {
SYNC_QUERIES_SHIFT,
USERS_SYNC_INTERVAL,
WAIT_FOR_IMPROVED_SOLUTION_DURATION,
IMPROVE_SOLUTION_ON_BACKGROUND_DURATION);
IMPROVE_SOLUTION_ON_BACKGROUND_DURATION,
INIT_DELAY);

SolverHandlerConfig handlerConfig = serviceConfig.getSolverHandlerConfig();
assertThat(handlerConfig).isNotNull();
Expand All @@ -48,5 +50,6 @@ public void getSolverHandlerConfig() {
assertThat(handlerConfig.getUsersSyncInterval()).isEqualTo(USERS_SYNC_INTERVAL);
assertThat(handlerConfig.getWaitForImprovedSolutionDuration()).isEqualTo(WAIT_FOR_IMPROVED_SOLUTION_DURATION);
assertThat(handlerConfig.getImproveSolutionOnBackgroundDuration()).isEqualTo(IMPROVE_SOLUTION_ON_BACKGROUND_DURATION);
assertThat(handlerConfig.getInitDelay()).isEqualTo(INIT_DELAY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<properties>
<java.module.name>org.kie.server.itests.taskassigning</java.module.name>
<org.kie.server.taskAssigning.initDelay>0</org.kie.server.taskAssigning.initDelay>
</properties>

<dependencies>
Expand Down Expand Up @@ -141,6 +142,7 @@
<org.kie.server.taskAssigning.processRuntime.pwd>usetheforce123@</org.kie.server.taskAssigning.processRuntime.pwd>
<org.kie.server.taskAssigning.processRuntime.targetUser>yoda</org.kie.server.taskAssigning.processRuntime.targetUser>>
<org.kie.server.taskAssigning.solutionSyncInterval>PT1S</org.kie.server.taskAssigning.solutionSyncInterval>
<org.kie.server.taskAssigning.initDelay>${org.kie.server.taskAssigning.initDelay}</org.kie.server.taskAssigning.initDelay>

<org.kie.server.taskAssigning.userSystem.name>SimpleUserSystemService</org.kie.server.taskAssigning.userSystem.name>
<org.kie.server.services.taskassigning.user.system.simple.users>${project.build.testOutputDirectory}/roles.properties</org.kie.server.services.taskassigning.user.system.simple.users>
Expand Down Expand Up @@ -242,6 +244,9 @@
<value>oracle-wls-12</value>
</property>
</activation>
<properties>
<org.kie.server.taskAssigning.initDelay>20000</org.kie.server.taskAssigning.initDelay>
</properties>
</profile>
<profile>
<id>websphere9</id>
Expand Down

0 comments on commit 95887a9

Please sign in to comment.