Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Evolveum/midpoint
- Loading branch information
Showing
11 changed files
with
778 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestIterativeTasks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2010-2019 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.model.intest; | ||
|
||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.task.api.RunningTask; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.annotation.DirtiesContext.ClassMode; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.testng.AssertJUnit; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.util.Collection; | ||
|
||
import static org.testng.AssertJUnit.assertNotNull; | ||
|
||
/** | ||
* Tests AbstractSearchIterativeTaskHandler and related classes. See e.g. MID-5227. | ||
*/ | ||
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"}) | ||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS) | ||
public class TestIterativeTasks extends AbstractInitializedModelIntegrationTest { | ||
|
||
public static final File TEST_DIR = new File("src/test/resources/iterative-tasks"); | ||
|
||
private static final File TASK_BUCKETS_MULTITHREADED_FILE = new File(TEST_DIR, "task-buckets-multithreaded.xml"); | ||
private static final String TASK_BUCKETS_MULTITHREADED_OID = "4ccd0cde-c506-49eb-9718-f85ba3438515"; | ||
|
||
private static final int BUCKETS = 10; // must be <= 100 (if > 10, adapt buckets specification in task) | ||
private static final int USERS_PER_BUCKET = 3; // must be <= 10 | ||
|
||
private static final int EXPECTED_SUBTASKS = 4; | ||
|
||
private static TestIterativeTasks instance; // brutal hack | ||
|
||
@Override | ||
public void initSystem(Task initTask, OperationResult initResult) throws Exception { | ||
super.initSystem(initTask, initResult); | ||
createUsers(initResult); | ||
instance = this; | ||
} | ||
|
||
private void createUsers(OperationResult result) throws ObjectAlreadyExistsException, SchemaException { | ||
for (int i = 0; i < BUCKETS; i++) { | ||
for (int j = 0; j < USERS_PER_BUCKET; j++) { | ||
createUser(result, i*10 + j); | ||
} | ||
} | ||
} | ||
|
||
private void createUser(OperationResult result, int number) throws ObjectAlreadyExistsException, SchemaException { | ||
UserType user = new UserType(prismContext) | ||
.name(String.format("%03d", number)) | ||
.subtype("test"); | ||
repositoryService.addObject(user.asPrismObject(), null, result); | ||
} | ||
|
||
/** | ||
* MID-5227 | ||
*/ | ||
@Test | ||
public void test100RunBucketsMultithreaded() throws Exception { | ||
final String TEST_NAME = "test100RunBucketsMultithreaded"; | ||
displayTestTitle(TEST_NAME); | ||
|
||
// GIVEN | ||
|
||
// WHEN | ||
displayWhen(TEST_NAME); | ||
addTask(TASK_BUCKETS_MULTITHREADED_FILE); | ||
|
||
// THEN | ||
displayThen(TEST_NAME); | ||
waitForTaskFinish(TASK_BUCKETS_MULTITHREADED_OID, false); | ||
} | ||
|
||
@SuppressWarnings("unused") // called from Groovy code | ||
public static void checkLightweightSubtasks(TaskType subtask) { | ||
RunningTask parent = instance.taskManager.getLocallyRunningTaskByIdentifier(subtask.getParent()); | ||
assertNotNull("no parent running task", parent); | ||
Collection<? extends RunningTask> subtasks = parent.getLightweightAsynchronousSubtasks(); | ||
LOGGER.info("Subtask: {}, parent: {}, its subtasks: ({}): {}", subtask, parent, subtasks.size(), subtasks); | ||
if (subtasks.size() > EXPECTED_SUBTASKS) { | ||
AssertJUnit.fail("Exceeded the expected number of subtasks: have " + subtasks.size() + ", expected max: " + EXPECTED_SUBTASKS + ": " + subtasks); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.