public void Parse_InvalidVersions(string version) { Assert.Throws <VersionParsingException>(() => { var parsedVersion = DependencyVersionParser.Parse(version, true); }); }
/// <summary> /// Gets the versions. /// </summary> /// <returns> /// Returns an enumerable with the MongoDb versions. /// </returns> /// <exception cref="NAMEException">Thrown when an unexpected exception happens.</exception> public override async Task <IEnumerable <DependencyVersion> > GetVersions() { var versions = new List <DependencyVersion>(); if (!this.connectionStringProvider.TryGetConnectionString(out string connectionString)) { throw new ConnectionStringNotFoundException(this.connectionStringProvider.ToString()); } var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString); byte[] message = this.CreateServerStatusMessagePayload(connectionStringBuilder); foreach (var mongoEndpoint in connectionStringBuilder.Servers) { using (var client = await this.OpenTcpClient(mongoEndpoint.Host, mongoEndpoint.Port, SupportedDependencies.MongoDb.ToString())) { await client.GetStream().WriteAsync(message, 0, message.Length, default(CancellationToken)).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); BSONObject obj = ExtractServerStatusFromResponse(client); versions.Add(DependencyVersionParser.Parse(obj["version"].stringValue, false)); } } return(versions); }
public void Translate_Versions(SqlServerVersions exptectedVersion, string versionStr) { IVersionTranslator translator = new SqlServerVersionTranslator(); string v = translator.Translate(DependencyVersionParser.Parse(versionStr, false)); Assert.True(v == exptectedVersion.ToString()); }
public void Translate_WindowsVersions(WindowsVersions version, string expectedVersion) { IVersionTranslator translator = new WindowsVersionTranslator(); DependencyVersion v = translator.Translate(version.ToString()); Assert.True(v >= DependencyVersionParser.Parse(expectedVersion, false)); }
public async Task GetVersions_SpecificVersion_UriWithQueryString() { MongoDbVersionResolver resolver = new MongoDbVersionResolver(new StaticConnectionStringProvider($"mongodb://{ Constants.SpecificMongoHostname }:27017/?w=1"), 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); Assert.Equal(versions.First(), DependencyVersionParser.Parse(Constants.SpecificMongoVersion, false)); }
public async Task GetVersions_LatestVersion() { MongoDbVersionResolver resolver = new MongoDbVersionResolver(new StaticConnectionStringProvider($"mongodb://{ Constants.LatestMongoHostname }:27017"), 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); Assert.True(versions.First() >= DependencyVersionParser.Parse("3.0.0", false)); }
public async Task GetVersions_SpecificVersion() { ElasticsearchVersionResolver resolver = new ElasticsearchVersionResolver(new StaticConnectionStringProvider($"http://{ Constants.SpecificElasticsearchHostname }:9200"), 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); Assert.Equal(versions.First(), DependencyVersionParser.Parse(Constants.SpecificElasticsearchVersion, false)); }
public async Task GetVersions_SpecificPort() { string connectionString = $"Data Source={ Constants.LatestSqlServerHostname },1433;Initial Catalog=DBTests;Integrated Security=True;"; IVersionResolver resolver = new SqlServerVersionResolver(new StaticConnectionStringProvider(connectionString), 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); Assert.True(versions.First() >= DependencyVersionParser.Parse("12.0.0", false), "The version should be greater than 12.0.0"); }
public async Task GetVersions_LatestVersion() { ElasticsearchVersionResolver resolver = new ElasticsearchVersionResolver(new StaticConnectionStringProvider($"http://{ Constants.LatestElasticsearchHostname }:9200"), 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); // Latest GA RELEASE: https://www.elastic.co/downloads/elasticsearch#ga-release Assert.Equal(versions.First(), DependencyVersionParser.Parse("5.6.3", false)); }
public void Parse_ValidVersion_MissingValues() { string version = "3"; var parsedVersion = DependencyVersionParser.Parse(version, true); Assert.Equal(3, (int)parsedVersion.Major); Assert.Equal(0, (int)parsedVersion.Minor); Assert.Equal(0, (int)parsedVersion.Patch); }
public void Parse_ValidVersion() { string version = "3.1.1"; var parsedVersion = DependencyVersionParser.Parse(version, true); Assert.Equal(3, (int)parsedVersion.Major); Assert.Equal(1, (int)parsedVersion.Minor); Assert.Equal(1, (int)parsedVersion.Patch); }
public async Task GetVersions() { string connectionString = $"http://{ Constants.SpecificKestrelSelfHostHostname }:40500"; IVersionResolver resolver = new ServiceVersionResolver(new StaticConnectionStringProvider(connectionString), 0, 5, 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); Assert.Equal(versions.First(), DependencyVersionParser.Parse(Constants.SpecificKestrelSelfHostVersion, false)); }
public async Task GetVersions_WrongEndpoint_ReturnedOk() { string connectionString = $"http://{ Constants.SpecificServiceHostname }:5000/not/the/real"; IVersionResolver resolver = new ServiceVersionResolver(new StaticConnectionStringProvider(connectionString), 0, 5, 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(1, versions.Count()); Assert.Equal(versions.First(), DependencyVersionParser.Parse(Constants.SpecificServiceVersion, false)); }
public async Task GetVersions_MultipleConnectionStrings() { string connectionString = $"amqp://*****:*****@{ Constants.SpecificRabbitHostname }:5672/, amqp://gibberish:notneeded@{ Constants.LatestRabbitHostname }:5672/"; IVersionResolver resolver = new RabbitMqVersionResolver(new StaticConnectionStringProvider(connectionString), 10000, 10000); var versions = await resolver.GetVersions().ConfigureAwait(false); Assert.Equal(2, versions.Count()); Assert.Equal(versions.First(), DependencyVersionParser.Parse(Constants.SpecificRabbitVersion, false)); }
public void Parse_MinorWildcard() { string version = "3.*"; var parsedVersion = DependencyVersionParser.Parse(version, true); var castedVersion = Assert.IsAssignableFrom <WildcardDependencyVersion>(parsedVersion); Assert.Equal(3, (int)castedVersion.Major); Assert.True(castedVersion.IsMinorWildcard, "Minor should be marked as wildcard"); }
public override async Task <IEnumerable <DependencyVersion> > GetVersions() { var versions = new List <DependencyVersion>(); var connectionString = string.Empty; if (!this.connectionStringProvider.TryGetConnectionString(out connectionString)) { throw new ConnectionStringNotFoundException(this.connectionStringProvider.ToString()); } HttpWebResponse response; try { var request = this.GetHttpWebRequest(connectionString, SupportedDependencies.Elasticsearch.ToString()); var getResponseTask = request.GetResponseAsync(); var readWriteTimeout = this.ConnectTimeout + this.ReadWriteTimeout; readWriteTimeout = readWriteTimeout < 1000 ? 1000 : readWriteTimeout; //If Elasticsearch takes to long to return a response, when readWriteTimeout passes, the request will be aborted var completedTask = await Task.WhenAny(getResponseTask, Task.Delay(readWriteTimeout)).ConfigureAwait(false); if (completedTask == getResponseTask) { using (response = await getResponseTask.ConfigureAwait(false) as HttpWebResponse) { using (var reader = new StreamReader(response.GetResponseStream())) { var body = await reader.ReadToEndAsync(); var version = string.Empty; version = this.DeserializeJsonResponse(body); versions.Add(DependencyVersionParser.Parse(version, false)); } } } else { request.Abort(); throw new NAMEException($"{SupportedDependencies.Elasticsearch}: Timed out, the server accepted the connection but did not send a response.", NAMEStatusLevel.Error); } } catch (WebException e) { throw new DependencyNotReachableException($"{SupportedDependencies.Elasticsearch}: {e.Message}"); } return(versions); }
private static DependencyVersion ParseMaximumVersion(string version, string dependencyType) { if (DependencyVersionParser.TryParse(version, true, out DependencyVersion parsedVersion)) { return(parsedVersion); } if (!dependencyVersionTranslators.ContainsKey(dependencyType)) { throw new VersionParsingException($"Could not parse the version of the dependency type {dependencyType}."); } return(dependencyVersionTranslators[dependencyType].Translate(version)); }
private OperatingSystemDependencyVersion HandleWindowsOperatingSystem() { #if NET45 return(new OperatingSystemDependencyVersion("windows", (uint)Environment.OSVersion.Version.Major, (uint)Environment.OSVersion.Version.Minor, (uint)Environment.OSVersion.Version.Build)); #else string osDescription = RuntimeInformation.OSDescription; string versionPortion = osDescription.Split(new char[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Last(); if (!DependencyVersionParser.TryParse(versionPortion, false, out var version)) { throw new NAMEException($"Windows: Was not able to extract the version from the OS description ({osDescription}).", NAMEStatusLevel.Warn); } return(new OperatingSystemDependencyVersion("windows", version)); #endif }
/// <summary> /// Gets the version of the SQL Server. /// </summary> /// <returns> /// Returns an enumerable with a single element containing the version of the SQL Server. /// </returns> /// <exception cref="NAMEException">An unexpected exception happened. See inner exception for details.</exception> public override async Task <IEnumerable <DependencyVersion> > GetVersions() { this.ExtractHostnameAndPort(out string hostname, out int port); byte[] message = this.CreatePreLoginMessage(); using (var client = await this.OpenTcpClient(hostname, port, SupportedDependencies.SqlServer.ToString())) { await client.GetStream().WriteAsync(message, 0, message.Length, default(CancellationToken)).ConfigureAwait(false); string versionStr = this.GetServerVersionFromResponse(client.GetStream()); return(new List <DependencyVersion> { DependencyVersionParser.Parse(versionStr, false) }); } }
/// <summary> /// Gets the versions. /// </summary> /// <returns> /// Returns an enumerable with only an item, containing the RabbitMq version. /// </returns> /// <exception cref="NAMEException">An unexpected exception happened. See inner exception for details.</exception> public override async Task <IEnumerable <DependencyVersion> > GetVersions() { if (!this.connectionStringProvider.TryGetConnectionString(out var rabbitConnectionString)) { throw new ConnectionStringNotFoundException(this.connectionStringProvider.ToString()); } var result = new List <DependencyVersion>(); foreach (string connectionString in rabbitConnectionString.Split(',')) { Uri rabbitMQUri = new Uri(connectionString.Trim()); using (var client = await this.OpenTcpClient(rabbitMQUri.Host, rabbitMQUri.Port, SupportedDependencies.RabbitMq.ToString()).ConfigureAwait(false)) { SendConnectionHeader(client); string version = GetVersionFromServerReponse(client); result.Add(DependencyVersionParser.Parse(version, false)); } } return(result); }
private OperatingSystemDependencyVersion HandleLinuxOperatingSystem() { if (!File.Exists(LINUX_OS_RELEASE_FILE)) { throw new NAMEException($"Linux: The file {LINUX_OS_RELEASE_FILE} does not exist or not enough permissions.", NAMEStatusLevel.Warn); } var osReleaseLines = File.ReadAllLines(LINUX_OS_RELEASE_FILE); string distroId = null; string distroVersion = null; foreach (string line in osReleaseLines) { if (line.StartsWith(LINUX_OS_RELEASE_DISTRO_NAME_KEY + '=', StringComparison.Ordinal)) { distroId = line.Split('=')[1].Trim('"'); } else if (line.StartsWith(LINUX_OS_RELEASE_DISTRO_VERSION_KEY + '=', StringComparison.Ordinal)) { distroVersion = line.Split('=')[1].Trim('"'); } } if (distroId == null) { throw new NAMEException($"Linux: Was unable to resolve the current distribution.", NAMEStatusLevel.Warn); } if (distroVersion == null) { throw new NAMEException($"Linux: Was unable to resolve the current version.", NAMEStatusLevel.Warn); } if (!DependencyVersionParser.TryParse(distroVersion, false, out var parsedVersion)) { throw new NAMEException($"Linux: The extracted version ({distroVersion}) from the file {LINUX_OS_RELEASE_FILE} is not valid.", NAMEStatusLevel.Warn); } return(new OperatingSystemDependencyVersion(distroId, parsedVersion)); }
/// <summary> /// Gets the versions. /// </summary> /// <returns> /// Returns an enumerable with the versions. /// </returns> /// <exception cref="ConnectionStringNotFoundException">The connection string was not found</exception> /// <exception cref="NAMEException">The service returned an invalid JSON from the manifest endpoint</exception> /// <exception cref="VersionParsingException">The version from manifest cannot be parsed</exception> public override async Task <IEnumerable <DependencyVersion> > GetVersions() { if (!this._connectionStringProvider.TryGetConnectionString(out string serviceConnectionString)) { throw new ConnectionStringNotFoundException(this._connectionStringProvider.ToString()); } var serviceUri = new Uri(serviceConnectionString + Constants.MANIFEST_ENDPOINT); string jsonContents = await this.GetManifest(serviceUri, true, this.HopNumber) .ConfigureAwait(false); DependencyVersion dependencyVersion; JsonNode node; try { node = Json.Json.Parse(jsonContents); DependencyVersionParser.TryParse(node?["version"], false, out dependencyVersion); } catch (Exception ex) { throw new NAMEException($"{SupportedDependencies.Service}: The service returned an invalid JSON from the manifest endpoint.", ex, NAMEStatusLevel.Warn); } if (dependencyVersion == null) { throw new VersionParsingException(node?["version"], $"The version from manifest {node} cannot be parsed"); } dependencyVersion.ManifestNode = node; await this.GetDependantManifests(dependencyVersion).ConfigureAwait(false); return(new[] { dependencyVersion }); }
public static bool TryParse(string version, out DependencyVersion outVersion) { return(DependencyVersionParser.TryParse(version, false, out outVersion)); }
public static DependencyVersion Parse(string version) { return(DependencyVersionParser.Parse(version, false)); }
public void Translate_Versions(WindowsVersions exptectedVersion, string versionStr) { IVersionTranslator translator = new WindowsVersionTranslator(); string v = translator.Translate(new OperatingSystemDependencyVersion("windows", DependencyVersionParser.Parse(versionStr, false))); Assert.True(v == exptectedVersion.ToString()); }