Skip to content
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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6a4277a
add http-client-generator-standard-test
weidongxu-microsoft Dec 25, 2024
ff96a9d
skip versioning
weidongxu-microsoft Dec 25, 2024
46a13a3
more skipped tests
weidongxu-microsoft Dec 25, 2024
9948161
bug fix on count of clients
weidongxu-microsoft Dec 25, 2024
4f592fd
generated code
weidongxu-microsoft Dec 25, 2024
3585249
ignore spelling and prettier on http-client-generator-standard-test f…
weidongxu-microsoft Dec 25, 2024
65ec59f
Add test case to http-client-generator-standard-test
v-hongli1 Jan 2, 2025
e788921
Fix import and remove useless cases
v-hongli1 Jan 2, 2025
806fb04
Fix test exception
v-hongli1 Jan 3, 2025
3412085
Fix comments
v-hongli1 Jan 6, 2025
f07eb05
Fix comments
v-hongli1 Jan 6, 2025
f385033
Fix comments
v-hongli1 Jan 6, 2025
078bda8
Merge pull request #1 from v-hongli1/http-client-java_e2e-standard
weidongxu-microsoft Jan 7, 2025
ac8c552
remove AzureKeyCredentialPolicy
weidongxu-microsoft Jan 8, 2025
d77db37
format
weidongxu-microsoft Jan 8, 2025
58275a2
remove DecimalJackson
weidongxu-microsoft Jan 8, 2025
64cabcd
eng, use standard report
weidongxu-microsoft Jan 8, 2025
4b6a886
Merge branch 'main' into http-client-java_e2e-standard
weidongxu-microsoft Jan 8, 2025
55bea5e
add Spector-Tests.ps1
weidongxu-microsoft Jan 8, 2025
acbccbd
internal publish, if not on main
weidongxu-microsoft Jan 8, 2025
cdcec31
regen
weidongxu-microsoft Jan 8, 2025
6139301
no need to verify java, when it is no-emit
weidongxu-microsoft Jan 8, 2025
38a23eb
add tsp-spector to devDep
weidongxu-microsoft Jan 8, 2025
a3a8cdc
Revert "no need to verify java, when it is no-emit"
weidongxu-microsoft Jan 8, 2025
883adf5
move to http-client-generator-clientcore-test
weidongxu-microsoft Jan 9, 2025
c83f5b0
remove GenerationChecks, as currently generated code is still checked-in
weidongxu-microsoft Jan 9, 2025
fdc7911
Merge branch 'main' into http-client-java_e2e-standard
weidongxu-microsoft Jan 9, 2025
8f173e7
nit
weidongxu-microsoft Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ packages/http-client-csharp/generator/TestProjects/**/tspCodeModel.json

# auto generated api view properties files
packages/http-client-java/generator/http-client-generator-test/src/main/**/*.json
packages/http-client-java/generator/http-client-generator-clientcore-test/src/main/**/*.json
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ ignorePaths:
- "**/ThirdPartyNotices.txt"
- packages/compiler/test/formatter/scenarios/**
- packages/http-client-java/generator/http-client-generator-test/**
- packages/http-client-java/generator/http-client-generator-clientcore-test/**
- pnpm-lock.yaml
- "**/*.mp4"
- .git/**
Expand Down
3 changes: 1 addition & 2 deletions packages/http-client-java/eng/pipeline/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extends:
parameters:
BuildPrereleaseVersion: true
UseTypeSpecNext: false
Publish: "public"
Publish: ${{replace(replace('True',eq(variables['Build.SourceBranchName'], 'main'), 'public'),'True','internal')}}
PublishDependsOnTest: true
PackagePath: /packages/http-client-java
EmitterPackageJsonPath: packages/http-client-java/emitter/package.json
Expand All @@ -30,4 +30,3 @@ extends:
LanguageShortName: "java"
HasNugetPackages: false
CadlRanchName: "@typespec/http-client-java"
EnableCadlRanchReport: false
7 changes: 5 additions & 2 deletions packages/http-client-java/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ $env:PATH = "$env:JAVA_HOME\bin;$env:PATH"
Invoke "npm run build:generator"
Invoke "npm run build:emitter"

$testDir = Join-Path $repoRoot 'test'

$generatorTestDir = Join-Path $repoRoot 'generator/http-client-generator-test'
Set-Location $generatorTestDir
./Generate.ps1
Set-Location $PSScriptRoot

$generatorTestDir = Join-Path $repoRoot 'generator/http-client-generator-clientcore-test'
Set-Location $generatorTestDir
./Generate.ps1
Set-Location $PSScriptRoot
16 changes: 14 additions & 2 deletions packages/http-client-java/eng/scripts/Test-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ try {
& ./Setup.ps1
& ./Spector-Tests.ps1
Set-Location $packageRoot
Write-Host "Spector tests passed"
}
finally {
Pop-Location
}

$generatorTestDir = Join-Path $packageRoot 'generator/http-client-generator-clientcore-test'
Push-Location $generatorTestDir
try {
& ./Setup.ps1
& ./Spector-Tests.ps1
Set-Location $packageRoot
}
finally {
Pop-Location
}

Write-Host "Spector tests passed"
}
catch {
Write-Error "Spector tests failed: $_"
Expand All @@ -52,7 +64,7 @@ try {
if (!(Test-Path $coverageReportDir)) {
New-Item -ItemType Directory -Path $coverageReportDir

$sourceFile = Join-Path $packageRoot 'generator/http-client-generator-test/tsp-spector-coverage-java-standard.json'
$sourceFile = Join-Path $packageRoot 'generator/http-client-generator-clientcore-test/tsp-spector-coverage-java-standard.json'
Copy link
Contributor Author

@weidongxu-microsoft weidongxu-microsoft Jan 9, 2025

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.

$targetFile = Join-Path $coverageReportDir 'tsp-spector-coverage-java-standard.json'
Copy-Item $sourceFile -Destination $targetFile
}
Expand Down
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
Copy link
Contributor Author

@weidongxu-microsoft weidongxu-microsoft Jan 9, 2025

Choose a reason for hiding this comment

The 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 DateTimeRfc1123 be public in current code)


$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>
Loading
Loading