Skip to content

Commit

Permalink
BE: Chore: drop deprecated protobuf single file property (provectus#3825
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AndreyNenashev authored Jun 21, 2023
1 parent 328d91d commit 742e6ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ build/
.vscode/
/kafka-ui-api/app/node

### SDKMAN ###
.sdkmanrc

.DS_Store
*.code-workspace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.io.ByteArrayInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -204,17 +203,13 @@ record Configuration(@Nullable Descriptor defaultMessageDescriptor,
Map<String, Descriptor> keyMessageDescriptorMap) {

static boolean canBeAutoConfigured(PropertyResolver kafkaClusterProperties) {
Optional<String> protobufFile = kafkaClusterProperties.getProperty("protobufFile", String.class);
Optional<List<String>> protobufFiles = kafkaClusterProperties.getListProperty("protobufFiles", String.class);
Optional<String> protobufFilesDir = kafkaClusterProperties.getProperty("protobufFilesDir", String.class);
return protobufFilesDir.isPresent()
|| protobufFile.isPresent()
|| protobufFiles.filter(files -> !files.isEmpty()).isPresent();
return protobufFilesDir.isPresent() || protobufFiles.filter(files -> !files.isEmpty()).isPresent();
}

static Configuration create(PropertyResolver properties) {
var protobufSchemas = loadSchemas(
properties.getProperty("protobufFile", String.class),
properties.getListProperty("protobufFiles", String.class),
properties.getProperty("protobufFilesDir", String.class)
);
Expand Down Expand Up @@ -272,12 +267,11 @@ private static Map<String, Descriptor> populateDescriptors(Map<String, Descripto
}

@VisibleForTesting
static Map<Path, ProtobufSchema> loadSchemas(Optional<String> protobufFile,
Optional<List<String>> protobufFiles,
static Map<Path, ProtobufSchema> loadSchemas(Optional<List<String>> protobufFiles,
Optional<String> protobufFilesDir) {
if (protobufFilesDir.isPresent()) {
if (protobufFile.isPresent() || protobufFiles.isPresent()) {
log.warn("protobufFile and protobufFiles properties will be ignored, since protobufFilesDir provided");
if (protobufFiles.isPresent()) {
log.warn("protobufFiles properties will be ignored, since protobufFilesDir provided");
}
List<ProtoFile> loadedFiles = new ProtoSchemaLoader(protobufFilesDir.get()).load();
Map<String, ProtoFileElement> allPaths = loadedFiles.stream()
Expand All @@ -288,10 +282,8 @@ static Map<Path, ProtobufSchema> loadSchemas(Optional<String> protobufFile,
f -> new ProtobufSchema(f.toElement(), List.of(), allPaths)));
}
//Supporting for backward-compatibility. Normally, protobufFilesDir setting should be used
return Stream.concat(
protobufFile.stream(),
protobufFiles.stream().flatMap(Collection::stream)
)
return protobufFiles.stream()
.flatMap(Collection::stream)
.distinct()
.map(Path::of)
.collect(Collectors.toMap(path -> path, path -> new ProtobufSchema(readFileAsString(path))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class ProtobufFileSerdeTest {
@BeforeEach
void setUp() throws Exception {
Map<Path, ProtobufSchema> files = ProtobufFileSerde.Configuration.loadSchemas(
Optional.empty(),
Optional.empty(),
Optional.of(protoFilesDir())
);
Expand Down Expand Up @@ -107,15 +106,6 @@ void canBeAutoConfiguredReturnsNoProtoPropertiesProvided() {
.isFalse();
}

@Test
void canBeAutoConfiguredReturnsTrueIfNoProtoFileHasBeenProvided() {
PropertyResolver resolver = mock(PropertyResolver.class);
when(resolver.getProperty("protobufFile", String.class))
.thenReturn(Optional.of("file.proto"));
assertThat(Configuration.canBeAutoConfigured(resolver))
.isTrue();
}

@Test
void canBeAutoConfiguredReturnsTrueIfProtoFilesHasBeenProvided() {
PropertyResolver resolver = mock(PropertyResolver.class);
Expand Down Expand Up @@ -193,13 +183,10 @@ void unknownSchemaAsTopicSchemaForKeyThrowsException() {
@Test
void createConfigureFillsDescriptorMappingsWhenProtoFilesListProvided() throws Exception {
PropertyResolver resolver = mock(PropertyResolver.class);
when(resolver.getProperty("protobufFile", String.class))
.thenReturn(Optional.of(
ResourceUtils.getFile("classpath:protobuf-serde/sensor.proto").getPath()));

when(resolver.getListProperty("protobufFiles", String.class))
.thenReturn(Optional.of(
List.of(
ResourceUtils.getFile("classpath:protobuf-serde/sensor.proto").getPath(),
ResourceUtils.getFile("classpath:protobuf-serde/address-book.proto").getPath())));

when(resolver.getProperty("protobufMessageName", String.class))
Expand Down

0 comments on commit 742e6ee

Please sign in to comment.