Search in sources :

Example 21 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project kogito-apps by kiegroup.

the class ProtoDomainModelProducerTest method onFileDescriptorRegistered.

@Test
void onFileDescriptorRegistered() {
    FileDescriptor fileDescriptor = getTestFileDescriptor();
    FileDescriptorRegisteredEvent event = new FileDescriptorRegisteredEvent(fileDescriptor);
    protoDomainModelProducer.onFileDescriptorRegistered(event);
    verify(domainEvent).fire(eq(new DomainModelRegisteredEvent(TestUtils.PROCESS_ID, TestUtils.DOMAIN_DESCRIPTOR, TestUtils.ADDITIONAL_DESCRIPTORS)));
}
Also used : DomainModelRegisteredEvent(org.kie.kogito.persistence.api.proto.DomainModelRegisteredEvent) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.jupiter.api.Test)

Example 22 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project kogito-apps by kiegroup.

the class ProtoIndexParserTest method testCreateEntityIndexeDescriptors.

@Test
void testCreateEntityIndexeDescriptors() {
    FileDescriptor fileDescriptor = createFileDescriptor();
    Map<String, EntityIndexDescriptor> entityIndexes = createFileDescriptor().getMessageTypes().stream().map(t -> t.<EntityIndexDescriptor>getProcessedAnnotation(INDEXED_ANNOTATION)).filter(Objects::nonNull).collect(toMap(EntityIndexDescriptor::getName, Function.identity()));
    Map<String, EntityIndexDescriptor> indexDescriptor = createEntityIndexDescriptors(fileDescriptor, entityIndexes);
    assertEquals(getValidEntityIndexDescriptors(true), indexDescriptor);
}
Also used : EntityIndexDescriptor(org.kie.kogito.persistence.api.schema.EntityIndexDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.jupiter.api.Test)

Example 23 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class SerializationContextImpl method unregisterFileDescriptorTypes.

@GuardedBy("descriptorLock")
private void unregisterFileDescriptorTypes(FileDescriptor fileDescriptor) {
    if (fileDescriptor.isResolved()) {
        for (GenericDescriptor d : fileDescriptor.getTypes().values()) {
            Integer typeId = d.getTypeId();
            if (typeId != null) {
                typeIds.remove(typeId);
            }
            if (d instanceof EnumDescriptor) {
                for (EnumValueDescriptor ev : ((EnumDescriptor) d).getValues()) {
                    enumValueDescriptors.remove(ev.getScopedName());
                }
            }
        }
        genericDescriptors.keySet().removeAll(fileDescriptor.getTypes().keySet());
        fileDescriptor.markUnresolved();
    }
    for (FileDescriptor fd : fileDescriptor.getDependants().values()) {
        unregisterFileDescriptorTypes(fd);
    }
}
Also used : GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) EnumValueDescriptor(org.infinispan.protostream.descriptors.EnumValueDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) GuardedBy(net.jcip.annotations.GuardedBy)

Example 24 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class SerializationContextImpl method unregisterProtoFiles.

@Override
public void unregisterProtoFiles(Set<String> fileNames) {
    log.debugf("Unregistering proto files : %s", fileNames);
    long stamp = descriptorLock.writeLock();
    try {
        for (String fileName : fileNames) {
            FileDescriptor fileDescriptor = fileDescriptors.remove(fileName);
            if (fileDescriptor != null) {
                unregisterFileDescriptorTypes(fileDescriptor);
            } else {
                throw new IllegalArgumentException("File " + fileName + " does not exist");
            }
        }
    } finally {
        descriptorLock.unlockWrite(stamp);
    }
}
Also used : FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor)

Example 25 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class SquareProtoParser method reportParsingError.

/**
 * Report the error to the callback if any, or just throw it otherwise.
 */
private void reportParsingError(FileDescriptorSource fileDescriptorSource, Map<String, FileDescriptor> fileDescriptorMap, String fileName, DescriptorParserException dpe) {
    if (fileDescriptorSource.getProgressCallback() == null) {
        // fail fast
        throw dpe;
    }
    // create an empty FileDescriptor that has just a name and a parsing error status
    FileDescriptor stub = new FileDescriptor.Builder().withName(fileName).withParsingException(dpe).build();
    stub.setConfiguration(configuration);
    fileDescriptorMap.put(fileName, stub);
    fileDescriptorSource.getProgressCallback().handleError(fileName, dpe);
}
Also used : FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor)

Aggregations

FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)43 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)24 Test (org.junit.Test)23 Descriptor (org.infinispan.protostream.descriptors.Descriptor)12 Configuration (org.infinispan.protostream.config.Configuration)11 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)11 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)11 List (java.util.List)8 SerializationContext (org.infinispan.protostream.SerializationContext)8 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)8 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DescriptorParserException (org.infinispan.protostream.DescriptorParserException)5 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)5 EntityIndexDescriptor (org.kie.kogito.persistence.api.schema.EntityIndexDescriptor)4 HashMap (java.util.HashMap)3 ResolutionContext (org.infinispan.protostream.descriptors.ResolutionContext)3 Ignore (org.junit.Ignore)3 Test (org.junit.jupiter.api.Test)3