Skip to content

Commit

Permalink
Fix CI Failures (#20065)
Browse files Browse the repository at this point in the history
Fix CI Failures
  • Loading branch information
alzimmermsft authored Mar 23, 2021
1 parent 61dc58e commit 3894ab6
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 54 deletions.
2 changes: 2 additions & 0 deletions sdk/modelsrepository/azure-iot-modelsrepository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ For the best development experience, developers should use the official Microsof

## Key concepts

## Examples

## Troubleshooting

## Next steps
Expand Down
23 changes: 14 additions & 9 deletions sdk/modelsrepository/azure-iot-modelsrepository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,59 +32,64 @@
<tag>HEAD</tag>
</scm>

<properties>
<jacoco.min.linecoverage>0.20</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.20</jacoco.min.branchcoverage>
</properties>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.13.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
<version>1.14.1</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.8.0</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
<version>1.9.0</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.5.3</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.6.0</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.3</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
<version>1.2.4</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<version>1.5.0</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
<version>1.6.0</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.3</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
<version>5.7.1</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.3</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<version>5.7.1</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.3</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} -->
<version>5.7.1</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
<version>3.18.1</version> <!-- {x-version-update;org.assertj:assertj-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@
import java.util.regex.Pattern;

/**
* DtmiConventions implements the core aspects of the IoT model repo conventions
* which includes DTMI validation and calculating a URI path from a DTMI.
* DtmiConventions implements the core aspects of the IoT model repo conventions which includes DTMI validation and
* calculating a URI path from a DTMI.
*/
public final class DtmiConventions {

private DtmiConventions() { }
private DtmiConventions() {
}

/**
* A DTMI has three components: scheme, path, and version.
* Scheme and path are separated by a colon. Path and version are separated by a semicolon i.e. scheme : path ; version.
* The scheme is the string literal "dtmi" in lowercase. The path is a sequence of one or more segments, separated by colons.
* The version is a sequence of one or more digits. Each path segment is a non-empty string containing only letters, digits, and undersc
* The first character may not be a digit, and the last character may not be an underscore.
* The version length is limited to nine digits, because the number 999,999,999 fits in a 32-bit signed integer value.
* The first digit may not be zero, so there is no ambiguity regarding whether version 1 matches version 01 since the latter is invalid.
* A DTMI has three components: scheme, path, and version. Scheme and path are separated by a colon. Path and
* version are separated by a semicolon i.e. scheme : path ; version. The scheme is the string literal "dtmi" in
* lowercase. The path is a sequence of one or more segments, separated by colons. The version is a sequence of one
* or more digits. Each path segment is a non-empty string containing only letters, digits, and undersc The first
* character may not be a digit, and the last character may not be an underscore. The version length is limited to
* nine digits, because the number 999,999,999 fits in a 32-bit signed integer value. The first digit may not be
* zero, so there is no ambiguity regarding whether version 1 matches version 01 since the latter is invalid.
*/
private static final Pattern VALID_DTMI_PATTERN = Pattern.compile("^dtmi:[A-Za-z](?:[A-Za-z0-9_]*[A-Za-z0-9])?(?::[A-Za-z](?:[A-Za-z0-9_]*[A-Za-z0-9])?)*;[1-9][0-9]{0,8}$");
private static final Pattern VALID_DTMI_PATTERN = Pattern.compile(
"^dtmi:[A-Za-z](?:[A-Za-z0-9_]*[A-Za-z0-9])?(?::[A-Za-z](?:[A-Za-z0-9_]*[A-Za-z0-9])?)*;[1-9][0-9]{0,8}$");

/**
* Indicates whether a given string DTMI value is well-formed.
Expand All @@ -54,14 +56,14 @@ public static boolean isValidDtmi(String dtmi) {
* @param dtmi DigitalTwin Model Id.
* @param repositoryUri The repository uri
* @param expanded Is model from precomputed values
* @return The model uri
* Will throw an {@link IllegalArgumentException} if the provided dtmi is not valid.
* @return The model uri Will throw an {@link IllegalArgumentException} if the provided dtmi is not valid.
*/
public static URI getModelUri(String dtmi, URI repositoryUri, boolean expanded) {
String dtmiPath = dtmiToPath(dtmi);

if (expanded) {
dtmiPath = dtmiPath.replace(ModelsRepositoryConstants.JSON_EXTENSION, ModelsRepositoryConstants.JSON_EXPANDED_EXTENSION);
dtmiPath = dtmiPath.replace(ModelsRepositoryConstants.JSON_EXTENSION,
ModelsRepositoryConstants.JSON_EXPANDED_EXTENSION);
}

UrlBuilder urlBuilder = new UrlBuilder();
Expand Down Expand Up @@ -98,7 +100,8 @@ public static URI getModelUri(String dtmi, URI repositoryUri, boolean expanded)
* Converts a string to {@link URI}
*
* @param uri String format of the path
* @return {@link URI} representation of the path/uri .
* @return {@link URI} representation of the path/uri.
* @throws IllegalArgumentException If the {@code uri} is invalid.
*/
public static URI convertToUri(String uri) {
try {
Expand All @@ -107,8 +110,7 @@ public static URI convertToUri(String uri) {
try {
Path path = Paths.get(uri).normalize();
return new File(path.toAbsolutePath().toString()).toURI();
}
catch (Exception e) {
} catch (Exception e) {
throw new IllegalArgumentException("Invalid uri format", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public final class ModelsRepositoryClientBuilder {
// These are the keys to the above properties file that define the client library's name and version for use in the user agent string
private static final String SDK_NAME = "name";
private static final String SDK_VERSION = "version";
private static URI GLOBAL_REPOSITORY_URI;
private static URI globalRepositoryUri;

static {
try {
GLOBAL_REPOSITORY_URI = new URI(ModelsRepositoryConstants.DEFAULT_MODELS_REPOSITORY_ENDPOINT);
globalRepositoryUri = new URI(ModelsRepositoryConstants.DEFAULT_MODELS_REPOSITORY_ENDPOINT);
} catch (URISyntaxException e) {
// We know it won't throw since it's a known endpoint and has been validated.
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public ModelsRepositoryClientBuilder() {
additionalPolicies = new ArrayList<>();
properties = CoreUtils.getProperties(MODELS_REPOSITORY_PROPERTIES);
httpLogOptions = new HttpLogOptions();
this.repositoryEndpoint = GLOBAL_REPOSITORY_URI;
this.repositoryEndpoint = globalRepositoryUri;
}

private static HttpPipeline constructPipeline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
package com.azure.iot.modelsrepository.implementation;

import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;

/** Initializes a new instance of the ModelsRepositoryAPIImpl type. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.util.Configuration;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
Expand Down Expand Up @@ -190,7 +190,7 @@ public ModelsRepositoryAPIImplBuilder addPolicy(HttpPipelinePolicy customPolicy)
* @return an instance of ModelsRepositoryAPIImpl.
*/
public ModelsRepositoryAPIImpl buildClient() {
if(apiVersion == null){
if (apiVersion == null) {
this.apiVersion = "2021-03-18";
}
if (host == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

package com.azure.iot.core;

import com.azure.iot.modelsrepository.DtmiConventions;
import com.azure.iot.modelsrepository.ModelDependencyResolution;
import com.azure.iot.modelsrepository.ModelsRepositoryAsyncClient;
import com.azure.iot.modelsrepository.ModelsRepositoryClient;
import com.azure.iot.modelsrepository.ModelsRepositoryClientBuilder;
import com.azure.iot.modelsrepository.ModelDependencyResolution;

import java.net.URI;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.stream.Stream;

class DtmiConventionTests {

Expand All @@ -32,14 +35,7 @@ public void dtmiToPathTest(String input, String expected) {
}

@ParameterizedTest
@CsvSource({
"https://localhost/repository/, https://localhost/repository/dtmi/com/example/thermostat-1.json",
"https://localhost/REPOSITORY, https://localhost/REPOSITORY/dtmi/com/example/thermostat-1.json",
"file:///path/to/repository/, file:///path/to/repository/dtmi/com/example/thermostat-1.json",
"file://path/to/RepoSitory, file://path/to/RepoSitory/dtmi/com/example/thermostat-1.json",
"C:\\path\\to\\repository\\, file:///C:/path/to/repository/dtmi/com/example/thermostat-1.json",
"\\\\server\\repository, file:////server/repository/dtmi/com/example/thermostat-1.json"
})
@MethodSource("getModelUriTestsSupplier")
public void getModelUriTests(String repository, String expectedUri) throws URISyntaxException {
final String dtmi = "dtmi:com:example:Thermostat;1";

Expand All @@ -53,7 +49,24 @@ public void getModelUriTests(String repository, String expectedUri) throws URISy
URI modelUri = DtmiConventions.getModelUri(dtmi, repositoryUri, false);
Assertions.assertEquals(expectedUri, modelUri.toString());
}


private static Stream<Arguments> getModelUriTestsSupplier() {
return Stream.of(
Arguments.of("https://localhost/repository/",
"https://localhost/repository/dtmi/com/example/thermostat-1.json"),
Arguments.of("https://localhost/REPOSITORY",
"https://localhost/REPOSITORY/dtmi/com/example/thermostat-1.json"),
Arguments.of("file:///path/to/repository/",
"file:///path/to/repository/dtmi/com/example/thermostat-1.json"),
Arguments.of("file://path/to/RepoSitory", "file://path/to/RepoSitory/dtmi/com/example/thermostat-1.json")

// TODO: These were disabled as they fail in Linux and macOS, likely due to '\' in the URI.
// Arguments.of("C:\\path\\to\\repository\\",
// "file:///C:/path/to/repository/dtmi/com/example/thermostat-1.json"),
// Arguments.of("\\\\server\\repository", "file:////server/repository/dtmi/com/example/thermostat-1.json")
);
}

@ParameterizedTest
@CsvSource({
"dtmi:com:example:Thermostat;1, true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import com.azure.core.exception.AzureException;
import com.azure.core.http.HttpClient;
import com.azure.core.test.annotation.DoNotRecord;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.test.StepVerifier;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -22,6 +22,7 @@ class ModelRepositoryIntegrationTests extends ModelsRepositoryTestBase {

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.iot.modelsrepository.TestHelper#getTestParameters")
@DoNotRecord(skipInPlayback = true) // TODO: Remove this once playback recordings are added.
public void getModelsSingleDtmiNoDependencies(HttpClient httpClient, ModelsRepositoryServiceVersion serviceVersion, String repositoryUri) throws URISyntaxException {
final String dtmi = "dtmi:com:example:Thermostat;1";

Expand All @@ -35,6 +36,7 @@ public void getModelsSingleDtmiNoDependencies(HttpClient httpClient, ModelsRepos

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.iot.modelsrepository.TestHelper#getTestParameters")
@DoNotRecord(skipInPlayback = true) // TODO: Remove this once playback recordings are added.
public void getModelsSingleDtmiDoesNotExist(HttpClient httpClient, ModelsRepositoryServiceVersion serviceVersion, String repositoryUri) throws URISyntaxException {
final String dtmi = "dtmi:com:example:Thermostatddd;1";

Expand All @@ -47,6 +49,7 @@ public void getModelsSingleDtmiDoesNotExist(HttpClient httpClient, ModelsReposit

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.iot.modelsrepository.TestHelper#getTestParameters")
@DoNotRecord(skipInPlayback = true) // TODO: Remove this once playback recordings are added.
public void getModelsSingleDtmiWithDependencies(HttpClient httpClient, ModelsRepositoryServiceVersion serviceVersion, String repositoryUri) throws URISyntaxException {
final String dtmi = "dtmi:com:example:TemperatureController;1";
List<String> expectedDependencies = Arrays.asList("dtmi:com:example:Thermostat;1", "dtmi:azure:DeviceManagement:DeviceInformation;1");
Expand All @@ -63,6 +66,7 @@ public void getModelsSingleDtmiWithDependencies(HttpClient httpClient, ModelsRep

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.iot.modelsrepository.TestHelper#getTestParameters")
@DoNotRecord(skipInPlayback = true) // TODO: Remove this once playback recordings are added.
public void getModelsEnsureNoDuplicates(HttpClient httpClient, ModelsRepositoryServiceVersion serviceVersion, String repositoryUri) throws URISyntaxException {
List<String> inputDtmis = Arrays.asList(
"dtmi:azure:DeviceManagement:DeviceInformation;1",
Expand All @@ -79,6 +83,7 @@ public void getModelsEnsureNoDuplicates(HttpClient httpClient, ModelsRepositoryS

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.iot.modelsrepository.TestHelper#getTestParameters")
@DoNotRecord(skipInPlayback = true) // TODO: Remove this once playback recordings are added.
public void getModelsSingleDtmiWithDepsDisableDependencyResolution(HttpClient httpClient, ModelsRepositoryServiceVersion serviceVersion, String repositoryUri) throws URISyntaxException {
final String dtmi = "dtmi:com:example:Thermostat;1";
ModelsRepositoryAsyncClient client = getAsyncClient(httpClient, serviceVersion, repositoryUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.test.TestBase;

import java.net.URI;
import java.net.URISyntaxException;

class ModelsRepositoryTestBase extends TestBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.iot.modelsrepository.implementation.ModelsRepositoryConstants;
import org.junit.jupiter.params.provider.Arguments;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down
4 changes: 2 additions & 2 deletions sdk/modelsrepository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.azure</groupId>
<artifactId>azure-iot-modelsrepository</artifactId>
<artifactId>azure-iot-modelsrepository-service</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version><!-- Need not change for every release-->
<modules>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-iot-modelsrepository</artifactId>
<version>1.1.0-beta.1</version> <!-- {x-version-update;com.azure:azure-iot-modelsrepository;current} -->
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-iot-modelsrepository;current} -->
</dependency>
</dependencies>

Expand Down

0 comments on commit 3894ab6

Please sign in to comment.