Skip to content

Commit

Permalink
Issue #379: Clean up code
Browse files Browse the repository at this point in the history
- Fix index protection tests
  • Loading branch information
reckart committed Sep 2, 2024
1 parent 78462fb commit 7270128
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
1 change: 0 additions & 1 deletion uimaj-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j-version}</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public class CASImpl extends AbstractCas_ImplBase
public static final String THROW_EXCEPTION_FS_UPDATES_CORRUPTS = "uima.exception_when_fs_update_corrupts_index";

/**
* @deprecate Will become package private.
* @deprecated Will become package private.
* @forRemoval 4.0.0
*/
// public for test case use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
* under the License.
*/

package org.apache.uima.cas.test;
package org.apache.uima.cas.impl;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import org.apache.uima.UIMARuntimeException;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
import org.apache.uima.cas.FSIndex;
Expand All @@ -35,9 +37,8 @@
import org.apache.uima.cas.admin.LinearTypeOrder;
import org.apache.uima.cas.admin.LinearTypeOrderBuilder;
import org.apache.uima.cas.admin.TypeSystemMgr;
import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.cas.impl.LinearTypeOrderBuilderImpl;
import org.apache.uima.cas.impl.TypeSystemImpl;
import org.apache.uima.cas.test.AnnotatorInitializer;
import org.apache.uima.cas.test.CASInitializer;
import org.apache.uima.test.junit_extension.JUnitExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -135,14 +136,8 @@ class IndexComparitorTest {

private FSIndex<FeatureStructure> bagType1Sub1TypeOrder;

/**
* class which sets up
*/
private class SetupForIndexCompareTesting implements AnnotatorInitializer {

/**
* @see org.apache.uima.cas.test.AnnotatorInitializer#initTypeSystem(TypeSystemMgr)
*/
@Override
public void initTypeSystem(TypeSystemMgr tsm) {
// Add new types and features.
Expand Down Expand Up @@ -245,7 +240,7 @@ private LinearTypeOrder newTypeOrder() {
}

@BeforeEach
public void setUp() throws Exception {
void setUp() throws Exception {
try {
cas = CASInitializer.initCas(new SetupForIndexCompareTesting(), ts -> reinitTypes(ts));
assertThat(cas).isNotNull();
Expand Down Expand Up @@ -325,7 +320,7 @@ private void reinitTypes(TypeSystemImpl tsm) {
}

@AfterEach
public void tearDown() {
void tearDown() {
fss = null;
cas = null;
ts = null;
Expand Down Expand Up @@ -567,18 +562,18 @@ void testSetUsesType() throws Exception {
// note: this test is here because the setup is done
@Test
void testProtectIndex() throws Exception {
FSIterator<FeatureStructure> it = sortedType1.iterator();
FeatureStructure fs = it.get();
boolean ok = false;
var fs = sortedType1.iterator().get();

var oldIsReportFsUpdatesCorrputs = CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX;
var oldIsThrowExceptionCorruptIndes = CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX;
try {
System.setProperty(CASImpl.THROW_EXCEPTION_FS_UPDATES_CORRUPTS, "true");
fs.setBooleanValue(type1UsedBoolean, !fs.getBooleanValue(type1UsedBoolean)); // should cause
// protection
} catch (Exception e) {
ok = true;
CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX = true;
CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX = true;
assertThatExceptionOfType(UIMARuntimeException.class).isThrownBy(
() -> fs.setBooleanValue(type1UsedBoolean, !fs.getBooleanValue(type1UsedBoolean)));
} finally {
System.clearProperty(CASImpl.THROW_EXCEPTION_FS_UPDATES_CORRUPTS);
CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX = oldIsThrowExceptionCorruptIndes;
CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX = oldIsReportFsUpdatesCorrputs;
}
assertThat(CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX ? ok : !ok).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class IndexCorruptionReportingTest {
@BeforeAll
static void setupClass() {
oldReportFsUpdateCorruptsIndex = CASImpl.IS_REPORT_FS_UPDATE_CORRUPTS_INDEX = true;
disableAutoProtectIndexes = CASImpl.IS_DISABLED_PROTECT_INDEXES = true;
disableAutoProtectIndexes = CASImpl.IS_DISABLED_PROTECT_INDEXES = false;
exceptionWhenFsUpdateCorruptsIndex = CASImpl.IS_THROW_EXCEPTION_CORRUPT_INDEX = true;
}

Expand Down

0 comments on commit 7270128

Please sign in to comment.