Skip to content

Commit

Permalink
[Fix_#1923] Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Jan 15, 2024
1 parent 0cc6bca commit f7f0400
Show file tree
Hide file tree
Showing 94 changed files with 717 additions and 815 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.index;

package org.kie.kogito.index.event.mapper;
import java.util.Set;

public interface Merger<I, R> {
boolean accept(Object input);
public class CommonUtils {

private static final Set<String> finalStates = Set.of("Completed", "Aborted");

public static boolean isTaskCompleted(String status) {
return finalStates.contains(status);
}

R merge(R instance, I input);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,9 @@ public void indexProcessInstanceEvent(ProcessInstanceDataEvent<?> event) {
//retry in case of rare but possible race condition during the insert for the first registry
@Retry(maxRetries = 3, delay = 300, jitter = 100, retryOn = ConcurrentModificationException.class)
public void indexProcessDefinition(ProcessDefinitionDataEvent definitionDataEvent) {
String key = ProcessDefinition.toKey(definitionDataEvent.getKogitoProcessId(), definitionDataEvent.getData().getVersion());
ProcessDefinition definition = manager.getProcessDefinitionStorage().get(key);
if (definition == null) {
definition = new ProcessDefinition();
definition.setId(definitionDataEvent.getKogitoProcessId());
definition.setVersion(definitionDataEvent.getData().getVersion());
}
manager.getProcessDefinitionStorage().put(key, ProcessDefinitionHelper.merge(definition, definitionDataEvent));
ProcessDefinition definition = ProcessDefinitionHelper
.merge(manager.getProcessDefinitionStorage().get(ProcessDefinition.toKey(definitionDataEvent.getKogitoProcessId(), definitionDataEvent.getData().getVersion())), definitionDataEvent);
manager.getProcessDefinitionStorage().put(definition.getKey(), definition);
}

//retry in case of rare but possible race condition during the insert for the first registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@
public class ProcessDefinitionHelper {

public static ProcessDefinition merge(ProcessDefinition instance, ProcessDefinitionDataEvent event) {
if (event == null) {
return instance;
}
ProcessDefinitionEventBody data = event.getData();
if (data == null) {
return instance;
}
if (instance == null) {
instance = new ProcessDefinition();
}
instance.setId(doMerge(data.getId(), instance.getId()));
instance.setName(doMerge(data.getName(), instance.getName()));
instance.setVersion(doMerge(data.getVersion(), instance.getVersion()));
instance.setAddons(doMerge(data.getAddons(), instance.getAddons()));
instance.setRoles(doMerge(data.getRoles(), instance.getRoles()));
instance.setType(doMerge(data.getType(), instance.getType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.jupiter.api.Test;
import org.kie.kogito.index.model.ProcessInstance;
import org.kie.kogito.index.storage.DataIndexStorageService;
import org.kie.kogito.persistence.api.StorageService;
import org.kie.kogito.persistence.api.query.AttributeFilter;

import jakarta.inject.Inject;
Expand All @@ -36,6 +37,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.kie.kogito.index.model.ProcessInstanceState.ACTIVE;
import static org.kie.kogito.index.model.ProcessInstanceState.COMPLETED;
import static org.kie.kogito.index.storage.Constants.PROCESS_INSTANCES_STORAGE;
import static org.kie.kogito.index.test.TestUtils.getProcessInstance;
import static org.kie.kogito.persistence.api.query.QueryFilterFactory.between;
import static org.kie.kogito.persistence.api.query.QueryFilterFactory.contains;
Expand All @@ -55,6 +57,9 @@ public abstract class AbstractQueryIT {
@Inject
public DataIndexStorageService cacheService;

@Inject
public StorageService storageService;

@BeforeEach
void setup() {
cacheService.getProcessDefinitionStorage().clear();
Expand All @@ -74,8 +79,9 @@ void testProcessInstanceQueries() {
String subProcessId = processId + "_sub";
String subProcessInstanceId = UUID.randomUUID().toString();
ProcessInstance processInstance = getProcessInstance(processId, processInstanceId, ACTIVE.ordinal(), null, null);
cacheService.getProcessInstanceStorage().put(processInstanceId, processInstance);
cacheService.getProcessInstanceStorage().put(subProcessInstanceId, getProcessInstance(subProcessId, subProcessInstanceId, COMPLETED.ordinal(), processInstanceId, processId));
storageService.getCache(PROCESS_INSTANCES_STORAGE, ProcessInstance.class).put(processInstanceId, processInstance);
storageService.getCache(PROCESS_INSTANCES_STORAGE, ProcessInstance.class).put(subProcessInstanceId,
getProcessInstance(subProcessId, subProcessInstanceId, COMPLETED.ordinal(), processInstanceId, processId));

queryAndAssert(in("state", asList(ACTIVE.ordinal(), COMPLETED.ordinal())), processInstanceId, subProcessInstanceId);
queryAndAssert(equalTo("state", ACTIVE.ordinal()), processInstanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,29 @@
import org.kie.kogito.index.model.ProcessInstanceState;
import org.kie.kogito.index.storage.DataIndexStorageService;
import org.kie.kogito.persistence.api.Storage;
import org.kie.kogito.persistence.api.StorageService;

import jakarta.inject.Inject;

import static org.assertj.core.api.Assertions.assertThat;
import static org.kie.kogito.index.storage.Constants.PROCESS_INSTANCES_STORAGE;
import static org.kie.kogito.index.test.TestUtils.getProcessInstance;

public abstract class AbstractStorageIT {

@Inject
public DataIndexStorageService cacheService;

@Inject
public StorageService storageService;

@Test
void testObjectCreatedListener() throws Exception {
String processId = "travels";
String processInstanceId = UUID.randomUUID().toString();

CompletableFuture<ProcessInstance> cf = new CompletableFuture<>();
Storage<String, ProcessInstance> cache = cacheService.getProcessInstanceStorage();
Storage<String, ProcessInstance> cache = storageService.getCache(PROCESS_INSTANCES_STORAGE, ProcessInstance.class);
cache.objectCreatedListener().subscribe().with(pi -> cf.complete(pi));
cache.put(processInstanceId, getProcessInstance(processId, processInstanceId, ProcessInstanceState.ACTIVE.ordinal(), null, null));

Expand All @@ -59,7 +64,7 @@ void testObjectUpdatedListener() throws Exception {
String processInstanceId = UUID.randomUUID().toString();

CompletableFuture<ProcessInstance> cf = new CompletableFuture<>();
Storage<String, ProcessInstance> cache = cacheService.getProcessInstanceStorage();
Storage<String, ProcessInstance> cache = storageService.getCache(PROCESS_INSTANCES_STORAGE, ProcessInstance.class);
cache.objectUpdatedListener().subscribe().with(pi -> cf.complete(pi));
cache.put(processInstanceId, getProcessInstance(processId, processInstanceId, ProcessInstanceState.ACTIVE.ordinal(), null, null));
cache.put(processInstanceId, getProcessInstance(processId, processInstanceId, ProcessInstanceState.COMPLETED.ordinal(), null, null));
Expand All @@ -74,7 +79,7 @@ void testObjectRemovedListener() throws Exception {
String processInstanceId = UUID.randomUUID().toString();

CompletableFuture<String> cf = new CompletableFuture<>();
Storage<String, ProcessInstance> cache = cacheService.getProcessInstanceStorage();
Storage<String, ProcessInstance> cache = storageService.getCache(PROCESS_INSTANCES_STORAGE, ProcessInstance.class);
cache.objectRemovedListener().subscribe().with(id -> cf.complete(id));
cache.put(processInstanceId, getProcessInstance(processId, processInstanceId, ProcessInstanceState.ACTIVE.ordinal(), null, null));
cache.remove(processInstanceId);
Expand Down
Loading

0 comments on commit f7f0400

Please sign in to comment.