Skip to content

Commit

Permalink
Remove unused checkProto2Syntax from ProtobufUtil.java and test. (#25885
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zhangskz authored Mar 30, 2023
1 parent be725c8 commit 57ac318
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
*/
package org.apache.beam.sdk.extensions.protobuf;

import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;

import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Descriptors.FileDescriptor.Syntax;
import com.google.protobuf.Descriptors.GenericDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.ExtensionRegistry.ExtensionInfo;
import com.google.protobuf.Message;
Expand Down Expand Up @@ -67,22 +63,6 @@ static Set<Descriptor> getRecursiveDescriptorsForClass(
return descriptors;
}

/**
* Recursively walks the given {@link Message} class and verifies that every field or message
* linked in uses the Protocol Buffers proto2 syntax.
*/
static void checkProto2Syntax(Class<? extends Message> clazz, ExtensionRegistry registry) {
for (GenericDescriptor d : getRecursiveDescriptorsForClass(clazz, registry)) {
Syntax s = d.getFile().getSyntax();
checkArgument(
s == Syntax.PROTO2,
"Message %s or one of its dependencies does not use proto2 syntax: %s in file %s",
clazz.getName(),
d.getFullName(),
d.getFile().getName());
}
}

/**
* Recursively checks whether the specified class uses any Protocol Buffers fields that cannot be
* deterministically encoded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
*/
package org.apache.beam.sdk.extensions.protobuf;

import static org.apache.beam.sdk.extensions.protobuf.ProtobufUtil.checkProto2Syntax;
import static org.apache.beam.sdk.extensions.protobuf.ProtobufUtil.getRecursiveDescriptorsForClass;
import static org.apache.beam.sdk.extensions.protobuf.ProtobufUtil.verifyDeterministic;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import com.google.protobuf.Any;
import com.google.protobuf.Descriptors.GenericDescriptor;
import com.google.protobuf.Duration;
import com.google.protobuf.ExtensionRegistry;
Expand Down Expand Up @@ -113,35 +111,6 @@ public void testRecursiveDescriptorsReferencesMessageWithMap() {
getRecursiveDescriptorFullNames(ReferencesMessageWithMap.class), equalTo(REFERS_MAP_ALL));
}

@Test
public void testVerifyProto2() {
checkProto2Syntax(MessageA.class, ExtensionRegistry.getEmptyRegistry());
checkProto2Syntax(MessageB.class, ExtensionRegistry.getEmptyRegistry());
checkProto2Syntax(MessageC.class, ExtensionRegistry.getEmptyRegistry());
checkProto2Syntax(MessageWithMap.class, ExtensionRegistry.getEmptyRegistry());
checkProto2Syntax(ReferencesMessageWithMap.class, ExtensionRegistry.getEmptyRegistry());
}

@Test
public void testAnyIsNotProto2() {
// Any is a core Protocol Buffers type that uses proto3 syntax.
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(Any.class.getCanonicalName());
thrown.expectMessage("in file " + Any.getDescriptor().getFile().getName());

checkProto2Syntax(Any.class, ExtensionRegistry.getEmptyRegistry());
}

@Test
public void testDurationIsNotProto2() {
// Duration is a core Protocol Buffers type that uses proto3 syntax.
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(Duration.class.getCanonicalName());
thrown.expectMessage("in file " + Duration.getDescriptor().getFile().getName());

checkProto2Syntax(Duration.class, ExtensionRegistry.getEmptyRegistry());
}

@Test
public void testDurationIsDeterministic() throws NonDeterministicException {
// Duration can be encoded deterministically.
Expand Down

0 comments on commit 57ac318

Please sign in to comment.