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()));
}
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()));
}
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()));
}
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"))));
}
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);
}
}
Aggregations