新增测试模块

This commit is contained in:
boyce
2019-09-23 14:38:44 +08:00
parent 6e1ccc9a36
commit 9623cd2735
11 changed files with 298 additions and 0 deletions

21
Test2/Helloworld/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "N_All",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/main.go",
"env": {
"GOPATH":"${workspaceRoot}/../../../../../../"
},
"args": ["NodeId=1"],
"output": "./OriginServer.exe"
}
]
}

View File

@@ -0,0 +1,3 @@
{
"go.gopath": "${workspaceRoot}/../../../../../"
}

View File

@@ -0,0 +1,34 @@
package main
import (
"fmt"
"github.com/duanhf2012/origin/cluster"
"github.com/duanhf2012/origin/originnode"
"github.com/duanhf2012/origin/service"
)
type SubNet1_Service struct {
service.BaseService
}
func init() {
originnode.InitService(&SubNet1_Service{})
}
//OnInit ...
func (ws *SubNet1_Service) OnInit() error {
return nil
}
//OnRun ...
func (ws *SubNet1_Service) OnRun() bool {
var in InputData
var ret int
in.A1 = 10
in.A2 = 20
err := cluster.Call("SubNet2_Service1.RPC_Multi", &in, &ret)
fmt.Printf("%+v", err)
return false
}

View File

@@ -0,0 +1,40 @@
package main
import (
"github.com/duanhf2012/origin/originnode"
"github.com/duanhf2012/origin/service"
)
type InputData struct {
A1 int
A2 int
}
type SubNet1_Service1 struct {
service.BaseService
}
func init() {
originnode.InitService(&SubNet1_Service1{})
}
//OnInit ...
func (ws *SubNet1_Service1) OnInit() error {
return nil
}
//OnRun ...
func (ws *SubNet1_Service1) OnRun() bool {
return false
}
//服务要对外的接口规划如下:
//RPC_MethodName(arg *DataType1, ret *DataType2) error
//如果不符合规范,在加载服务时,该函数将不会被映射,其他服务将不允能调用。
func (slf *SubNet1_Service1) RPC_Add(arg *InputData, ret *int) error {
*ret = arg.A1 + arg.A2
return nil
}

View File

@@ -0,0 +1,31 @@
package main
import (
"github.com/duanhf2012/origin/originnode"
"github.com/duanhf2012/origin/service"
)
type SubNet1_Service2 struct {
service.BaseService
}
func init() {
originnode.InitService(&SubNet1_Service2{})
}
//OnInit ...
func (ws *SubNet1_Service2) OnInit() error {
return nil
}
//OnRun ...
func (ws *SubNet1_Service2) OnRun() bool {
return false
}
func (slf *SubNet1_Service2) RPC_Sub(arg *InputData, ret *int) error {
*ret = arg.A1 - arg.A2
return nil
}

View File

@@ -0,0 +1,31 @@
package main
import (
"github.com/duanhf2012/origin/originnode"
"github.com/duanhf2012/origin/service"
)
type SubNet2_Service1 struct {
service.BaseService
}
func init() {
originnode.InitService(&SubNet2_Service1{})
}
//OnInit ...
func (ws *SubNet2_Service1) OnInit() error {
return nil
}
//OnRun ...
func (ws *SubNet2_Service1) OnRun() bool {
return false
}
func (slf *SubNet2_Service1) RPC_Multi(arg *InputData, ret *int) error {
*ret = arg.A1 * arg.A2
return nil
}

View File

@@ -0,0 +1,4 @@
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build -v

View File

@@ -0,0 +1,54 @@
{
"SubNet": [{
"Remark": "Manual,Full,Auto",
"SubNetMode": "Full",
"SubNetName": "SubNet1",
"PublicServiceList": ["logiclog"],
"NodeList": [{
"NodeID": 1,
"NodeName": "N_Node1",
"ServiceList": [
"HttpServerService",
"SubNet1_Service",
"SubNet1_Service1"
],
"ClusterNode":["SubNet2.N_Node1","N_Node2"]
},
{
"NodeID": 2,
"NodeName": "N_Node2",
"ServiceList": [
"SubNet1_Service2"
],
"ClusterNode":[]
}
]
},
{
"Remark": "Manual,Full,Auto",
"SubNetMode": "Full",
"SubNetName": "SubNet2",
"PublicServiceList": ["logiclog"],
"NodeList": [{
"NodeID": 3,
"NodeName": "N_Node1",
"ServiceList": [
"SubNet2_Service1"
],
"ClusterNode":["URQ.N_Node1"]
}
]
}
]
}

View File

@@ -0,0 +1,44 @@
{
"Public":{
"LogLevel":1,
"HttpPort":9400,
"WSPort":9500,
"CAFile":[
{
"CertFile":"",
"KeyFile":""
},
{
"CertFile":"",
"KeyFile":""
}
],
"Environment":"FS_Dev_LFY",
"IsListenLog":1,
"IsSendErrorMail":0
},
"NodeList":[
{
"NodeID":1,
"NodeAddr": "127.0.0.1:8081",
"LogLevel":1,
"HttpPort":7001,
"WSPort":7000,
"CertFile":"",
"KeyFile":""
},
{
"NodeID":2,
"NodeAddr": "127.0.0.1:8082"
}
,
{
"NodeID":3,
"NodeAddr": "127.0.0.1:8083"
}
]
}

26
Test2/Helloworld/main.go Normal file
View File

@@ -0,0 +1,26 @@
package main
import (
"github.com/duanhf2012/origin/cluster"
"github.com/duanhf2012/origin/originnode"
"github.com/duanhf2012/origin/sysservice"
)
func main() {
node := originnode.NewOriginNode()
if node == nil {
return
}
nodeCfg, _ := cluster.ReadNodeConfig("./config/nodeconfig.json", cluster.GetNodeId())
httpserver := sysservice.NewHttpServerService(nodeCfg.HttpPort) // http服务
for _, ca := range nodeCfg.CAFile {
httpserver.SetHttps(ca.CertFile, ca.KeyFile)
}
httpserver.SetPrintRequestTime(true)
node.SetupService(httpserver)
node.Init()
node.Start()
}

View File

@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"http.systemCertificates": false
}
}