-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture Client Guest OS and architecture in JDBC #2561
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f979936
Capture Client Guest OS and architecture in JDBC
muskan124947 62455f4
Added app name with format Microsoft JDBC - {os}, {platform} - {arch}
muskan124947 57d8f2b
Adding log info and getAppNameWithProperties()
muskan124947 03486dc
Updated the application name to be set dynamically
muskan124947 8bbbbcf
Added log level as FINE
muskan124947 e9cb5b1
Added test case to verify application name
muskan124947 08e7dba
Updated the SQLServerDriverPropertyInfo with default name
muskan124947 1cdcac4
Added static block for initialization
muskan124947 51be560
Added test case for code coverage
muskan124947 9a7b948
Updated app Name
muskan124947 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import static org.junit.Assert.fail; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.sql.Connection; | ||
|
@@ -190,4 +192,40 @@ public void testConnectionDriver() throws SQLException { | |
} | ||
} | ||
} | ||
|
||
/** | ||
* test application name | ||
* | ||
* @throws SQLException | ||
*/ | ||
@Test | ||
public void testApplicationName() throws SQLException { | ||
try (Connection conn = DriverManager.getConnection(connectionString); | ||
Statement stmt = conn.createStatement(); | ||
ResultSet rs = stmt.executeQuery("SELECT program_name FROM sys.dm_exec_sessions WHERE session_id = @@SPID")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to have this test which is actually querying the program name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
if (rs.next()) { | ||
assertEquals(SQLServerDriver.constructedAppName, rs.getString("program_name")); | ||
} | ||
} catch (SQLException e) { | ||
fail(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* test application name when system properties are empty | ||
* | ||
*/ | ||
@Test | ||
public void testGetAppName() { | ||
String appName = SQLServerDriver.getAppName(); | ||
assertNotNull(appName, "Application name should not be null"); | ||
assertFalse(appName.isEmpty(), "Application name should not be empty"); | ||
|
||
System.setProperty("os.name", ""); | ||
System.setProperty("os.arch", ""); | ||
System.setProperty("java.vm.name", ""); | ||
System.setProperty("java.vm.version", ""); | ||
String defaultAppName = SQLServerDriver.getAppName(); | ||
assertEquals(SQLServerDriver.DEFAULT_APP_NAME, defaultAppName, "Application name should be the default one"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If osName, platform and osArch are empty, then we can avoid String formatting:
if (!osName.isEmpty() && !platform.isEmpty() && !osArch.isEmpty()) {
return String.format(APP_NAME_TEMPLATE, osName, platform, osArch);
}
return DEFAULT_APP_NAME;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a static and only done once