-
Notifications
You must be signed in to change notification settings - Fork 9
feat: support TDengine version check #111
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
| namespace TDengine.Driver.Impl.WebSocketMethods.Protocol | ||
| { | ||
| public class WSVersionReq | ||
| { | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/Driver/Impl/WebSocketMethods/Protocol/WSVersionResp.cs
This file contains hidden or 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,19 @@ | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace TDengine.Driver.Impl.WebSocketMethods.Protocol | ||
| { | ||
| public class WSVersionResp : IWSBaseResp | ||
| { | ||
| [JsonProperty("code")] public int Code { get; set; } | ||
|
|
||
| [JsonProperty("message")] public string Message { get; set; } | ||
|
|
||
| [JsonProperty("action")] public string Action { get; set; } | ||
|
|
||
| [JsonProperty("req_id")] public ulong ReqId { get; set; } | ||
|
|
||
| [JsonProperty("timing")] public long Timing { get; set; } | ||
|
|
||
| [JsonProperty("version")] public string Version { get; set; } | ||
| } | ||
| } |
This file contains hidden or 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,66 @@ | ||
| using System; | ||
|
|
||
| namespace TDengine.Driver | ||
| { | ||
| public class TDengineVersion | ||
| { | ||
| private static Version MinimumVersion { get; set; } = new Version(3, 3, 2, 0); | ||
|
|
||
| public static Version ParseVersion(string version) | ||
| { | ||
| if (string.IsNullOrEmpty(version)) | ||
| { | ||
| throw new UnknownVersionException(version); | ||
| } | ||
|
|
||
| var parts = version.Split('.'); | ||
| if (parts.Length < 4) | ||
| { | ||
| throw new UnknownVersionException(version); | ||
| } | ||
|
|
||
| version = string.Join(".", parts[0], parts[1], parts[2], parts[3]); | ||
| if (!Version.TryParse(version, out var parsedVersion)) | ||
| { | ||
| throw new UnknownVersionException(version); | ||
| } | ||
|
|
||
| return parsedVersion; | ||
| } | ||
|
|
||
| public static void CheckVersionCompatibility(string ver) | ||
| { | ||
| var currentVersion = ParseVersion(ver); | ||
| if (currentVersion < MinimumVersion) | ||
| { | ||
| throw new VersionMismatchException( | ||
| currentVersion.ToString(), | ||
| MinimumVersion.ToString()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class UnknownVersionException : Exception | ||
| { | ||
| public string Version { get; } | ||
|
|
||
| public UnknownVersionException(string version) | ||
| : base($"Unknown TDengine version: {version}") | ||
| { | ||
| Version = version; | ||
| } | ||
| } | ||
|
|
||
| public class VersionMismatchException : Exception | ||
| { | ||
| public string CurrentVersion { get; } | ||
| public string MinimumVersion { get; } | ||
|
|
||
| public VersionMismatchException(string currentVersion, string minimumVersion) | ||
| : base($"Version mismatch. The minimum required TDengine version is {minimumVersion}.") | ||
| { | ||
| CurrentVersion = currentVersion; | ||
| MinimumVersion = minimumVersion; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| using TDengine.Driver; | ||
| using Xunit; | ||
|
|
||
| namespace Driver.Test.Client.Version | ||
| { | ||
| public class TDengineVersionTests | ||
| { | ||
| [Theory] | ||
| [InlineData("3.3.6.3", 3, 3, 6, 3)] | ||
| [InlineData("3.3.2.0", 3, 3, 2, 0)] | ||
| [InlineData("3.3.6.3.alpha", 3, 3, 6, 3)] | ||
| public void ParseVersion_ValidVersion_ReturnsVersion(string input, int major, int minor, int build, | ||
| int revision) | ||
| { | ||
| var version = TDengineVersion.ParseVersion(input); | ||
| Assert.Equal(new System.Version(major, minor, build, revision), version); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("")] | ||
| [InlineData(null)] | ||
| [InlineData("3.3")] | ||
| [InlineData("3.3.6")] | ||
| [InlineData("abc.def.ghi.jkl")] | ||
| public void ParseVersion_InvalidVersion_ThrowsUnknownVersionException(string input) | ||
| { | ||
| Assert.Throws<UnknownVersionException>(() => TDengineVersion.ParseVersion(input)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CheckVersionCompatibility_VersionTooLow_ThrowsVersionMismatchException() | ||
| { | ||
| Assert.Throws<VersionMismatchException>(() => TDengineVersion.CheckVersionCompatibility("3.3.1.0")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CheckVersionCompatibility_VersionEqualOrHigher_NoException() | ||
| { | ||
| TDengineVersion.CheckVersionCompatibility("3.3.2.0"); | ||
| TDengineVersion.CheckVersionCompatibility("3.3.6.3"); | ||
| TDengineVersion.CheckVersionCompatibility("3.3.10.0"); | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.