-
Notifications
You must be signed in to change notification settings - Fork 230
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
http-client-java, e2e test, use clientcore #5437
base: main
Are you sure you want to change the base?
Changes from all commits
6a4277a
ff96a9d
46a13a3
9948161
4f592fd
3585249
65ec59f
e788921
806fb04
3412085
f07eb05
f385033
078bda8
ac8c552
d77db37
58275a2
64cabcd
4b6a886
55bea5e
acbccbd
cdcec31
6139301
38a23eb
a3a8cdc
883adf5
c83f5b0
fdc7911
8f173e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Use case: | ||
# | ||
# The purpose of this script is to compact the steps required to regenerate TypeSpec into a single script. | ||
# | ||
param ( | ||
[int] $Parallelization = [Environment]::ProcessorCount | ||
) | ||
|
||
|
||
$ExitCode = 0 | ||
|
||
if ($Parallelization -lt 1) { | ||
$Parallelization = 1 | ||
} | ||
|
||
Write-Host "Parallelization: $Parallelization" | ||
|
||
|
||
$generateScript = { | ||
$tspFile = $_ | ||
|
||
$tspClientFile = $tspFile -replace 'main.tsp', 'client.tsp' | ||
if (($tspClientFile -match 'client.tsp$') -and (Test-Path $tspClientFile)) { | ||
$tspFile = $tspClientFile | ||
} | ||
|
||
# With TypeSpec code generation being parallelized, we need to make sure that the output directory is unique | ||
# for each test run. We do this by appending a random number to the output directory. | ||
# Without this, we could have multiple runs trying to write to the same directory which introduces race conditions. | ||
$tspOptions = "--option ""@typespec/http-client-java.emitter-output-dir={project-root}/tsp-output/$(Get-Random)""" | ||
if ($tspFile -match "type[\\/]enum[\\/]extensible[\\/]") { | ||
# override namespace for reserved keyword "enum" | ||
$tspOptions += " --option ""@typespec/http-client-java.namespace=type.enums.extensible""" | ||
} elseif ($tspFile -match "type[\\/]enum[\\/]fixed[\\/]") { | ||
# override namespace for reserved keyword "enum" | ||
$tspOptions += " --option ""@typespec/http-client-java.namespace=type.enums.fixed""" | ||
} elseif ($tspFile -match "type[\\/]array" -or $tspFile -match "type[\\/]dictionary") { | ||
# TODO https://github.com/Azure/autorest.java/issues/2964 | ||
# also serve as a test for "use-object-for-unknown" emitter option | ||
$tspOptions += " --option ""@typespec/http-client-java.use-object-for-unknown=true""" | ||
} | ||
|
||
$tspTrace = "--trace import-resolution --trace projection --trace http-client-java" | ||
$tspCommand = "npx --no-install tsp compile $tspFile $tspOptions $tspTrace" | ||
|
||
$timer = [Diagnostics.Stopwatch]::StartNew() | ||
$generateOutput = Invoke-Expression $tspCommand | ||
$timer.Stop() | ||
|
||
$global:ExitCode = $global:ExitCode -bor $LASTEXITCODE | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
Write-Host " | ||
======================== | ||
$tspCommand | ||
======================== | ||
FAILED (Time elapsed: $($timer.ToString())) | ||
$([String]::Join("`n", $generateOutput)) | ||
" | ||
} else { | ||
Write-Host " | ||
======================== | ||
$tspCommand | ||
======================== | ||
SUCCEEDED (Time elapsed: $($timer.ToString())) | ||
" | ||
} | ||
|
||
if ($global:ExitCode -ne 0) { | ||
exit $global:ExitCode | ||
} | ||
} | ||
|
||
./Setup.ps1 | ||
|
||
if (Test-Path ./src/main) { | ||
Remove-Item ./src/main -Recurse -Force | ||
} | ||
if (Test-Path ./src/samples) { | ||
Remove-Item ./src/samples -Recurse -Force | ||
} | ||
if (Test-Path ./tsp-output) { | ||
Remove-Item ./tsp-output -Recurse -Force | ||
} | ||
|
||
# generate for http-specs/azure-http-specs test sources | ||
Copy-Item -Path node_modules/@typespec/http-specs/specs -Destination ./ -Recurse -Force | ||
# remove xml tests, emitter has not supported xml model | ||
Remove-Item ./specs/payload/xml -Recurse -Force | ||
|
||
# ServiceVersion not in core | ||
Remove-Item ./specs/versioning -Recurse -Force | ||
Remove-Item ./specs/server/path -Recurse -Force | ||
Remove-Item ./specs/server/versions -Recurse -Force | ||
# TokenCredential not in core | ||
Remove-Item ./specs/authentication/oauth2 -Recurse -Force | ||
Remove-Item ./specs/authentication/union -Recurse -Force | ||
# Base64Url not in core | ||
Remove-Item ./specs/encode/bytes -Recurse -Force | ||
# DateTimeRfc1123 is private in beta.1, should now be public in main | ||
Remove-Item ./specs/encode/datetime -Recurse -Force | ||
Remove-Item ./specs/special-headers -Recurse -Force | ||
# JacksonAdapter not in core | ||
Remove-Item ./specs/encode/duration -Recurse -Force | ||
Comment on lines
+91
to
+104
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. At present, lots of tests is skipped, due to class/feature not available in clientcore (compile failure). Some tests are also disabled (runtime failure). We will later make a summary on these, and discuss what need to be fixed in clientcore, what need to be handled differently in emitter. After clientcore beta.2 we likely can enable more test (I think I can see |
||
|
||
$job = (Get-ChildItem ./specs -Include "main.tsp","old.tsp" -File -Recurse) | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob | ||
|
||
$job | Wait-Job -Timeout 1200 | ||
$job | Receive-Job | ||
|
||
Remove-Item ./specs -Recurse -Force | ||
|
||
Copy-Item -Path ./tsp-output/*/src -Destination ./ -Recurse -Force -Exclude @("module-info.java") | ||
|
||
Remove-Item ./tsp-output -Recurse -Force | ||
|
||
if (Test-Path ./src/main/resources/META-INF/client-structure-service_apiview_properties.json) { | ||
# client structure is generated from multiple client.tsp files and the last one to execute overwrites | ||
# the api view properties file. Because the tests run in parallel, the order is not guaranteed. This | ||
# causes git diff check to fail as the checked in file is not the same as the generated one. | ||
Remove-Item ./src/main/resources/META-INF/client-structure-service_apiview_properties.json -Force | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# re-build http-client-java | ||
Set-Location (Resolve-Path (Join-Path $PSScriptRoot '..' '..')) | ||
|
||
./Setup.ps1 | ||
|
||
Set-Location $PSScriptRoot | ||
|
||
npm run clean && npm install |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#Requires -Version 7.0 | ||
|
||
$ErrorActionPreference = 'Stop' | ||
Set-StrictMode -Version 3.0 | ||
|
||
Write-Host "Running Spector tests" | ||
|
||
Write-Host "Starting the Spector server" | ||
npm run spector-start | ||
Write-Host "Compile and run the tests" | ||
mvn clean test --no-transfer-progress -T 1C | ||
if ($LASTEXITCODE -ne 0) { | ||
exit $LASTEXITCODE | ||
} | ||
Write-Host "Stopping the Spector server" | ||
npm run spector-stop | ||
|
||
Write-Host "Finished running the Spector tests" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@typespec/http-client-java-clientcore-tests", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"scripts": { | ||
"clean": "rimraf ./node_modules/@typespec/http-client-java ./package-lock.json ./tsp-output", | ||
"format": "npm run -s prettier -- --write", | ||
"check-format": "npm run prettier -- --check", | ||
"prettier": "prettier --config ./.prettierrc.yaml **/*.tsp", | ||
"spector-serve": "tsp-spector serve ./node_modules/@typespec/http-specs/specs --coverageFile ./tsp-spector-coverage-java-standard.json", | ||
"spector-start": "tsp-spector server start ./node_modules/@typespec/http-specs/specs --coverageFile ./tsp-spector-coverage-java-standard.json", | ||
"spector-stop": "tsp-spector server stop" | ||
}, | ||
"dependencies": { | ||
"@typespec/http-specs": "0.1.0-alpha.5", | ||
"@typespec/http-client-java": "file:../../typespec-http-client-java-0.1.5.tgz", | ||
"@typespec/http-client-java-tests": "file:" | ||
}, | ||
"overrides": { | ||
"@typespec/compiler": "~0.63.0", | ||
"@typespec/http": "~0.63.0", | ||
"@typespec/rest": "~0.63.0", | ||
"@typespec/versioning": "~0.63.0", | ||
"@typespec/openapi": "~0.63.0", | ||
"@typespec/xml": "~0.63.0", | ||
"@azure-tools/typespec-azure-core": "~0.49.0", | ||
"@azure-tools/typespec-client-generator-core": "~0.49.1", | ||
"@azure-tools/typespec-azure-resource-manager": "~0.49.0", | ||
"@azure-tools/typespec-autorest": "~0.49.0" | ||
}, | ||
"private": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
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> | ||
<parent> | ||
<groupId>com.microsoft.typespec</groupId> | ||
<artifactId>typespec-java-generator</artifactId> | ||
<version>1.0.0-beta.1</version> | ||
</parent> | ||
|
||
<groupId>com.microsoft.typespec</groupId> | ||
<artifactId>http-client-generator-clientcore-test</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>http-client-generator-test</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<spotless.config.path>../</spotless.config.path> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.clientcore</groupId> | ||
<artifactId>core</artifactId> | ||
<version>1.0.0-beta.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.11.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.projectreactor</groupId> | ||
<artifactId>reactor-test</artifactId> | ||
<version>3.4.41</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>4.11.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- bytebuddy dependencies are required for mockito 4.11.0 to work with Java 21. Mockito 4.11.0 is the last release --> | ||
<!-- of Mockito supporting Java 8 as a baseline. --> | ||
<dependency> | ||
<groupId>net.bytebuddy</groupId> | ||
<artifactId>byte-buddy</artifactId> | ||
<version>1.15.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.bytebuddy</groupId> | ||
<artifactId>byte-buddy-agent</artifactId> | ||
<version>1.15.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.36</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.18.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>5.11.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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.
Now we can finally take the report of unbranded e2e.