-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#824 Add system property to configure default enableProtocol value
- Loading branch information
1 parent
80c4c2a
commit d613305
Showing
9 changed files
with
253 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...c/jdp/jdp-2024-07-add-system-property-to-configure-default-enable-protocol.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
= jdp-2024-07: Add System Property to Configure Default of `enableProtocol` | ||
|
||
== Status | ||
|
||
* Published: 2024-11-05 | ||
* Implemented in: Jaybird 6 | ||
* Updates: https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2023-04-disable-unsupported-protocols.md[jdp-2023-04] | ||
|
||
== Type | ||
|
||
* Feature-Specification | ||
|
||
== Context | ||
|
||
In https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2023-04-disable-unsupported-protocols.md[jdp-2023-04], we disabled unsupported protocols by default (that is, wire protocol versions 10 - 12 for pure Java connections), and added a connection property `enableProtocol` which can selectively enable unsupported protocols with a comma-separated list of versions, or all unsupported protocols with '```*```'. | ||
|
||
In some cases, it might be easier for users to configure a system property than update connection properties, so having a way to globally control this default will be handy to have as a fallback measure. | ||
|
||
== Decision | ||
|
||
Jaybird will add a connection property `org.firebirdsql.jdbc.defaultEnableProtocol` with the same syntax as the `enableProtocol` connection property. | ||
This system property will establish the default value for `enableProtocol`, and will be evaluated for each connection, so it can also be changed on the fly during run time. | ||
|
||
== Consequences | ||
|
||
A default value for `enableProtocol` can be established without having to specify the connection property explicitly, by setting a system property on startup, or during run time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.common; | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
/** | ||
* Helper methods for managing system properties during a test. | ||
* | ||
* @author Mark Rotteveel | ||
*/ | ||
@NullMarked | ||
public final class SystemPropertyHelper { | ||
|
||
private SystemPropertyHelper() { | ||
// no instances | ||
} | ||
|
||
/** | ||
* Temporarily sets the system property {@code name} to {@code value}, restoring the original value when | ||
* {@link AutoCloseable#close()} is called. | ||
* <p> | ||
* The recommended use for this method is in a try-with-resources statement. | ||
* </p> | ||
* | ||
* @param name | ||
* name of the system property | ||
* @param value | ||
* value of the system property ({@code null} will clear/remove the system property if it exists) | ||
* @return auto-closeable which will restore the original value of the system property | ||
*/ | ||
public static AutoCloseable withTemporarySystemProperty(String name, @Nullable String value) { | ||
record TemporarySystemProperty(String name, @Nullable String value, @Nullable String originalValue) | ||
implements AutoCloseable { | ||
|
||
TemporarySystemProperty { | ||
if (name == null) { | ||
throw new NullPointerException("name"); | ||
} | ||
setSystemProperty(name, value); | ||
} | ||
|
||
TemporarySystemProperty(String name, @Nullable String value) { | ||
this(name, value, System.getProperty(name)); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
setSystemProperty(name, originalValue); | ||
} | ||
} | ||
|
||
return new TemporarySystemProperty(name, value); | ||
} | ||
|
||
/** | ||
* Sets the system property {@code name} to {@code value}, or clears the property if {@code value} is {@code null}. | ||
* | ||
* @param name | ||
* system property name | ||
* @param value | ||
* new value | ||
*/ | ||
public static void setSystemProperty(String name, @Nullable String value) { | ||
if (value == null) { | ||
System.clearProperty(name); | ||
} else { | ||
System.setProperty(name, value); | ||
} | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/test/org/firebirdsql/common/SystemPropertyHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.common; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
/** | ||
* @author Mark Rotteveel | ||
*/ | ||
class SystemPropertyHelperTest { | ||
|
||
private static final String TEST_PROPERTY_NAME = "org.firebirdsql.common.SystemPropertyHelperTest"; | ||
private static final String INITIAL_VALUE = "Initial value"; | ||
|
||
@BeforeEach | ||
void removeTestProperty() { | ||
System.clearProperty(TEST_PROPERTY_NAME); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = { "Test value", INITIAL_VALUE }) | ||
void withTemporarySystemProperty_propertyDidNotExist(String testValue) throws Exception { | ||
try (var ignored = SystemPropertyHelper.withTemporarySystemProperty(TEST_PROPERTY_NAME, testValue)) { | ||
assertEquals(testValue, System.getProperty(TEST_PROPERTY_NAME), "Unexpected value in try"); | ||
} | ||
assertNull(System.getProperty(TEST_PROPERTY_NAME), "Unexpected value after try"); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = { "Test value", INITIAL_VALUE }) | ||
void withTemporarySystemProperty_propertyExisted(String testValue) throws Exception{ | ||
System.setProperty(TEST_PROPERTY_NAME, INITIAL_VALUE); | ||
try (var ignored = SystemPropertyHelper.withTemporarySystemProperty(TEST_PROPERTY_NAME, testValue)) { | ||
assertEquals(testValue, System.getProperty(TEST_PROPERTY_NAME), "Unexpected value in try"); | ||
} | ||
assertEquals(INITIAL_VALUE, System.getProperty(TEST_PROPERTY_NAME), "Unexpected value after try"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/org/firebirdsql/gds/ng/FbServicePropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Firebird Open Source JDBC Driver | ||
* | ||
* Distributable under LGPL license. | ||
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* LGPL License for more details. | ||
* | ||
* This file was created by members of the firebird development team. | ||
* All individual contributions remain the Copyright (C) of those | ||
* individuals. Contributors to this file are either listed here or | ||
* can be obtained from a source control history command. | ||
* | ||
* All rights reserved. | ||
*/ | ||
package org.firebirdsql.gds.ng; | ||
|
||
import org.firebirdsql.gds.JaybirdSystemProperties; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.firebirdsql.common.SystemPropertyHelper.withTemporarySystemProperty; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Tests for {@link FbServiceProperties}. | ||
*/ | ||
class FbServicePropertiesTest { | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = { "*", "11" }) | ||
void enableProtocolDefaultDerivedFromSystemProperty(String defaultValue) throws Exception { | ||
try (var ignored = withTemporarySystemProperty(JaybirdSystemProperties.DEFAULT_ENABLE_PROTOCOL, defaultValue)) { | ||
assertEquals(defaultValue, new FbServiceProperties().getEnableProtocol(), | ||
"Unexpected enableProtocol value"); | ||
} | ||
} | ||
|
||
} |