use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class TestBase method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
System.out.println("EncryptType => " + EncryptType.getEncryptType());
web3j = Web3j.build(channelEthereumService, service.getGroupId());
credentials = GenCredential.create();
Ok ok = Ok.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send();
blockNumber = ok.getTransactionReceipt().get().getBlockNumber();
blockHash = ok.getTransactionReceipt().get().getBlockHash();
txHash = ok.getTransactionReceipt().get().getTransactionHash();
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class Channel2ClientMultiNeedVerify method main.
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);
}
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class Channel2Client method main.
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("===================================================================");
ChannelRequest request = new ChannelRequest();
for (Integer i = 0; i < count; ++i) {
Thread.sleep(2000);
request.setToTopic(topic);
request.setMessageID(service.newSeq());
request.setTimeout(5000);
String content = "request seq:" + request.getMessageID();
request.setContent(content.getBytes());
System.out.println(df.format(LocalDateTime.now()) + " request seq:" + request.getMessageID() + ", Content:" + request.getContent() + " content:" + Arrays.toString(request.getContentByteArray()));
ChannelResponse response = service.sendChannelMessage2(request);
System.out.println(df.format(LocalDateTime.now()) + "response seq:" + response.getMessageID() + ", ErrorCode:" + response.getErrorCode() + ", Content:" + response.getContent());
}
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class Channel2ClientBinNeedVerify method main.
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());
if (response.getErrorCode() != 0) {
System.out.println("Error message" + response.getErrorMessage());
}
}
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class PerfomanceTableRemove method main.
public static void main(String[] args) throws Exception {
try {
String groupId = args[3];
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.setGroupId(Integer.parseInt(groupId));
service.run();
System.out.println("Start test...");
System.out.println("===================================================================");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
Credentials credentials = Credentials.create("b83261efa42895c38c6c2364ca878f43e77f3cddbc922bf57d0d48070f79feb6");
BigInteger gasPrice = new BigInteger("30000000");
BigInteger gasLimit = new BigInteger("30000000");
String command = args[0];
Integer count = 0;
Integer qps = 0;
switch(command) {
case "trans":
count = Integer.parseInt(args[1]);
qps = Integer.parseInt(args[2]);
break;
default:
System.out.println("Args: <trans> <Total> <QPS>");
}
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(200);
threadPool.setMaxPoolSize(500);
threadPool.setQueueCapacity(count);
threadPool.initialize();
System.out.println("Deploying contract...");
TableTest tabletest = TableTest.deploy(web3, credentials, gasPrice, gasLimit).send();
PerfomanceCollector collector = new PerfomanceCollector();
collector.setTotal(count);
RateLimiter limiter = RateLimiter.create(qps);
Integer area = count / 10;
final Integer total = count;
Random random = new Random(System.currentTimeMillis());
System.out.println("Start test,total:" + count);
for (Integer i = 0; i < count; ++i) {
threadPool.execute(new Runnable() {
@Override
public void run() {
limiter.acquire();
PerfomanceTableTestCallback callback = new PerfomanceTableTestCallback();
callback.setCollector(collector);
try {
long _id = getNextID();
Random r = new Random();
long l1 = r.nextLong();
tabletest.remove("fruit" + l1 % TableTestClient.modevalue, BigInteger.valueOf(_id), callback);
} catch (Exception e) {
TransactionReceipt receipt = new TransactionReceipt();
receipt.setStatus("-1");
callback.onResponse(receipt);
logger.error("Error sending:", e);
}
int current = sended.incrementAndGet();
if (current >= area && ((current % area) == 0)) {
System.out.println("Already sended: " + current + "/" + total + " transactions");
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
Aggregations