use of org.kie.kogito.persistence.api.schema.SchemaDescriptor in project kogito-apps by kiegroup.
the class ProtoSchemaManagerTest method onSchemaRegisteredEvent.
@Test
void onSchemaRegisteredEvent() {
String processId = "testProcessId";
String processType = "testProcessType";
ProcessDescriptor processDescriptor = new ProcessDescriptor(processId, processType);
String name = "testName";
String content = "testContent";
SchemaDescriptor schemaDescriptor = new SchemaDescriptor(name, content, emptyMap(), processDescriptor);
SchemaType schemaType = new SchemaType(ProtoSchemaAcceptor.PROTO_SCHEMA_TYPE);
SchemaRegisteredEvent event = new SchemaRegisteredEvent(schemaDescriptor, schemaType);
protoSchemaManager.onSchemaRegisteredEvent(event);
verify(protoSchemaAcceptor).accept(eq(schemaType));
verify(protobufCache).put(eq(name), eq(content));
verify(processIdModelCache).put(eq(processId), eq(processType));
verify(remoteCacheManagerAdmin).getOrCreateCache(eq(processId + "_domain"), any(BasicConfiguration.class));
verify(cacheManager).getDomainModelCacheName(processId);
verify(cacheTemplate).data("cache_name", processId + "_domain");
verify(templateInstance).data("indexed", emptySet());
}
use of org.kie.kogito.persistence.api.schema.SchemaDescriptor in project kogito-apps by kiegroup.
the class ProtoSchemaManagerTest method onSchemaRegisteredEventWithError.
@Test
void onSchemaRegisteredEventWithError() {
String processId = "testProcessId";
String processType = "testProcessType";
ProcessDescriptor processDescriptor = new ProcessDescriptor(processId, processType);
String name = "testName";
String content = "testContent";
SchemaDescriptor schemaDescriptor = new SchemaDescriptor(name, content, emptyMap(), processDescriptor);
SchemaType schemaType = new SchemaType(ProtoSchemaAcceptor.PROTO_SCHEMA_TYPE);
SchemaRegisteredEvent event = new SchemaRegisteredEvent(schemaDescriptor, schemaType);
when(protobufCache.containsKey(eq(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX))).thenReturn(true);
when(protobufCache.get(eq(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX))).thenReturn("testError");
assertThrows(SchemaRegistrationException.class, () -> protoSchemaManager.onSchemaRegisteredEvent(event));
verify(protoSchemaAcceptor).accept(eq(schemaType));
verify(protobufCache).put(eq(name), eq(content));
verify(processIdModelCache).put(eq(processId), eq(processType));
}
use of org.kie.kogito.persistence.api.schema.SchemaDescriptor in project kogito-apps by kiegroup.
the class ProtoSchemaManager method onSchemaRegisteredEvent.
public void onSchemaRegisteredEvent(@Observes SchemaRegisteredEvent event) {
if (schemaAcceptor.accept(event.getSchemaType())) {
SchemaDescriptor schemaDescriptor = event.getSchemaDescriptor();
Storage<String, String> cache = protobufCacheService.getProtobufCache();
cache.put(schemaDescriptor.getName(), schemaDescriptor.getSchemaContent());
schemaDescriptor.getProcessDescriptor().ifPresent(processDescriptor -> {
cacheManager.getProcessIdModelCache().put(processDescriptor.getProcessId(), processDescriptor.getProcessType());
// Initialize domain cache
String cacheName = cacheManager.getDomainModelCacheName(processDescriptor.getProcessId());
String cacheTemplateRendered = getTemplateRendered(schemaDescriptor, cacheName);
LOGGER.debug("Cache template: \n{}", cacheTemplateRendered);
manager.administration().getOrCreateCache(cacheName, new XMLStringConfiguration(cacheTemplateRendered));
});
List<String> errors = checkSchemaErrors(cache);
if (!errors.isEmpty()) {
String message = "Proto Schema contain errors:\n" + String.join("\n", errors);
throw new SchemaRegistrationException(message);
}
if (LOGGER.isDebugEnabled()) {
logProtoCacheKeys();
}
}
}
use of org.kie.kogito.persistence.api.schema.SchemaDescriptor in project kogito-apps by kiegroup.
the class ProtobufServiceTest method registerProtoBufferTypeSchemaRegistrationFailed.
@Test
void registerProtoBufferTypeSchemaRegistrationFailed() {
String testExceptionMessage = "test schema registration fail";
doThrow(new RuntimeException(testExceptionMessage)).when(schemaEvent).fire(any(SchemaRegisteredEvent.class));
String content = TestUtils.getTestFileContent();
String exceptionMessage = "";
try {
protobufService.registerProtoBufferType(content);
} catch (ProtobufValidationException e) {
exceptionMessage = e.getMessage();
}
assertEquals(testExceptionMessage, exceptionMessage);
verify(schemaEvent, times(1)).fire(new SchemaRegisteredEvent(new SchemaDescriptor(TestUtils.PROCESS_ID + ".proto", content, getValidEntityIndexDescriptors(true), new ProcessDescriptor(TestUtils.PROCESS_ID, TestUtils.PROCESS_TYPE)), SCHEMA_TYPE));
verify(domainModelEvent, never()).fire(any(FileDescriptorRegisteredEvent.class));
}
use of org.kie.kogito.persistence.api.schema.SchemaDescriptor in project kogito-apps by kiegroup.
the class IndexManagerIT method testOnSchemaRegisteredEvent.
@Test
void testOnSchemaRegisteredEvent() {
Map<String, EntityIndexDescriptor> indexes = new HashMap<>();
indexes.put("test", travelEntityIndexDescriptor);
indexManager.getCollectionIndexMapping().put("test", travelEntityIndexDescriptor.getName());
indexManager.onSchemaRegisteredEvent(new SchemaRegisteredEvent(new SchemaDescriptor("test", "test", indexes, new ProcessDescriptor("test", travelEntityIndexDescriptor.getName())), new SchemaType("test")));
MongoCollection<Document> testCollection = indexManager.getCollection("test");
collections.add(testCollection);
Set<String> testIndexes = StreamSupport.stream(testCollection.listIndexes().spliterator(), false).map(document -> document.getString(INDEX_NAME_FIELD)).filter(name -> !DEFAULT_INDEX.equals(name)).collect(toSet());
assertEquals(getTestIndexNames(), testIndexes);
mockProcessIndexEventListener.assertFire("test", travelEntityIndexDescriptor.getName());
}
Aggregations