Search in sources :

Example 1 with ConcurrentUoWFileModificationException

use of org.qi4j.library.uowfile.internal.ConcurrentUoWFileModificationException in project qi4j-sdk by Qi4j.

the class HasUoWFilesTest method testConcurrentModification.

@Test
public void testConcurrentModification() throws IOException, UnitOfWorkCompletionException {
    LOGGER.info("# Test Concurrent Modification ###############################################################");
    final String entityId;
    // Create new
    try (UnitOfWork uow = module.newUnitOfWork()) {
        TestedEntity entity = createTestedOneEntityTwoFilesEntity(uow, "Testing Concurrent Modification");
        entityId = entity.identity().get();
        uow.complete();
    }
    // Testing concurrent modification
    UnitOfWork uow, uow2;
    TestedEntity entity;
    uow = module.newUnitOfWork();
    entity = uow.get(TestedEntity.class, entityId);
    Inputs.text(MODIFICATION_CONTENT_URL).transferTo(Outputs.text(entity.managedFile(MyEnum.fileOne)));
    uow2 = module.newUnitOfWork();
    entity = uow2.get(TestedEntity.class, entityId);
    Inputs.text(MODIFICATION_CONTENT_URL).transferTo(Outputs.text(entity.managedFile(MyEnum.fileOne)));
    uow.complete();
    try {
        uow2.complete();
        fail("A ConcurrentUoWFileModificationException should have been raised");
    } catch (ConcurrentUoWFileModificationException expected) {
        uow2.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentUoWFileModificationException(org.qi4j.library.uowfile.internal.ConcurrentUoWFileModificationException) Test(org.junit.Test)

Example 2 with ConcurrentUoWFileModificationException

use of org.qi4j.library.uowfile.internal.ConcurrentUoWFileModificationException in project qi4j-sdk by Qi4j.

the class HasUoWFileTest method testConcurrentModification.

@Test
public void testConcurrentModification() throws IOException, UnitOfWorkCompletionException {
    LOGGER.info("# Test Concurrent Modification ###############################################################");
    final String entityId;
    // Create new
    try (UnitOfWork uow = module.newUnitOfWork()) {
        TestedEntity entity = createTestedEntity(uow, "Testing Concurrent Modification");
        entityId = entity.identity().get();
        uow.complete();
    }
    // Testing concurrent modification
    UnitOfWork uow, uow2;
    TestedEntity entity;
    uow = module.newUnitOfWork();
    entity = uow.get(TestedEntity.class, entityId);
    Inputs.text(MODIFICATION_CONTENT_URL).transferTo(Outputs.text(entity.managedFile()));
    uow2 = module.newUnitOfWork();
    entity = uow2.get(TestedEntity.class, entityId);
    Inputs.text(MODIFICATION_CONTENT_URL).transferTo(Outputs.text(entity.managedFile()));
    uow.complete();
    try {
        uow2.complete();
        fail("A ConcurrentUoWFileModificationException should have been raised");
    } catch (ConcurrentUoWFileModificationException expected) {
        uow2.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) ConcurrentUoWFileModificationException(org.qi4j.library.uowfile.internal.ConcurrentUoWFileModificationException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)2 ConcurrentUoWFileModificationException (org.qi4j.library.uowfile.internal.ConcurrentUoWFileModificationException)2