use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project midpoint by Evolveum.
the class SequenceFunctionalTest method test010ReturningValues.
@Test
public void test010ReturningValues() throws Exception {
OperationResult result = createOperationResult();
String oid = repositoryService.addObject(new SequenceType(prismContext).name("Sequence 0-9, 5 unused values, wrap around").counter(0L).maxCounter(9L).allowRewind(true).maxUnusedValues(5).asPrismObject(), null, result);
assertEquals(repositoryService.advanceSequence(oid, result), 0L);
assertEquals(repositoryService.advanceSequence(oid, result), 1L);
assertEquals(repositoryService.advanceSequence(oid, result), 2L);
assertEquals(repositoryService.advanceSequence(oid, result), 3L);
assertEquals(repositoryService.advanceSequence(oid, result), 4L);
repositoryService.returnUnusedValuesToSequence(oid, Arrays.asList(2L, 4L), result);
assertEquals(repositoryService.advanceSequence(oid, result), 2L);
assertEquals(repositoryService.advanceSequence(oid, result), 4L);
assertEquals(repositoryService.advanceSequence(oid, result), 5L);
assertEquals(repositoryService.advanceSequence(oid, result), 6L);
repositoryService.returnUnusedValuesToSequence(oid, null, result);
repositoryService.returnUnusedValuesToSequence(oid, new ArrayList<>(), result);
repositoryService.returnUnusedValuesToSequence(oid, Collections.singletonList(6L), result);
assertEquals(repositoryService.advanceSequence(oid, result), 6L);
repositoryService.returnUnusedValuesToSequence(oid, Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L), // only 0-4 will be returned
result);
assertEquals(repositoryService.advanceSequence(oid, result), 0L);
assertEquals(repositoryService.advanceSequence(oid, result), 1L);
assertEquals(repositoryService.advanceSequence(oid, result), 2L);
assertEquals(repositoryService.advanceSequence(oid, result), 3L);
assertEquals(repositoryService.advanceSequence(oid, result), 4L);
assertEquals(repositoryService.advanceSequence(oid, result), 7L);
assertEquals(repositoryService.advanceSequence(oid, result), 8L);
assertEquals(repositoryService.advanceSequence(oid, result), 9L);
assertEquals(repositoryService.advanceSequence(oid, result), 0L);
assertEquals(repositoryService.advanceSequence(oid, result), 1L);
assertEquals(repositoryService.advanceSequence(oid, result), 2L);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project midpoint by Evolveum.
the class SequenceConcurrencyTest method concurrencyUniversal.
private void concurrencyUniversal(long duration, WorkerThread[] workerThreads, boolean alwaysOrder) throws Exception {
try (JdbcSession jdbcSession = startTransaction()) {
System.out.println(">>>>" + jdbcSession.connection().getTransactionIsolation());
}
OperationResult result = createOperationResult();
String oid = repositoryService.addObject(new SequenceType(prismContext).name(getTestNameShort()).counter(0L).maxUnusedValues(10).asPrismObject(), null, result);
display("*** Object added: " + oid + " ***");
display("*** Starting modifier threads ***");
for (WorkerThread t : workerThreads) {
t.setOid(oid);
t.start();
}
display("*** Waiting " + duration + " ms ***");
Thread.sleep(duration);
for (WorkerThread t : workerThreads) {
t.stop = true;
}
long endTime = System.currentTimeMillis() + STOP_TIMEOUT;
for (; ; ) {
long remaining = endTime - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
for (WorkerThread t : workerThreads) {
t.join(remaining);
remaining = endTime - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
}
}
for (WorkerThread t : workerThreads) {
display("Worker thread " + t.id + " finished after " + t.counter + " iterations with result: " + (t.threadResult != null ? t.threadResult : "OK"));
}
for (WorkerThread t : workerThreads) {
if (t.threadResult != null) {
throw new AssertionError("Worker thread " + t.id + " finished with an exception: " + t.threadResult, t.threadResult);
}
}
List<Long> allValues = new ArrayList<>();
for (WorkerThread t : workerThreads) {
allValues.addAll(t.values);
}
if (alwaysOrder || workerThreads.length > 1) {
Collections.sort(allValues);
}
logger.trace("Checking a list of {} values", allValues.size());
for (int i = 0; i < allValues.size(); i++) {
if (allValues.get(i) != i) {
logger.error("Incorrect value at position {}: {}", i, allValues.get(i));
for (WorkerThread t : workerThreads) {
display("Thread " + t.id + ": " + t.values);
}
fail("Incorrect value at position " + i + ": " + allValues.get(i));
}
}
}
Aggregations