-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add multibroadcast and binary send test function (#391)
* update config file * update config file fro rerun * add multibroadcast and binary send test function
- Loading branch information
1 parent
cfccba1
commit 891e3f3
Showing
5 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/test/java/org/fisco/bcos/channel/test/amop/Channel2ClientBinNeedVerify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.fisco.bcos.channel.test.amop; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import org.fisco.bcos.channel.client.Service; | ||
import org.fisco.bcos.channel.dto.ChannelRequest; | ||
import org.fisco.bcos.channel.dto.ChannelResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class Channel2ClientBinNeedVerify { | ||
private static Logger logger = LoggerFactory.getLogger(Channel2ClientBinNeedVerify.class); | ||
|
||
public static byte[] toByteArrFromFile(String path) throws Exception { | ||
File inFile = new File(path); | ||
FileInputStream fileInputStream = new FileInputStream(inFile); | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
int i; | ||
while ((i = fileInputStream.read()) != -1) { | ||
byteArrayOutputStream.write(i); | ||
} | ||
fileInputStream.close(); | ||
byte[] bytes = byteArrayOutputStream.toByteArray(); | ||
byteArrayOutputStream.close(); | ||
return bytes; | ||
} | ||
|
||
public static byte[] intToByteArray(int i) { | ||
byte[] result = new byte[4]; | ||
result[0] = (byte) ((i >> 24) & 0xFF); | ||
result[1] = (byte) ((i >> 16) & 0xFF); | ||
result[2] = (byte) ((i >> 8) & 0xFF); | ||
result[3] = (byte) (i & 0xFF); | ||
return result; | ||
} | ||
|
||
public static byte[] byteCat(byte[] data1, byte[] data2) { | ||
byte[] data3 = new byte[data1.length + data2.length]; | ||
System.arraycopy(data1, 0, data3, 0, data1.length); | ||
System.arraycopy(data2, 0, data3, data1.length, data2.length); | ||
return data3; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (args.length < 2) { | ||
System.out.println("param: target topic filename of request"); | ||
return; | ||
} | ||
String topic = args[0]; | ||
String filename = args[1]; | ||
Integer count = 10; | ||
|
||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
logger.debug("init client"); | ||
|
||
ApplicationContext context = | ||
new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); | ||
|
||
Service service = context.getBean(Service.class); | ||
service.run(); | ||
|
||
System.out.println("3s ..."); | ||
Thread.sleep(1000); | ||
System.out.println("2s ..."); | ||
Thread.sleep(1000); | ||
System.out.println("1s ..."); | ||
Thread.sleep(1000); | ||
|
||
System.out.println("start test"); | ||
System.out.println("==================================================================="); | ||
|
||
for (Integer i = 0; i < count; ++i) { | ||
Thread.sleep(2000); | ||
ChannelRequest request = new ChannelRequest(); | ||
request.setToTopic(topic); | ||
request.setMessageID(service.newSeq()); | ||
request.setTimeout(5000); | ||
|
||
/*设置为-128表示为传输二进制*/ | ||
int flag = -128; | ||
byte[] byteflag = intToByteArray(flag); | ||
int filelength = filename.length(); | ||
byte[] bytelength = intToByteArray(filelength); | ||
byte[] bytefilename = filename.getBytes(); | ||
byte[] contentfile = toByteArrFromFile(filename); | ||
byte[] content = | ||
byteCat(byteCat(byteCat(byteflag, bytelength), bytefilename), contentfile); | ||
request.setContent(content); | ||
|
||
logger.info("msg:" + Arrays.toString(content)); | ||
|
||
System.out.println( | ||
df.format(LocalDateTime.now()) | ||
+ " request seq:" | ||
+ String.valueOf(request.getMessageID()) | ||
+ " content length:" | ||
+ content.length); | ||
|
||
ChannelResponse response = service.sendChannelMessageForVerifyTopic(request); | ||
|
||
System.out.println( | ||
df.format(LocalDateTime.now()) | ||
+ "response seq:" | ||
+ String.valueOf(response.getMessageID()) | ||
+ ", ErrorCode:" | ||
+ response.getErrorCode() | ||
+ ", Content:" | ||
+ response.getContent()); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/test/java/org/fisco/bcos/channel/test/amop/Channel2ClientMultiBinNeedVerify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.fisco.bcos.channel.test.amop; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import org.fisco.bcos.channel.client.Service; | ||
import org.fisco.bcos.channel.dto.ChannelRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class Channel2ClientMultiBinNeedVerify { | ||
private static Logger logger = LoggerFactory.getLogger(Channel2ClientMulti.class); | ||
private static final int parameterNum = 2; | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (args.length < parameterNum) { | ||
System.out.println("param: target topic total number of request"); | ||
return; | ||
} | ||
String topic = args[0]; | ||
Integer count = 10; | ||
String filename = args[1]; | ||
|
||
int flag = -128; | ||
byte[] byteflag = Channel2ClientBin.intToByteArray(flag); | ||
int filelength = filename.length(); | ||
byte[] bytelength = Channel2ClientBin.intToByteArray(filelength); | ||
byte[] bytefilename = filename.getBytes(); | ||
byte[] contentfile = Channel2ClientBin.toByteArrFromFile(filename); | ||
byte[] content = | ||
Channel2ClientBin.byteCat( | ||
Channel2ClientBin.byteCat( | ||
Channel2ClientBin.byteCat(byteflag, bytelength), bytefilename), | ||
contentfile); | ||
|
||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
logger.debug("init client"); | ||
|
||
ApplicationContext context = | ||
new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); | ||
|
||
Service service = context.getBean(Service.class); | ||
service.run(); | ||
|
||
System.out.println("3s ..."); | ||
Thread.sleep(1000); | ||
System.out.println("2s ..."); | ||
Thread.sleep(1000); | ||
System.out.println("1s ..."); | ||
Thread.sleep(1000); | ||
|
||
System.out.println("start test"); | ||
System.out.println("==================================================================="); | ||
|
||
for (Integer i = 0; i < count; ++i) { | ||
Thread.sleep(2000); | ||
ChannelRequest request = new ChannelRequest(); | ||
request.setToTopic(topic); | ||
request.setMessageID(service.newSeq()); | ||
request.setTimeout(5000); | ||
request.setContent(content); | ||
|
||
System.out.println( | ||
df.format(LocalDateTime.now()) | ||
+ " multicast request seq:" | ||
+ String.valueOf(request.getMessageID()) | ||
+ ", filename:" | ||
+ filename); | ||
service.asyncMulticastChannelMessageForVerifyTopic(request); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/org/fisco/bcos/channel/test/amop/Channel2ClientMultiNeedVerify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.fisco.bcos.channel.test.amop; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import org.fisco.bcos.channel.client.Service; | ||
import org.fisco.bcos.channel.dto.ChannelRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class Channel2ClientMultiNeedVerify { | ||
private static Logger logger = LoggerFactory.getLogger(Channel2ClientMultiNeedVerify.class); | ||
private static final int parameterNum = 2; | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (args.length < parameterNum) { | ||
System.out.println("param: target topic total number of request"); | ||
return; | ||
} | ||
String topic = args[0]; | ||
Integer count = Integer.parseInt(args[1]); | ||
|
||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
logger.debug("init client"); | ||
|
||
ApplicationContext context = | ||
new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); | ||
|
||
Service service = context.getBean(Service.class); | ||
service.run(); | ||
|
||
System.out.println("3s ..."); | ||
Thread.sleep(1000); | ||
System.out.println("2s ..."); | ||
Thread.sleep(1000); | ||
System.out.println("1s ..."); | ||
Thread.sleep(1000); | ||
|
||
System.out.println("start test"); | ||
System.out.println("==================================================================="); | ||
|
||
for (Integer i = 0; i < count; ++i) { | ||
Thread.sleep(2000); | ||
ChannelRequest request = new ChannelRequest(); | ||
request.setToTopic(topic); | ||
request.setMessageID(service.newSeq()); | ||
request.setTimeout(5000); | ||
|
||
request.setContent("request seq:" + request.getMessageID()); | ||
|
||
System.out.println( | ||
df.format(LocalDateTime.now()) | ||
+ " multicast request seq:" | ||
+ String.valueOf(request.getMessageID()) | ||
+ ", Content:" | ||
+ request.getContent()); | ||
|
||
service.asyncMulticastChannelMessageForVerifyTopic(request); | ||
} | ||
} | ||
} |