Support HTTP/JSON to dubbo (#340)

This commit is contained in:
Hinsteny Hisoka
2023-06-19 10:40:28 +08:00
committed by GitHub
parent ac2f0a5545
commit ea7b581e26
34 changed files with 3341 additions and 27 deletions

View File

@@ -318,3 +318,42 @@ spec:
resources:
requests:
cpu: 10m
---
apiVersion: v1
kind: Pod
metadata:
name: nacos-standlone-rc3
namespace: higress-system
labels:
name: nacos-standlone-rc3
spec:
containers:
- name: nacos-standlone-rc3
image: registry.cn-hangzhou.aliyuncs.com/hinsteny/nacos-standlone-rc3:1.0.0-RC3
ports:
- containerPort: 8848
---
apiVersion: v1
kind: Service
metadata:
name: nacos-standlone-rc3-service
namespace: higress-system
spec:
selector:
name: nacos-standlone-rc3
clusterIP: None
ports:
- name: foo # name is not required for single-port Services
port: 8848
---
apiVersion: v1
kind: Pod
metadata:
name: dubbo-demo-provider
namespace: higress-system
spec:
containers:
- name: dubbo-demo-provider
image: registry.cn-hangzhou.aliyuncs.com/hinsteny/dubbo-provider-demo:0.0.1
ports:
- containerPort: 20880

View File

@@ -0,0 +1,56 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// 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.
package tests
import (
"testing"
"github.com/alibaba/higress/test/ingress/conformance/utils/http"
"github.com/alibaba/higress/test/ingress/conformance/utils/suite"
)
func init() {
HigressConformanceTests = append(HigressConformanceTests, HTTPRouteHttp2Rpc)
}
var HTTPRouteHttp2Rpc = suite.ConformanceTest{
ShortName: "HTTPRouteHttp2Rpc",
Description: "The Ingress in the higress-conformance-infra namespace uses the http2rpc.",
Manifests: []string{"tests/httproute-http2rpc.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
testcases := []http.Assertion{
{
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "foo.com",
Path: "/sayhello?name=hisoka",
Method: "GET",
},
},
Response: http.AssertionResponse{
ExpectedResponseNoRequest: true,
ExpectedResponse: http.Response{
StatusCode: 200,
},
},
},
}
t.Run("HTTPRoute app root", func(t *testing.T) {
for _, testcase := range testcases {
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, suite.GatewayAddress, testcase)
}
})
},
}

View File

@@ -0,0 +1,70 @@
# Copyright (c) 2022 Alibaba Group Holding Ltd.
#
# 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.
apiVersion: networking.higress.io/v1
kind: Http2Rpc
metadata:
name: httproute-http2rpc-demo
namespace: higress-system
spec:
dubbo:
service: "com.dubbo.demo.api.DemoService"
version: "1.0.0"
methods:
- serviceMethod: "sayHello"
headersAttach: "*"
httpMethods:
- "GET"
- “POST”
httpPath: "/sayhello"
params:
- paramKey: "name"
paramSource: "QUERY"
paramType: "java.lang.String"
---
apiVersion: networking.higress.io/v1
kind: McpBridge
metadata:
name: default
namespace: higress-system
spec:
registries:
- domain: nacos-standlone-rc3-service
nacosGroups:
- DEFAULT_GROUP
name: nacos-service-resource
port: 8848
type: nacos
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
higress.io/destination: providers:com.dubbo.demo.api.DemoService:1.0.0:.DEFAULT-GROUP.public.nacos
higress.io/rpc-destination-name: httproute-http2rpc-demo
name: httproute-http2rpc-demo-ingress
namespace: higress-system
spec:
ingressClassName: higress
rules:
- host: "foo.com"
http:
paths:
- pathType: Prefix
path: /
backend:
resource:
apiGroup: networking.higress.io
kind: McpBridge
name: default

View File

@@ -59,6 +59,8 @@ type AssertionResponse struct {
// AdditionalResponseHeaders is a set of headers
// the echoserver should set in its response.
AdditionalResponseHeaders map[string]string
// set not need to judge response has request info
ExpectedResponseNoRequest bool
}
// Request can be used as both the request to make and a means to verify
@@ -263,7 +265,7 @@ func CompareRequest(req *roundtripper.Request, cReq *roundtripper.CapturedReques
if expected.Response.ExpectedResponse.StatusCode != cRes.StatusCode {
return fmt.Errorf("expected status code to be %d, got %d", expected.Response.ExpectedResponse.StatusCode, cRes.StatusCode)
}
if cRes.StatusCode == 200 {
if cRes.StatusCode == 200 && !expected.Response.ExpectedResponseNoRequest {
// The request expected to arrive at the backend is
// the same as the request made, unless otherwise
// specified.

View File

@@ -83,6 +83,7 @@ func TestHigressConformanceTests(t *testing.T) {
tests.HTTPRouteRequestHeaderControl,
tests.HTTPRouteDownstreamEncryption,
tests.HTTPRouteFullPathRegex,
tests.HTTPRouteHttp2Rpc,
}
}