use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityBucketingStateType.F_BUCKET in project midpoint by Evolveum.
the class RepoConcurrencyTest method test150WorkBucketsReplace.
/**
* Here we test concurrent work bucket delegation using
* {@link RepositoryService#modifyObjectDynamically(Class, String, Collection, ModificationsSupplier, RepoModifyOptions, OperationResult)}
* method.
*/
@Test
public void test150WorkBucketsReplace() throws Exception {
int THREADS = 8;
long DURATION = 30_000L;
TaskType task = new TaskType(prismContext).name("test150").beginActivityState().beginActivity().beginBucketing().bucketsProcessingRole(BucketsProcessingRoleType.COORDINATOR).<ActivityStateType>end().<TaskActivityStateType>end().end();
OperationResult result = new OperationResult("test150WorkBucketsReplace");
String oid = plainRepositoryService.addObject(task.asPrismObject(), null, result);
displayValue("object added", oid);
logger.info("Starting worker threads");
List<WorkerThread> threads = new ArrayList<>();
for (int i = 0; i < THREADS; i++) {
final int threadIndex = i;
WorkerThread thread = new WorkerThread(i) {
@Override
void runOnce(OperationResult result) throws Exception {
ModificationsSupplier<TaskType> modificationSupplier = task -> prismContext.deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE, F_ACTIVITY, F_BUCKETING, F_BUCKET).replaceRealValues(getBucketsToReplace(task)).asItemDeltas();
plainRepositoryService.modifyObjectDynamically(TaskType.class, oid, null, modificationSupplier, null, result);
}
private List<WorkBucketType> getBucketsToReplace(TaskType task) {
List<WorkBucketType> currentBuckets = getCurrentBuckets(task);
List<WorkBucketType> newBuckets = CloneUtil.cloneCollectionMembers(currentBuckets);
newBuckets.add(getNextBucket(currentBuckets));
return newBuckets;
}
private WorkBucketType getNextBucket(List<WorkBucketType> currentBuckets) {
return new WorkBucketType(prismContext).sequentialNumber(getLastBucketNumber(currentBuckets) + 1).state(WorkBucketStateType.DELEGATED).workerRef(String.valueOf(threadIndex), TaskType.COMPLEX_TYPE);
}
private List<WorkBucketType> getCurrentBuckets(TaskType task) {
return task.getActivityState().getActivity().getBucketing().getBucket();
}
private int getLastBucketNumber(List<WorkBucketType> buckets) {
return buckets.stream().mapToInt(WorkBucketType::getSequentialNumber).max().orElse(0);
}
@Override
String description() {
return "Bucket computer thread #" + threadIndex;
}
};
thread.start();
threads.add(thread);
}
waitForThreads(threads, DURATION);
PrismObject<TaskType> taskAfter = plainRepositoryService.getObject(TaskType.class, oid, null, result);
displayValue("task after", taskAfter);
assertCorrectBucketSequence(taskAfter.asObjectable().getActivityState().getActivity().getBucketing().getBucket());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityBucketingStateType.F_BUCKET in project midpoint by Evolveum.
the class RepoConcurrencyTest method test140WorkBucketsAdd.
/**
* Here we test concurrent work bucket creation using
* {@link RepositoryService#modifyObjectDynamically(Class, String, Collection, ModificationsSupplier, RepoModifyOptions, OperationResult)}
* method.
*/
@Test
public void test140WorkBucketsAdd() throws Exception {
int THREADS = 8;
long DURATION = 30_000L;
TaskType task = new TaskType(prismContext).name("test140").beginActivityState().beginActivity().beginBucketing().bucketsProcessingRole(BucketsProcessingRoleType.COORDINATOR).<ActivityStateType>end().<TaskActivityStateType>end().end();
OperationResult result = new OperationResult("test140WorkBucketsAdd");
String oid = plainRepositoryService.addObject(task.asPrismObject(), null, result);
displayValue("object added", oid);
logger.info("Starting worker threads");
List<WorkerThread> threads = new ArrayList<>();
for (int i = 0; i < THREADS; i++) {
final int threadIndex = i;
WorkerThread thread = new WorkerThread(i) {
@Override
void runOnce(OperationResult result) throws Exception {
ModificationsSupplier<TaskType> modificationSupplier = task -> prismContext.deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE, F_ACTIVITY, F_BUCKETING, F_BUCKET).add(getNextBucket(task)).asItemDeltas();
plainRepositoryService.modifyObjectDynamically(TaskType.class, oid, null, modificationSupplier, null, result);
}
private WorkBucketType getNextBucket(TaskType task) {
int lastBucketNumber = task.getActivityState() != null ? getLastBucketNumber(task.getActivityState().getActivity().getBucketing().getBucket()) : 0;
return new WorkBucketType(prismContext).sequentialNumber(lastBucketNumber + 1).state(WorkBucketStateType.DELEGATED).workerRef(String.valueOf(threadIndex), TaskType.COMPLEX_TYPE);
}
private int getLastBucketNumber(List<WorkBucketType> buckets) {
return buckets.stream().mapToInt(WorkBucketType::getSequentialNumber).max().orElse(0);
}
@Override
String description() {
return "Bucket computer thread #" + threadIndex;
}
};
thread.start();
threads.add(thread);
}
waitForThreads(threads, DURATION);
PrismObject<TaskType> taskAfter = plainRepositoryService.getObject(TaskType.class, oid, null, result);
displayValue("task after", taskAfter);
assertCorrectBucketSequence(taskAfter.asObjectable().getActivityState().getActivity().getBucketing().getBucket());
}
Aggregations