Skip to content

Commit

Permalink
Merge branch 'maintenance/3.3.x' into bugfix/240-Helper-annotation-cr…
Browse files Browse the repository at this point in the history
…eated-by-SelectFS-should-not-survive

* maintenance/3.3.x:
  #238 - Form 6 serializes non-reachable FSes but should not
  Issue #238 - Form 6 serializes non-reachable FSes but should not
  • Loading branch information
reckart committed Jul 30, 2022
2 parents b7225a4 + 6baa0c1 commit 819c18d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ private void processIndexedFeatureStructures(final CASImpl cas1, boolean isWrite
if (!isWrite) {
// always have form 6 do just reachables, to mimic what v2 did
AllFSs allFSs;
try (AutoCloseableNoException a = LowLevelCAS.ll_defaultV2IdRefs(false)) {
try (AutoCloseableNoException a = cas1.ll_enableV2IdRefs(false)) {
allFSs = new AllFSs(cas1, mark, isTypeMapping ? fs -> isTypeInTgt(fs) : null,
isTypeMapping ? typeMapper : null).getAllFSsAllViews_sofas_reachable();
// AllFSs internally already causes _save_to_cas_data() to be called, so we have to add all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.util.AutoCloseableNoException;
import org.apache.uima.util.CasCreationUtils;
import org.apache.uima.util.impl.SerializationMeasures;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -420,15 +419,6 @@ public void testAllKinds() {
}
}

@Test
public void testAllKindsV2() {
try (AutoCloseableNoException a = LowLevelCAS.ll_defaultV2IdRefs();
AutoCloseableNoException b = casSrc.ll_enableV2IdRefs()) { // because casSrc set in
// setup
testAllKinds();
}
}

// Test chains going through filtered type
// Repeat below with OneType, and TwoTypes with filtered slot == fsRef

Expand Down
40 changes: 40 additions & 0 deletions uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.uima.util;

import static java.util.Arrays.asList;
import static org.apache.uima.cas.SerialFormat.COMPRESSED_FILTERED_TSI;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.ByteArrayInputStream;
Expand All @@ -32,14 +33,18 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.SerialFormat;
import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.resource.metadata.FsIndexDescription;
import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
Expand Down Expand Up @@ -337,6 +342,41 @@ public void testDocumentAnnotationIsNotResurrected() throws Exception {
.extracting(fs -> fs.getType().getName()).containsExactly(customDocAnnoTypeName);
}

@Test
public void thatBinaryForm6DoesOnlyIncludeReachableFSes() throws Exception {
CASImpl cas = (CASImpl) CasCreationUtils.createCas();
byte[] buf;
try (AutoCloseableNoException a = cas.ll_enableV2IdRefs(true)) {
Annotation ann = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
ann.addToIndexes();
ann.removeFromIndexes();

Set<FeatureStructure> allFSes = new LinkedHashSet<>();
cas.walkReachablePlusFSsSorted(allFSes::add, null, null, null);

assertThat(allFSes) //
.as("The annotation that was added and then removed before serialization should be found") //
.containsExactly(cas.getSofa(), ann);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
CasIOUtils.save(cas, bos, COMPRESSED_FILTERED_TSI);
buf = bos.toByteArray();
}

cas.reset();

try (AutoCloseableNoException a = cas.ll_enableV2IdRefs(true)) {
CasIOUtils.load(new ByteArrayInputStream(buf), cas);

Set<FeatureStructure> allFSes = new LinkedHashSet<>();
cas.walkReachablePlusFSsSorted(allFSes::add, null, null, null);

assertThat(allFSes) //
.as("The annotation that was added and then removed before serialization should not be found") //
.containsExactly(cas.getSofa());
}
}

@AfterEach
public void tearDown() throws Exception {
cas.release();
Expand Down

0 comments on commit 819c18d

Please sign in to comment.