Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Apr 9, 2019
2 parents 57ebe9d + 97fe462 commit 9547a73
Show file tree
Hide file tree
Showing 11 changed files with 778 additions and 16 deletions.
Expand Up @@ -546,18 +546,20 @@ private static JAXBElement<String> copyOfStringElement(final JAXBElement<String>
return null;
}

// !!! Do NOT autogenerate this method without preserving custom changes !!!
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((any == null) ? 0 : any.hashCode());
result = prime * result + ((any == null || any.isEmpty()) ? 0 : any.hashCode());
result = prime * result + ((lang == null) ? 0 : lang.hashCode());
result = prime * result + ((norm == null) ? 0 : norm.hashCode());
result = prime * result + ((orig == null) ? 0 : orig.hashCode());
result = prime * result + ((translation == null) ? 0 : translation.hashCode());
return result;
}

// !!! Do NOT autogenerate this method without preserving custom changes !!!
@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -570,8 +572,8 @@ public boolean equals(Object obj) {
return false;
}
PolyStringType other = (PolyStringType) obj;
if (any == null) {
if (other.any != null) {
if (any == null || any.isEmpty()) { // because any is instantiated on get (so null and empty should be considered equivalent)
if (other.any != null && !other.any.isEmpty()) {
return false;
}
} else if (!any.equals(other.any)) {
Expand Down
@@ -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);
}
}

}

0 comments on commit 9547a73

Please sign in to comment.