Search in sources :

Example 41 with SequenceType

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);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 42 with SequenceType

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));
        }
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)

Aggregations

SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)33 CloseSequenceType (org.apache.cxf.ws.rm.v200702.CloseSequenceType)12 RMProperties (org.apache.cxf.ws.rm.RMProperties)11 CreateSequenceType (org.apache.cxf.ws.rm.v200702.CreateSequenceType)11 TerminateSequenceType (org.apache.cxf.ws.rm.v200702.TerminateSequenceType)11 SequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)9 Message (org.apache.cxf.message.Message)8 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 IOException (java.io.IOException)6 Unmarshaller (javax.xml.bind.Unmarshaller)5 AckRequestedType (org.apache.cxf.ws.rm.v200702.AckRequestedType)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Exchange (org.apache.cxf.message.Exchange)4 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)4 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)4 Test (org.junit.Test)4 Test (org.testng.annotations.Test)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3