Search in sources :

Example 1 with EXCLUSIVE_WRITE_ACCESS

use of de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.EXCLUSIVE_WRITE_ACCESS in project webanno by webanno.

the class CasStorageServiceImplTest method testRestorationOfCasWhenSaveFails.

@Test
public void testRestorationOfCasWhenSaveFails() throws Exception {
    try (CasStorageSession casStorageSession = openNested(true)) {
        // Setup fixture
        SourceDocument doc = makeSourceDocument(6l, 6l, "test");
        String user = "test";
        File casFile = sut.getCasFile(doc, user);
        long casFileSize;
        long casFileLastModified;
        try (CasStorageSession session = openNested(true)) {
            createCasFile(doc, user, "This is a test");
            assertThat(casFile).exists();
            casFileSize = casFile.length();
            casFileLastModified = casFile.lastModified();
        }
        CAS mainCas = sut.readCas(doc, user, EXCLUSIVE_WRITE_ACCESS);
        // Wrap the CAS in a proxy so that UIMA cannot serialize it
        CAS guardedCas = (CAS) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { CAS.class }, (proxy, method, args) -> method.invoke(mainCas, args));
        assertThatExceptionOfType(IOException.class).as("Saving fails because UIMA cannot cast the proxied CAS to something serializable").isThrownBy(() -> sut.writeCas(doc, guardedCas, user)).withRootCauseInstanceOf(ClassCastException.class);
        assertThat(casFile).exists().hasSize(casFileSize);
        assertThat(casFile.lastModified()).isEqualTo(casFileLastModified);
        assertThat(new File(casFile.getParentFile(), user + ".ser.old")).doesNotExist();
    }
}
Also used : CasStorageSession.openNested(de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession.openNested) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) UNMANAGED_NON_INITIALIZING_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_NON_INITIALIZING_ACCESS) UNMANAGED_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_ACCESS) RepositoryProperties(de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) CASException(org.apache.uima.cas.CASException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LayerConfigurationChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent) Arrays.asList(java.util.Arrays.asList) Thread.sleep(java.lang.Thread.sleep) CasFactory.createCas(org.apache.uima.fit.factory.CasFactory.createCas) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) JCas(org.apache.uima.jcas.JCas) CasStorageSession(de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession) CasSessionException(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasSessionException) StringUtils.repeat(org.apache.commons.lang3.StringUtils.repeat) FORCE_CAS_UPGRADE(de.tudarmstadt.ukp.clarin.webanno.api.CasUpgradeMode.FORCE_CAS_UPGRADE) FileNotFoundException(java.io.FileNotFoundException) AUTO_CAS_UPGRADE(de.tudarmstadt.ukp.clarin.webanno.api.CasUpgradeMode.AUTO_CAS_UPGRADE) List(java.util.List) EXCLUSIVE_WRITE_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.EXCLUSIVE_WRITE_ACCESS) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) CasMetadataUtils.getInternalTypeSystem(de.tudarmstadt.ukp.clarin.webanno.api.dao.CasMetadataUtils.getInternalTypeSystem) CasProvider(de.tudarmstadt.ukp.clarin.webanno.api.CasProvider) Proxy(java.lang.reflect.Proxy) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) CASMetadata(de.tudarmstadt.ukp.clarin.webanno.api.type.CASMetadata) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CAS(org.apache.uima.cas.CAS) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) NO_CAS_UPGRADE(de.tudarmstadt.ukp.clarin.webanno.api.CasUpgradeMode.NO_CAS_UPGRADE) ArrayList(java.util.ArrayList) CasFactory(org.apache.uima.fit.factory.CasFactory) CasCreationUtils.mergeTypeSystems(org.apache.uima.util.CasCreationUtils.mergeTypeSystems) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JCasFactory(org.apache.uima.fit.factory.JCasFactory) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) INITIAL_CAS_PSEUDO_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER) SHARED_READ_ONLY_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.SHARED_READ_ONLY_ACCESS) Before(org.junit.Before) Logger(org.slf4j.Logger) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) Rule(org.junit.Rule) JCasUtil.select(org.apache.uima.fit.util.JCasUtil.select) TemporaryFolder(org.junit.rules.TemporaryFolder) CAS(org.apache.uima.cas.CAS) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) IOException(java.io.IOException) CasStorageSession(de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession) File(java.io.File) Test(org.junit.Test)

Aggregations

CasProvider (de.tudarmstadt.ukp.clarin.webanno.api.CasProvider)1 AUTO_CAS_UPGRADE (de.tudarmstadt.ukp.clarin.webanno.api.CasUpgradeMode.AUTO_CAS_UPGRADE)1 FORCE_CAS_UPGRADE (de.tudarmstadt.ukp.clarin.webanno.api.CasUpgradeMode.FORCE_CAS_UPGRADE)1 NO_CAS_UPGRADE (de.tudarmstadt.ukp.clarin.webanno.api.CasUpgradeMode.NO_CAS_UPGRADE)1 RepositoryProperties (de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties)1 INITIAL_CAS_PSEUDO_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER)1 EXCLUSIVE_WRITE_ACCESS (de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.EXCLUSIVE_WRITE_ACCESS)1 SHARED_READ_ONLY_ACCESS (de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.SHARED_READ_ONLY_ACCESS)1 UNMANAGED_ACCESS (de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_ACCESS)1 UNMANAGED_NON_INITIALIZING_ACCESS (de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_NON_INITIALIZING_ACCESS)1 CasSessionException (de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasSessionException)1 CasMetadataUtils.getInternalTypeSystem (de.tudarmstadt.ukp.clarin.webanno.api.dao.CasMetadataUtils.getInternalTypeSystem)1 CasStorageSession (de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession)1 CasStorageSession.openNested (de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession.openNested)1 LayerConfigurationChangedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent)1 CASMetadata (de.tudarmstadt.ukp.clarin.webanno.api.type.CASMetadata)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1