Commit 696f9904 authored by xie.qin's avatar xie.qin

temp commit.

parent c99aaf01
......@@ -39,9 +39,9 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'io.qameta.allure:allure-okhttp3:2.14.0'
implementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.6'
implementation 'com.google.protobuf:protobuf-java:3.17.3'
implementation 'com.google.protobuf:protobuf-java-util:3.17.3'
implementation 'net.devh:grpc-client-spring-boot-starter:2.12.0.RELEASE'
//implementation 'com.google.protobuf:protobuf-java:3.17.3'
//implementation 'com.google.protobuf:protobuf-java-util:3.17.3'
implementation 'net.devh:grpc-client-spring-boot-starter:2.12.0.RELEASE' exclude group: 'io.grpc', module: 'grpc-netty-shaded'
compileOnly 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
......@@ -98,9 +98,28 @@ protobuf {
artifact = 'io.grpc:protoc-gen-grpc-java:1.39.0'
}
}
generatedFilesBaseDir = "$projectDir/src"
generatedFilesBaseDir = "$projectDir/src/generated"
clean {
delete protobuf.generatedFilesBaseDir
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
idea {
module {
sourceDirs += file('src/generated/main/java')
sourceDirs += file('src/generated/main/grpc')
generatedSourceDirs += file('src/generated/main/java')
generatedSourceDirs += file('src/generated/main/grpc')
}
}
package com.fuzamei.autotest.rpc.grpc;
import com.google.protobuf.RpcChannel;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.protobuf.RpcController;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;
import types.AccountManagerProto;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@Service
@Slf4j
public class AccountManagerClient {
@GrpcClient("chain33")
private AccountManagerProto.accountmanager.Stub stub;
public JsonNode sendMessageToRegister(String accountID) {
try{
RpcController rpcController = new
final AccountManagerProto.AccountReceipt response = this.stub.registerAccount(AccountManagerProto.Register.newBuilder().setAccountID(accountID).build());
}
AccountManagerProto.accountmanager.Stub stub = AccountManagerProto.accountmanager.newStub(chainChannel);
AccountManagerProto.AccountReceipt response = stub.registerAccount();
AccountManagerProto.Register.Builder accountManager = AccountManagerProto.Register.newBuilder();
accountManager.setAccountID(accountID);
AccountManagerProto.Register register = accountManager.build();
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
register.writeTo(output);
byte[] byteArray = output.toByteArray();
}
catch (IOException ex){
log.error("The request failed to send out as error: {}", ex);
assertThat("Test failed as exception happened.", false, equalTo(true));
}
}
}
package com.fuzamei.autotest.rpc.grpc;
import io.grpc.*;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GrpcClientLogInterceptor implements ClientInterceptor {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions, Channel next) {
log.info("now is calling gRPC method: {}", method.getFullMethodName());
return next.newCall(method, callOptions);
}
}
......@@ -3,7 +3,9 @@ syntax = "proto3";
import "transaction.proto";
package types;
option java_package = "com.fuzamei.autotest.rpc.proto";
//option java_package = "com.fuzamei.autotest.rpc.proto";
option java_outer_classname = "AccountManagerProto";
option java_generic_services = true;
message Accountmanager {
}
......@@ -150,5 +152,5 @@ message balance {
int64 frozen = 2;
}
service accountmanager {
rpc registerAccount(Register) returns(AccountReceipt){}
}
syntax = "proto3";
package types;
option java_package = "com.fuzamei.autotest.rpc.proto";
//option java_package = "com.fuzamei.autotest.rpc.proto";
option go_package = "github.com/33cn/chain33/types";
message Reply {
......
......@@ -3,7 +3,7 @@ syntax = "proto3";
import "common.proto";
package types;
option java_package = "com.fuzamei.autotest.rpc.proto";
//option java_package = "com.fuzamei.autotest.rpc.proto";
option go_package = "github.com/33cn/chain33/types";
// assert transfer struct
......
package com.fuzamei.autotest.steps.rpc;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fuzamei.autotest.properties.GlobalProperties;
import com.fuzamei.autotest.rpc.grpc.AccountManagerClient;
import io.cucumber.java.en.Then;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.File;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@Slf4j
public class GrpcRequestVerification {
@Autowired
private AccountManagerClient accountManagerClient;
@Autowired
private GlobalProperties globalProperties;
@Then("^Register an account in chain33 with dataNum (.*?) by (.*?) interface$")
public void registerAccountByRpcInterface(String dataNum, String rpcType) throws Throwable {
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode rootNode = objectMapper.readTree(new File(globalProperties.getTestdatapathintesting()));
JsonNode dataNode = rootNode.get(dataNum);
JsonNode reqDataNode = dataNode.get("request");
JsonNode expectedRespDataNode = dataNode.get("result");
JsonNode ActualResult = accountManagerClient.AccountManagerRegister(reqDataNode.get("accountID").asText());
assertThat("Test case failed.", ActualResult, equalTo(expectedRespDataNode));
}
catch (JsonProcessingException e){
log.error("parsing testing data error. the error is: {}", e);
e.printStackTrace();
}
}
}
......@@ -3,4 +3,4 @@ Feature: Account Management Contract Test
Scenario: Account registration by RPC interface
Given The testing RUNTIME data intelligent_contract.accountManager is ready
Then Create account in chain33 with dataNum accountManager.001 by gRPC interface
\ No newline at end of file
Then Register an account in chain33 with dataNum accountManager.001 by gRPC interface
\ No newline at end of file
{
"accountManager.001": {
"accountID": "stringstring"
"request": {
"accountID": "stringstring"
},
"result": {
"type": "boolean",
"value": true
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment