Search in sources :

Example 31 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class ServiceNamingRuleTest method testDisallowedName_existing.

@Parameters(method = "disallowedNames")
@Test
public void testDisallowedName_existing(final String name) throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + String.format("service %s {\n", name) + "}");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(candidate, candidate);
    assertThat(violations, is(empty()));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 32 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class ServiceNamingRuleTest method testAllowedName_new.

@Parameters(method = "allowedNames")
@Test
public void testAllowedName_new(final String name) throws Exception {
    final DescriptorSet current = DescriptorSet.empty();
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + String.format("service %s {\n", name) + "}");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, is(empty()));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 33 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class ServiceNamingRuleTest method testAllowedName_existing.

@Parameters(method = "allowedNames")
@Test
public void testAllowedName_existing(final String name) throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + String.format("service %s {\n", name) + "}");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(candidate, candidate);
    assertThat(violations, is(empty()));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 34 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class ServiceRemovalRuleTest method testMethodRemoved.

@Test
public void testMethodRemoved() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "}");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.WIRE_INCOMPATIBILITY_VIOLATION)).description(equalTo("service removed"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 35 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class SchemaRegistry method publishSchemata.

@Override
public PublishResult publishSchemata(final ImmutableList<SchemaFile> schemaFiles) {
    try (final SchemaStorage.Transaction tx = schemaStorage.open()) {
        final BuildDescriptorsResult buildDescriptorsResult = buildDescriptorSets(tx, schemaFiles);
        if (buildDescriptorsResult.currentCompilationError() != null) {
            // Compilation of what's currently in the registry failed. This should not happen!
            throw new RuntimeException("Failed to build descriptor for current schemata");
        }
        if (buildDescriptorsResult.candidateCompilationError() != null) {
            return PublishResult.error(buildDescriptorsResult.candidateCompilationError());
        }
        final DescriptorSet currentDs = buildDescriptorsResult.current();
        final DescriptorSet candidateDs = buildDescriptorsResult.candidate();
        // Validate changes
        final ImmutableList<ValidationViolation> violations = schemaValidator.validate(currentDs, candidateDs);
        // TODO(staffan): Don't treat all violations as fatal
        if (!violations.isEmpty()) {
            return PublishResult.error("Validation failed", violations);
        }
        // Store files, but only for protos that changed
        updatedFiles(schemaFiles.stream(), currentDs, candidateDs).forEach(file -> {
            final ImmutableSet<Path> dependencies = candidateDs.findFileByPath(file.path()).get().dependencies().stream().map(FileDescriptor::filePath).collect(toImmutableSet());
            logger.debug("proto: {}, deps: {}", file.path(), dependencies);
            tx.storeFile(file);
            tx.storeProtoDependencies(file.path(), dependencies);
        });
        // Update package versions (only for packages that have changed)
        final ImmutableMap<String, SchemaVersionPair> publishedPackages = updatePackageVersions(tx, currentDs, candidateDs);
        tx.commit();
        return PublishResult.create(violations, publishedPackages);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) DescriptorBuilderException(com.spotify.protoman.descriptor.DescriptorBuilderException) SchemaStorage(com.spotify.protoman.registry.storage.SchemaStorage) ValidationViolation(com.spotify.protoman.validation.ValidationViolation)

Aggregations

DescriptorSet (com.spotify.protoman.descriptor.DescriptorSet)79 ValidationViolation (com.spotify.protoman.validation.ValidationViolation)76 Test (org.junit.Test)74 Parameters (junitparams.Parameters)43 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 DescriptorProtos (com.google.protobuf.DescriptorProtos)3 FileDescriptor (com.spotify.protoman.descriptor.FileDescriptor)3 Objects (java.util.Objects)3 Function (java.util.function.Function)3 Nullable (javax.annotation.Nullable)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 DescriptorBuilderException (com.spotify.protoman.descriptor.DescriptorBuilderException)2 SchemaStorage (com.spotify.protoman.registry.storage.SchemaStorage)2 Path (java.nio.file.Path)2 Predicate (java.util.function.Predicate)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AutoValue (com.google.auto.value.AutoValue)1