Search in sources :

Example 6 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class PerformanceBenchmarks method testGetPrimitiveFieldsWithDescriptors.

private static void testGetPrimitiveFieldsWithDescriptors() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllPrimitiveFields(builder);
    TypicalData data = builder.build();
    List<FieldDescriptor> fields = getPrimitiveFieldDescriptors();
    for (int i = 0; i < 10000; i++) {
        for (FieldDescriptor field : fields) {
            data.getField(field);
        }
    }
}
Also used : TypicalData(protos.TypicalData) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 7 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class PerformanceBenchmarks method getRepeatedFieldDescriptors.

private static List<FieldDescriptor> getRepeatedFieldDescriptors() {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
    fields.add(descriptor.findFieldByNumber(4));
    fields.add(descriptor.findFieldByNumber(19));
    fields.add(descriptor.findFieldByNumber(20));
    fields.add(descriptor.findFieldByNumber(21));
    fields.add(descriptor.findFieldByNumber(5));
    fields.add(descriptor.findFieldByNumber(6));
    fields.add(descriptor.findFieldByNumber(7));
    fields.add(descriptor.findFieldByNumber(8));
    fields.add(descriptor.findFieldByNumber(9));
    fields.add(descriptor.findFieldByNumber(10));
    return fields;
}
Also used : ArrayList(java.util.ArrayList) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 8 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class PerformanceBenchmarks method getPrimitiveFieldDescriptors.

private static List<FieldDescriptor> getPrimitiveFieldDescriptors() {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
    fields.add(descriptor.findFieldByNumber(1));
    fields.add(descriptor.findFieldByNumber(12));
    fields.add(descriptor.findFieldByNumber(13));
    fields.add(descriptor.findFieldByNumber(14));
    fields.add(descriptor.findFieldByNumber(16));
    fields.add(descriptor.findFieldByNumber(17));
    fields.add(descriptor.findFieldByNumber(18));
    return fields;
}
Also used : ArrayList(java.util.ArrayList) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 9 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project core-java by SpineEventEngine.

the class ReferenceValidatorShould method store_valid_map_of_enrichment_fields_after_validation.

@Test
public void store_valid_map_of_enrichment_fields_after_validation() {
    final ReferenceValidator validator = new ReferenceValidator(eventEnricher, UserDeletedEvent.class, EnrichmentBoundWithMultipleFieldsWithDifferentNames.class);
    final ValidationResult result = validator.validate();
    final Multimap<FieldDescriptor, FieldDescriptor> fieldMap = result.getFieldMap();
    assertNotNull(fieldMap);
    assertFalse(fieldMap.isEmpty());
    assertSize(1, fieldMap);
    final Iterator<? extends Map.Entry<?, ? extends Collection<?>>> fieldsIterator = fieldMap.asMap().entrySet().iterator();
    assertTrue(fieldsIterator.hasNext());
    final Map.Entry<?, ? extends Collection<?>> entry = fieldsIterator.next();
    @SuppressWarnings("unchecked") final Map.Entry<FieldDescriptor, Collection<FieldDescriptor>> fieldEntry = (Map.Entry<FieldDescriptor, Collection<FieldDescriptor>>) entry;
    final FieldDescriptor eventField = fieldEntry.getKey();
    final String eventFieldName = eventField.getName();
    assertEquals("deleted_uid", eventFieldName);
    final Collection<FieldDescriptor> enrichmentFields = fieldEntry.getValue();
    assertFalse(enrichmentFields.isEmpty());
    assertSize(1, enrichmentFields);
    final Iterator<FieldDescriptor> enrichmentFieldIterator = enrichmentFields.iterator();
    assertTrue(enrichmentFieldIterator.hasNext());
    final FieldDescriptor enrichmentField = enrichmentFieldIterator.next();
    final String enrichmentFieldName = enrichmentField.getName();
    assertEquals(USER_GOOGLE_UID_FIELD, enrichmentFieldName);
}
Also used : ValidationResult(io.spine.server.event.enrich.ReferenceValidator.ValidationResult) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Collection(java.util.Collection) Map(java.util.Map) Test(org.junit.Test)

Example 10 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project core-java by SpineEventEngine.

the class ReferenceValidatorShould method handle_separator_spaces_in_by_argument.

@Test
public void handle_separator_spaces_in_by_argument() {
    final ReferenceValidator validator = new ReferenceValidator(eventEnricher, TaskAdded.class, EnrichmentBoundWithFieldsSeparatedWithSpaces.class);
    final ValidationResult result = validator.validate();
    final Multimap<FieldDescriptor, FieldDescriptor> fieldMap = result.getFieldMap();
    assertFalse(fieldMap.isEmpty());
    assertSize(1, fieldMap);
    final Iterator<Map.Entry<FieldDescriptor, Collection<FieldDescriptor>>> mapIterator = fieldMap.asMap().entrySet().iterator();
    assertTrue(mapIterator.hasNext());
    final Map.Entry<FieldDescriptor, Collection<FieldDescriptor>> singleEntry = mapIterator.next();
    final FieldDescriptor boundField = singleEntry.getKey();
    final String boundFieldName = boundField.getName();
    assertEquals("project_id", boundFieldName);
    final Collection<FieldDescriptor> targets = singleEntry.getValue();
    assertSize(1, targets);
    final FieldDescriptor targetField = targets.iterator().next();
    final String targetFieldName = targetField.getName();
    assertEquals(USER_GOOGLE_UID_FIELD, targetFieldName);
}
Also used : Collection(java.util.Collection) ValidationResult(io.spine.server.event.enrich.ReferenceValidator.ValidationResult) Map(java.util.Map) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Aggregations

FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)45 Descriptor (com.google.protobuf.Descriptors.Descriptor)18 Test (org.junit.Test)14 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)11 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)11 BooleanFieldValidator (io.spine.validate.BooleanFieldValidator)9 ByteStringFieldValidator (io.spine.validate.ByteStringFieldValidator)9 FloatFieldValidator (io.spine.validate.FloatFieldValidator)9 LongFieldValidator (io.spine.validate.LongFieldValidator)9 StringFieldValidator (io.spine.validate.StringFieldValidator)9 TypicalData (protos.TypicalData)5 ArrayList (java.util.ArrayList)4 ByteString (com.google.protobuf.ByteString)3 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)3 ValidationResult (io.spine.server.event.enrich.ReferenceValidator.ValidationResult)3 Map (java.util.Map)3 GeneratedMessage (com.google.protobuf.GeneratedMessage)2 Collection (java.util.Collection)2 TypicalDataMessage (protos.TypicalDataMessage)2 ImageAnnotatorClient (com.google.cloud.vision.spi.v1.ImageAnnotatorClient)1