Skip to content

Commit

Permalink
Feature/ar 156 update data its part1 (ikmdev#40)
Browse files Browse the repository at this point in the history
* update test helper and test constants

* update integration tests to use new test helper and test constants

* fix import * occurrences

* fix bindings generation and test

* fix import * occurences

* formatting cleanup
  • Loading branch information
rbradley813 authored Sep 27, 2024
1 parent 884dff8 commit 5b331a6
Show file tree
Hide file tree
Showing 31 changed files with 422 additions and 378 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void startup(File datastoreRootLocation){
LOG.info("Datastore location: " + datastoreRootLocation);
CachingService.clearAll();
ServiceProperties.set(ServiceKeys.DATA_STORE_ROOT, datastoreRootLocation);
PrimitiveData.selectControllerByName(TestConstants.SA_STORE_OPEN_NAME);
PrimitiveData.selectControllerByName("Open SpinedArrayStore");
PrimitiveData.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,18 @@
import java.util.function.Function;

public class TestConstants {
public static final Function<String, File> createFilePathInTarget = (pathName) -> new File("%s/target/%s".formatted(System.getProperty("user.dir"), pathName));
public static final Function<String,File> createFilePathInTarget = (pathName) -> new File("%s/target/%s".formatted(System.getProperty("user.dir"), pathName));

public static final Function<Class, File>
public static final Function<Class,File>
createFilePathInTargetFromClassName = (clazz) -> createFilePathInTarget.apply("generated-datastores/%s".formatted(clazz.getSimpleName()));

public static final File TINK_TEST_FILE = createFilePathInTarget.apply("data/tinkar-test-dto-1.1.0.zip");
public static final File PB_TEST_FILE = createFilePathInTarget.apply("data/tinkar-export-test.pb.zip");
// IKM Test Data Files
public static final File PB_STARTER_DATA = createFilePathInTarget.apply("data/tinkar-starter-data-1.0.0-pb.zip");
public static final File PB_STARTER_DATA_REASONED = createFilePathInTarget.apply("data/tinkar-starter-data-reasoned-1.0.0-pb.zip");

// Other Helper Files
public static final File PB_TEST_FILE = createFilePathInTarget.apply("data/tinkar-export-test.pb.zip");
public static final File PB_ROUNDTRIP_TEST_FILE = createFilePathInTarget.apply("data/tinkar-export-test-roundtrip.pb.zip");
public static final File PB_PERFORMANCE_TEST_FILE = createFilePathInTarget.apply("data/tinkar-export-test-performance.pb.zip");

public static final String MV_STORE_OPEN_NAME = "Open MV Store";
public static final String EPHEMERAL_STORE_NAME = "Load Ephemeral Store";
public static final String SA_STORE_OPEN_NAME = "Open SpinedArrayStore";
public static final File SNOMED_CT_DATA = createFilePathInTarget.apply("data/snomedct-2023.09.01.zip");

}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dev.ikm.tinkar.entity.EntityCountSummary;
import dev.ikm.tinkar.entity.EntityService;
import dev.ikm.tinkar.integration.TestConstants;
import dev.ikm.tinkar.integration.helper.DataStore;
import dev.ikm.tinkar.integration.helper.TestHelper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -30,13 +31,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class EntityServiceIT extends TestHelper {
class EntityServiceIT {

private static final File SAP_DATASTORE_ROOT = TestConstants.createFilePathInTargetFromClassName.apply(EntityServiceIT.class);

private static final File SAP_DATASTORE_ROOT = TestConstants.createFilePathInTargetFromClassName.apply(
EntityServiceIT.class);
@BeforeEach
public void init() {
loadSpinedArrayDataBase(SAP_DATASTORE_ROOT);
void beforeEach() {
TestHelper.startDataBase(DataStore.SPINED_ARRAY_STORE, SAP_DATASTORE_ROOT);
TestHelper.loadDataFile(TestConstants.PB_STARTER_DATA_REASONED);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,45 @@
import dev.ikm.tinkar.coordinate.stamp.calculator.Latest;
import dev.ikm.tinkar.coordinate.stamp.calculator.StampCalculatorWithCache;
import dev.ikm.tinkar.coordinate.view.calculator.ViewCalculator;
import dev.ikm.tinkar.entity.*;
import dev.ikm.tinkar.entity.ConceptEntity;
import dev.ikm.tinkar.entity.ConceptEntityVersion;
import dev.ikm.tinkar.entity.Entity;
import dev.ikm.tinkar.entity.EntityService;
import dev.ikm.tinkar.entity.SemanticEntity;
import dev.ikm.tinkar.integration.TestConstants;
import dev.ikm.tinkar.integration.helper.DataStore;
import dev.ikm.tinkar.integration.helper.TestHelper;
import dev.ikm.tinkar.terms.TinkarTerm;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.set.ImmutableSet;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.Optional;

import static dev.ikm.tinkar.terms.TinkarTerm.PATH_ORIGINS_PATTERN;


@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class CoordinatesIT extends TestHelper {
class CoordinatesIT {

private static final Logger LOG = LoggerFactory.getLogger(CoordinatesIT.class);
private static final File SAP_DATASTORE_ROOT = TestConstants.createFilePathInTargetFromClassName.apply(
private static final File DATASTORE_ROOT = TestConstants.createFilePathInTargetFromClassName.apply(
CoordinatesIT.class);

@BeforeAll
static void setupSuite() throws IOException {
loadSpinedArrayDataBase(SAP_DATASTORE_ROOT);
static void beforeAll() {
TestHelper.startDataBase(DataStore.SPINED_ARRAY_STORE, DATASTORE_ROOT);
TestHelper.loadDataFile(TestConstants.PB_STARTER_DATA_REASONED);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@

import dev.ikm.tinkar.common.id.IntIds;
import dev.ikm.tinkar.coordinate.Coordinates;
import dev.ikm.tinkar.coordinate.stamp.*;
import dev.ikm.tinkar.coordinate.stamp.StampCoordinateRecord;
import dev.ikm.tinkar.coordinate.stamp.StampCoordinateRecordBuilder;
import dev.ikm.tinkar.coordinate.stamp.StampPositionRecord;
import dev.ikm.tinkar.coordinate.stamp.StampPositionRecordBuilder;
import dev.ikm.tinkar.coordinate.stamp.StateSet;
import dev.ikm.tinkar.coordinate.stamp.calculator.Latest;
import dev.ikm.tinkar.coordinate.stamp.calculator.StampCalculator;
import dev.ikm.tinkar.entity.EntityService;
import dev.ikm.tinkar.entity.SemanticEntityVersion;
import dev.ikm.tinkar.entity.StampEntity;
import dev.ikm.tinkar.entity.StampEntityVersion;
import dev.ikm.tinkar.integration.TestConstants;
import dev.ikm.tinkar.integration.helper.DataStore;
import dev.ikm.tinkar.integration.helper.TestHelper;
import dev.ikm.tinkar.terms.TinkarTerm;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,15 +52,16 @@

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class QueryByTimeIT extends TestHelper {
public class QueryByTimeIT {

private static final Logger LOG = LoggerFactory.getLogger(QueryByTimeIT.class);
private static final File SAP_COORDINATESIT_DATASTORE_ROOT = TestConstants.createFilePathInTargetFromClassName.apply(
private static final File DATASTORE_ROOT = TestConstants.createFilePathInTargetFromClassName.apply(
QueryByTimeIT.class);

@BeforeAll
public void init() {
loadSpinedArrayDataBase(SAP_COORDINATESIT_DATASTORE_ROOT);
public void beforeAll() {
TestHelper.startDataBase(DataStore.SPINED_ARRAY_STORE, DATASTORE_ROOT);
TestHelper.loadDataFile(TestConstants.PB_STARTER_DATA_REASONED);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2015 Integrated Knowledge Management ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.ikm.tinkar.integration.helper;

public enum DataStore {
SPINED_ARRAY_STORE("Open SpinedArrayStore"),
EPHEMERAL_STORE("Load Ephemeral Store"),
MV_STORE("Open MV Store");

final String CONTROLLER_NAME;

DataStore(String contollerName) {
this.CONTROLLER_NAME = contollerName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,75 +21,48 @@
import dev.ikm.tinkar.common.service.ServiceProperties;
import dev.ikm.tinkar.entity.EntityCountSummary;
import dev.ikm.tinkar.entity.load.LoadEntitiesFromProtobufFile;
import dev.ikm.tinkar.integration.TestConstants;
import org.junit.jupiter.api.AfterAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

import static dev.ikm.tinkar.integration.TestConstants.PB_STARTER_DATA_REASONED;

public class TestHelper {

private static final Logger LOG = LoggerFactory.getLogger(TestHelper.class);

protected static void startEphemeralDataBase() {
public static void startDataBase(DataStore dataStore, File fileDataStore) {
if (fileDataStore.exists()) {
LOG.warn("Datastore {} already exists. Loading this datastore may impact test results.\n" +
"Consider leveraging Maven's clean lifecycle phase or `FileUtil.recursiveDelete` during test setup.", fileDataStore.getName());
}
CachingService.clearAll();
LOG.info("Cleared caches");
LOG.info("JVM Version: " + System.getProperty("java.version"));
LOG.info("JVM Name: " + System.getProperty("java.vm.name"));
LOG.info("Setup Ephemeral Suite: " + LOG.getName());
LOG.info(ServiceProperties.jvmUuid());
PrimitiveData.selectControllerByName(TestConstants.EPHEMERAL_STORE_NAME);
PrimitiveData.start();
ServiceProperties.set(ServiceKeys.DATA_STORE_ROOT, fileDataStore);
startDataController(dataStore);
}

protected static void startSpinedArrayDataBase(File fileDataStore) {
LOG.info("Clear caches");
public static void startDataBase(DataStore dataStore) {
CachingService.clearAll();
LOG.info("Setup Suite: " + LOG.getName());
LOG.info(ServiceProperties.jvmUuid());
ServiceProperties.set(ServiceKeys.DATA_STORE_ROOT, fileDataStore);
//FileUtil.recursiveDelete(fileDataStore);
PrimitiveData.selectControllerByName(TestConstants.SA_STORE_OPEN_NAME);
PrimitiveData.start();
LOG.info("Cleared caches");
startDataController(dataStore);
}

protected static void startMVStoreDataBase(File fileDataStore) {
LOG.info("Clear caches");
CachingService.clearAll();
LOG.info("Setup suite: " + LOG.getName());
private static void startDataController(DataStore dataStore) {
LOG.info("JVM Version: " + System.getProperty("java.version"));
LOG.info("JVM Name: " + System.getProperty("java.vm.name"));
LOG.info(ServiceProperties.jvmUuid());
ServiceProperties.set(ServiceKeys.DATA_STORE_ROOT, fileDataStore);
PrimitiveData.selectControllerByName(TestConstants.MV_STORE_OPEN_NAME);
PrimitiveData.selectControllerByName(dataStore.CONTROLLER_NAME);
PrimitiveData.start();
}

protected static void loadEphemeralDataBase() {
startEphemeralDataBase();
loadDataBase();
}

protected static void loadSpinedArrayDataBase(File fileDataStore) {
startSpinedArrayDataBase(fileDataStore);
loadDataBase();
public static EntityCountSummary loadDataFile(File dataFile){
EntityCountSummary entityCountSummary = new LoadEntitiesFromProtobufFile(dataFile).compute();
LOG.info("Import complete for {}. Imported {} Entities.", dataFile.getName(), entityCountSummary.getTotalCount());
return entityCountSummary;
}

protected static void loadMVStoreDataBase(File fileDataStore) {
startMVStoreDataBase(fileDataStore);
loadDataBase();
}

protected static void loadDataBase() {
LoadEntitiesFromProtobufFile loadProto = new LoadEntitiesFromProtobufFile(PB_STARTER_DATA_REASONED);
EntityCountSummary count = loadProto.compute();
LOG.info(count + " entitles loaded from file: " + loadProto.summarize() + "\n\n");
}

@AfterAll
protected static void stopDatabase() {
public static void stopDatabase() {
LOG.info("Teardown Suite: " + LOG.getName());
PrimitiveData.stop();
}

}
Loading

0 comments on commit 5b331a6

Please sign in to comment.