Skip to content

Commit

Permalink
refactor(#3390): Remove asset links when deleting a measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Jan 3, 2025
1 parent 4760477 commit 9b13132
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface IDataExplorerSchemaManagement {

DataLakeMeasure getById(String elementId);

DataLakeMeasure getByMeasureName(String measureName);

DataLakeMeasure createOrUpdateMeasurement(DataLakeMeasure measure);

void deleteMeasurement(String elementId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public DataLakeMeasure getById(String elementId) {
return dataLakeStorage.getElementById(elementId);
}

@Override
public DataLakeMeasure getByMeasureName(String measureName) {
return this.getExistingMeasureByName(measureName).orElse(null);
}

/**
* For new measurements an entry is generated in the database. For existing measurements the schema is updated
* according to the update strategy defined by the measurement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
Expand All @@ -47,22 +48,49 @@ public class DataExplorerSchemaManagementTest {
public static final String OLD_PROPERTY = "oldProperty";

private CRUDStorage<DataLakeMeasure> dataLakeStorageMock;
private DataExplorerSchemaManagement dataExplorerSchemaManagement;

@BeforeEach
public void setUp() {
dataLakeStorageMock = mock(CRUDStorage.class);
dataExplorerSchemaManagement = new DataExplorerSchemaManagement(dataLakeStorageMock);
}


@Test
public void getByMeasureName_ReturnsMeasureWhenMeasureExists() {
var measureName = "existingMeasure";
var existingMeasure = new DataLakeMeasure();
existingMeasure.setMeasureName(measureName);

when(dataLakeStorageMock.findAll()).thenReturn(List.of(existingMeasure));

var result = dataExplorerSchemaManagement.getByMeasureName(measureName);

assertEquals(existingMeasure, result);
}

@Test
public void getByMeasureName_ReturnsNullWhenMeasureDoesNotExist() {
var measureName = "nonExistingMeasure";

when(dataLakeStorageMock.findAll()).thenReturn(List.of());

var result = dataExplorerSchemaManagement.getByMeasureName(measureName);

assertNull(result);
}


@Test
public void createMeasurementThatNotExisted() {
public void createOrUpdateMeasuremente_ThatNotExisted() {
when(dataLakeStorageMock.findAll()).thenReturn(List.of());
var schemaManagement = new DataExplorerSchemaManagement(dataLakeStorageMock);

var oldMeasure = getSampleMeasure(
DataLakeMeasureSchemaUpdateStrategy.UPDATE_SCHEMA,
List.of()
);
var resultingMeasure = schemaManagement.createOrUpdateMeasurement(oldMeasure);
var resultingMeasure = dataExplorerSchemaManagement.createOrUpdateMeasurement(oldMeasure);

assertEquals(oldMeasure.getMeasureName(), resultingMeasure.getMeasureName());
verify(dataLakeStorageMock, Mockito.times(1))
Expand All @@ -71,7 +99,7 @@ public void createMeasurementThatNotExisted() {


@Test
public void createMeasurementWithUpdateStrategy() {
public void createOrUpdateMeasuremente_WithUpdateStrategy() {

var oldMeasure = getSampleMeasure(
DataLakeMeasureSchemaUpdateStrategy.UPDATE_SCHEMA,
Expand All @@ -82,11 +110,10 @@ public void createMeasurementWithUpdateStrategy() {

when(dataLakeStorageMock.findAll()).thenReturn(List.of(oldMeasure));
when(dataLakeStorageMock.getElementById(any())).thenReturn(oldMeasure);
var schemaManagement = new DataExplorerSchemaManagement(dataLakeStorageMock);

var newMeasure = getNewMeasure(DataLakeMeasureSchemaUpdateStrategy.UPDATE_SCHEMA);

var resultMeasure = schemaManagement.createOrUpdateMeasurement(newMeasure);
var resultMeasure = dataExplorerSchemaManagement.createOrUpdateMeasurement(newMeasure);

assertEquals(newMeasure.getMeasureName(), resultMeasure.getMeasureName());
verify(dataLakeStorageMock, Mockito.times(1))
Expand All @@ -98,7 +125,7 @@ public void createMeasurementWithUpdateStrategy() {


@Test
public void createMeasurementWithExtendSchemaStrategy() {
public void createOrUpdateMeasuremente_WithExtendSchemaStrategy() {

var oldMeasure = getSampleMeasure(
DataLakeMeasureSchemaUpdateStrategy.EXTEND_EXISTING_SCHEMA,
Expand All @@ -108,10 +135,9 @@ public void createMeasurementWithExtendSchemaStrategy() {
);
when(dataLakeStorageMock.findAll()).thenReturn(List.of(oldMeasure));
when(dataLakeStorageMock.getElementById(any())).thenReturn(oldMeasure);
var schemaManagement = new DataExplorerSchemaManagement(dataLakeStorageMock);
var newMeasure = getNewMeasure(DataLakeMeasureSchemaUpdateStrategy.EXTEND_EXISTING_SCHEMA);

var resultMeasure = schemaManagement.createOrUpdateMeasurement(newMeasure);
var resultMeasure = dataExplorerSchemaManagement.createOrUpdateMeasurement(newMeasure);

assertEquals(newMeasure.getMeasureName(), resultMeasure.getMeasureName());
verify(dataLakeStorageMock, Mockito.times(1)).updateElement(any());
Expand All @@ -121,7 +147,7 @@ public void createMeasurementWithExtendSchemaStrategy() {


@Test
public void createMeasurementWithExtendSchemaStrategyAndDifferentPropertyTypes() {
public void createOrUpdateMeasuremente_WithExtendSchemaStrategyAndDifferentPropertyTypes() {
var oldMeasure = getSampleMeasure(
DataLakeMeasureSchemaUpdateStrategy.EXTEND_EXISTING_SCHEMA,
List.of(
Expand All @@ -133,11 +159,9 @@ public void createMeasurementWithExtendSchemaStrategyAndDifferentPropertyTypes()
when(dataLakeStorageMock.findAll()).thenReturn(List.of(oldMeasure));
when(dataLakeStorageMock.getElementById(any())).thenReturn(oldMeasure);

var schemaManagement = new DataExplorerSchemaManagement(dataLakeStorageMock);

var newMeasure = getNewMeasure(DataLakeMeasureSchemaUpdateStrategy.EXTEND_EXISTING_SCHEMA);

var resultMeasure = schemaManagement.createOrUpdateMeasurement(newMeasure);
var resultMeasure = dataExplorerSchemaManagement.createOrUpdateMeasurement(newMeasure);
assertEquals(newMeasure.getMeasureName(), resultMeasure.getMeasureName());
verify(dataLakeStorageMock, Mockito.times(1)).updateElement(any());
assertEquals(
Expand Down
5 changes: 5 additions & 0 deletions streampipes-platform-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<artifactId>streampipes-platform-services</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.streampipes</groupId>
<artifactId>streampipes-asset-model-management</artifactId>
<version>0.98.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.streampipes</groupId>
<artifactId>streampipes-data-explorer-export</artifactId>
Expand Down
Loading

0 comments on commit 9b13132

Please sign in to comment.