Skip to content
Permalink
Browse files

Required changes for 3.0.0 preview3 (#112)

* Required changes for 3.0.0 preview3

* Add scripts to install dotnet SDK
  • Loading branch information...
JunTaoLuo committed Feb 21, 2019
1 parent f29c274 commit c7ca9cee320d4f9e6fd9b80603e965205e88333f
@@ -9,9 +9,7 @@ branches:
only:
- master
install:
- curl -o dotnet-sdk.tar.gz -sSL https://download.visualstudio.microsoft.com/download/pr/efa6dde9-a5ee-4322-b13c-a2a02d3980f0/dad445eba341c1d806bae5c8afb47015/dotnet-sdk-3.0.100-preview-010184-linux-x64.tar.gz
- mkdir -p $PWD/dotnet
- tar zxf dotnet-sdk.tar.gz -C $PWD/dotnet
- export PATH="$PWD/dotnet:$PATH"
- ./build/get-dotnet.sh
- export PATH="~/.dotnet/:$PATH"
script:
- ./build_and_test.sh
@@ -27,11 +27,15 @@ Documentation and guides are coming soon! In the mean time we suggest referring

## To develop gRPC for ASP.NET Core

Install [.NET Core SDK 3 preview 2](https://dotnet.microsoft.com/download/dotnet-core/3.0).
Installing .NET Core SDK:
```
# Run this script before building the project.
./build/get-dotnet.sh or ./build/get-dotnet.ps1
```

Setting up local feed with unreleased Grpc.* packages:
```
# For the time being, we are depending on unreleased Grpc.* packages.
# We may depend on unreleased Grpc.* packages.
# Run this script before building the project.
./build/get-grpc.sh or ./build/get-grpc.ps1
```
@@ -0,0 +1,44 @@
#!/usr/bin/env powershell

<#
.PARAMETER Upgrade
Upgrade the version of gRPC packages to be downloaded to the latest on https://packages.grpc.io/
.NOTES
This function will create a file grpc-lock.txt. This lock file can be committed to source, but does not have to be.
When the lock file is not present, the script will create one using latest available version from https://packages.grpc.io/.
#>

param (
[switch]$Upgrade = $false
)

Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'

# Variables

$WorkingDir = $PSScriptRoot
$TempDir = Join-Path $WorkingDir 'obj'
$InstallScriptUrl = 'https://dot.net/v1/dotnet-install.ps1'
$InstallScriptPath = Join-Path $TempDir 'dotnet-install.ps1'
$GlobalJsonPath = Join-Path $WorkingDir '..' | Join-Path -ChildPath 'global.json'

# Functions

function Ensure-Dir([string]$path) {
if (!(Test-Path $path -PathType Container)) {
New-Item -ItemType Directory -Force -Path $path | Out-Null
}
}

# Main

# Resolve SDK version
$GlobalJson = Get-Content -Raw $GlobalJsonPath | ConvertFrom-Json
$SDKVersion = $GlobalJson.sdk.version

# Download install script
Ensure-Dir $TempDir
Write-Host "Downloading install script: $InstallScriptUrl => $InstallScriptPath"
Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath
&$InstallScriptPath -Version $SDKVersion
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -euo pipefail

# variables
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
OBJDIR="$DIR/obj"
global_json_path="$DIR/../global.json"
install_script_url="https://dot.net/v1/dotnet-install.sh"
install_script_path="$OBJDIR/dotnet-install.sh"

# functions
ensure_dir() {
[ -d $1 ] || mkdir $1
}

# main

# resolve SDK version
sdk_version=$(jq -r .sdk.version $global_json_path)

# download dotnet-install.sh
ensure_dir $OBJDIR

echo "Downloading install script: $install_script_url => $install_script_path"
curl -sSL -o $install_script_path $install_script_url
chmod +x $install_script_path

$install_script_path -v $sdk_version
@@ -16,9 +16,7 @@

#endregion

using Grpc.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace GRPCServer
@@ -34,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseRouting(routes =>
{
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100-preview-010184"
"version": "3.0.100-preview3-010313"
}
}
@@ -16,9 +16,7 @@

#endregion

using Grpc.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace BenchmarkServer
@@ -33,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseRouting(routes =>
{
@@ -55,6 +55,28 @@ public static Task WriteMessageAsync(this PipeWriter pipeWriter, byte[] messageD
return Task.FromException(new RpcException(SendingMessageExceedsLimitStatus));
}

// Must call StartAsync before the first pipeWriter.GetSpan() in WriteHeader
var response = serverCallContext.HttpContext.Response;
if (!response.HasStarted)
{
var startAsyncTask = response.StartAsync();
if (!startAsyncTask.IsCompletedSuccessfully)
{
return pipeWriter.WriteMessageCoreAsyncAwaited(messageData, serverCallContext, flush, startAsyncTask);
}
}

return pipeWriter.WriteMessageCoreAsync(messageData, serverCallContext, flush);
}

private static async Task WriteMessageCoreAsyncAwaited(this PipeWriter pipeWriter, byte[] messageData, HttpContextServerCallContext serverCallContext, bool flush, Task startAsyncTask)
{
await startAsyncTask;
await pipeWriter.WriteMessageCoreAsync(messageData, serverCallContext, flush);
}

private static Task WriteMessageCoreAsync(this PipeWriter pipeWriter, byte[] messageData, HttpContextServerCallContext serverCallContext, bool flush)
{
WriteHeader(pipeWriter, messageData.Length);
pipeWriter.Write(messageData);

@@ -77,7 +99,7 @@ public static Task WriteMessageAsync(this PipeWriter pipeWriter, byte[] messageD

private static void WriteHeader(PipeWriter pipeWriter, int length)
{
Span<byte> headerData = pipeWriter.GetSpan(HeaderSize);
var headerData = pipeWriter.GetSpan(HeaderSize);
// Messages are currently always uncompressed
headerData[0] = 0;
EncodeMessageLength(length, headerData.Slice(1));
@@ -20,6 +20,7 @@
using System.Net.Http;
using FunctionalTestsWebsite.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;

@@ -78,11 +78,11 @@ public void MapGrpcService_CanBind_CreatesEndpoints()

var routeEndpoint1 = (RouteEndpoint)endpoints[0];
Assert.AreEqual("/Greet.Greeter/SayHello", routeEndpoint1.RoutePattern.RawText);
Assert.AreEqual("POST", ((IHttpMethodMetadata)routeEndpoint1.Metadata.Single()).HttpMethods.Single());
Assert.AreEqual("POST", routeEndpoint1.Metadata.GetMetadata<IHttpMethodMetadata>().HttpMethods.Single());

var routeEndpoint2 = (RouteEndpoint)endpoints[1];
Assert.AreEqual("/Greet.Greeter/SayHellos", routeEndpoint2.RoutePattern.RawText);
Assert.AreEqual("POST", ((IHttpMethodMetadata)routeEndpoint2.Metadata.Single()).HttpMethods.Single());
Assert.AreEqual("POST", routeEndpoint2.Metadata.GetMetadata<IHttpMethodMetadata>().HttpMethods.Single());
}

[Test]
@@ -0,0 +1,32 @@
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#endregion

using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features;

namespace FunctionalTestsWebsite.Infrastructure
{
internal class TestHttpResponseStartFeature : IHttpResponseStartFeature
{
public Task StartAsync(CancellationToken token = default(CancellationToken))
{
return Task.CompletedTask;
}
}
}
@@ -67,6 +67,8 @@ public void Configure(IApplicationBuilder app)

// Workaround for https://github.com/aspnet/AspNetCore/issues/7449
context.Features.Set<IHttpRequestLifetimeFeature>(new TestHttpRequestLifetimeFeature());
// Workaround for https://github.com/aspnet/AspNetCore/issues/7780
context.Features.Set<IHttpResponseStartFeature>(new TestHttpResponseStartFeature());

return next();
});
@@ -16,15 +16,9 @@

#endregion

using Grpc.AspNetCore;
using Grpc.Testing;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace InteropTestsWebsite
{
@@ -38,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseRouting(builder =>
{

0 comments on commit c7ca9ce

Please sign in to comment.
You can’t perform that action at this time.