@@ -76,18 +76,6 @@ public void versionValidation_versionNumbersAllTheSameAllowed() {
7676 "dummy" );
7777 }
7878
79- @ Test
80- public void versionValidation_newerRuntimeVersionAllowed () {
81- int gencodeMinor = RuntimeVersion .MINOR - 1 ;
82- RuntimeVersion .validateProtobufGencodeVersion (
83- RuntimeVersion .DOMAIN ,
84- RuntimeVersion .MAJOR ,
85- gencodeMinor ,
86- RuntimeVersion .PATCH ,
87- RuntimeVersion .SUFFIX ,
88- "dummy" );
89- }
90-
9179 @ Test
9280 public void versionValidation_olderRuntimeVersionDisallowed () {
9381 int gencodeMinor = RuntimeVersion .MINOR + 1 ;
@@ -146,8 +134,107 @@ public void versionValidation_differentVersionSuffixDisallowed() {
146134 + " testing.Foo" );
147135 }
148136
137+ @ Test
138+ public void versionValidation_suffixedRuntime_logsWarning () {
139+ // We can only execute this test if the test runtime does have a suffix (which is nearly always
140+ // for our OSS continuous tests).
141+ if (RuntimeVersion .SUFFIX .isEmpty ()) {
142+ return ;
143+ }
144+
145+ // Suffixed runtimes only log the message once. To force the warning to be logged for
146+ // this test unrelated to test order, flip the bool back to false if it had been flipped by
147+ // another test to ensure the intended log can be observed.
148+ RuntimeVersion .preleaseRuntimeWarningLogged = false ;
149+
150+ TestUtil .TestLogHandler logHandler = new TestUtil .TestLogHandler ();
151+ Logger logger = Logger .getLogger (RuntimeVersion .class .getName ());
152+ logger .addHandler (logHandler );
153+ RuntimeVersion .validateProtobufGencodeVersion (
154+ RuntimeVersion .DOMAIN ,
155+ RuntimeVersion .MAJOR ,
156+ RuntimeVersion .MINOR ,
157+ RuntimeVersion .PATCH ,
158+ RuntimeVersion .SUFFIX ,
159+ "dummy" );
160+ assertThat (logHandler .getStoredLogRecords ()).hasSize (1 );
161+ assertThat (logHandler .getStoredLogRecords ().get (0 ).getMessage ())
162+ .contains ("You can ignore this message if you are deliberately testing a prerelease." );
163+ }
164+
165+ @ Test
166+ public void versionValidation_suffixedRuntime_sameSuffixLowerMinorDisallowed () {
167+ // We can only execute this test if the test runtime does have a suffix (which is nearly always
168+ // for our OSS continuous tests).
169+ if (RuntimeVersion .SUFFIX .isEmpty ()) {
170+ return ;
171+ }
172+ RuntimeVersion .ProtobufRuntimeVersionException thrown =
173+ assertThrows (
174+ RuntimeVersion .ProtobufRuntimeVersionException .class ,
175+ () ->
176+ RuntimeVersion .validateProtobufGencodeVersion (
177+ RuntimeVersion .DOMAIN ,
178+ RuntimeVersion .MAJOR ,
179+ RuntimeVersion .MINOR - 1 ,
180+ RuntimeVersion .PATCH ,
181+ RuntimeVersion .SUFFIX ,
182+ "testing.Foo" ));
183+ assertThat (thrown )
184+ .hasMessageThat ()
185+ .contains (
186+ "Detected mismatched Protobuf Gencode/Runtime version suffixes when loading"
187+ + " testing.Foo" );
188+ }
189+
190+ @ Test
191+ public void versionValidation_suffixedRuntime_sameNumbersNoSuffixDisallowed () {
192+ // We can only execute this test if the test runtime does have a suffix (which is nearly always
193+ // for our OSS continuous tests).
194+ if (RuntimeVersion .SUFFIX .isEmpty ()) {
195+ return ;
196+ }
197+ RuntimeVersion .ProtobufRuntimeVersionException thrown =
198+ assertThrows (
199+ RuntimeVersion .ProtobufRuntimeVersionException .class ,
200+ () ->
201+ RuntimeVersion .validateProtobufGencodeVersion (
202+ RuntimeVersion .DOMAIN ,
203+ RuntimeVersion .MAJOR ,
204+ RuntimeVersion .MINOR ,
205+ RuntimeVersion .PATCH ,
206+ "" ,
207+ "testing.Foo" ));
208+ assertThat (thrown )
209+ .hasMessageThat ()
210+ .contains (
211+ "Detected mismatched Protobuf Gencode/Runtime version suffixes when loading"
212+ + " testing.Foo" );
213+ }
214+
215+ @ Test
216+ public void versionValidation_suffixedRuntime_allowedLowerVersionWarns () {
217+ // We can only execute this test if the runtime does have a suffix (which is nearly always for
218+ // our OSS continuous tests).
219+ if (RuntimeVersion .SUFFIX .isEmpty ()) {
220+ return ;
221+ }
222+ RuntimeVersion .validateProtobufGencodeVersion (
223+ RuntimeVersion .DOMAIN ,
224+ RuntimeVersion .MAJOR ,
225+ RuntimeVersion .MINOR - 1 ,
226+ RuntimeVersion .PATCH ,
227+ "" ,
228+ "testing.Foo" );
229+ }
230+
149231 @ Test
150232 public void versionValidation_gencodeOneMajorVersionOlderWarning () {
233+ // Hack: if this is a suffixed runtime it may log the prerelease warning here if this
234+ // is the first test to run. Force the bool to true to avoid the warning happening during
235+ // this test only if it was the first one run.
236+ RuntimeVersion .preleaseRuntimeWarningLogged = true ;
237+
151238 TestUtil .TestLogHandler logHandler = new TestUtil .TestLogHandler ();
152239 Logger logger = Logger .getLogger (RuntimeVersion .class .getName ());
153240 logger .addHandler (logHandler );
@@ -156,7 +243,7 @@ public void versionValidation_gencodeOneMajorVersionOlderWarning() {
156243 RuntimeVersion .MAJOR - 1 ,
157244 RuntimeVersion .MINOR ,
158245 RuntimeVersion .PATCH ,
159- RuntimeVersion . SUFFIX ,
246+ "" ,
160247 "dummy" );
161248 assertThat (logHandler .getStoredLogRecords ()).hasSize (1 );
162249 assertThat (logHandler .getStoredLogRecords ().get (0 ).getMessage ())
0 commit comments