Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ public void publishTrigger() {

public void startSubscribeThread() {
Thread thread = new Thread(() -> {
ZContext context = new ZContext();
ZMQ.Socket subscriber = context.createSocket(SocketType.SUB);
try (ZContext context = new ZContext()) {
ZMQ.Socket subscriber = context.createSocket(SocketType.SUB);

Assert.assertEquals(true, subscriber.connect(String.format("tcp://localhost:%d", bindPort)));
Assert.assertEquals(true, subscriber.subscribe(topic));
Assert.assertEquals(true, subscriber.connect(String.format("tcp://localhost:%d", bindPort)));
Assert.assertEquals(true, subscriber.subscribe(topic));

while (!Thread.currentThread().isInterrupted()) {
byte[] message = subscriber.recv();
String triggerMsg = new String(message);
while (!Thread.currentThread().isInterrupted()) {
byte[] message = subscriber.recv();
String triggerMsg = new String(message);

Assert.assertEquals(true, triggerMsg.contains(dataToSend) || triggerMsg.contains(topic));
Assert.assertEquals(true, triggerMsg.contains(dataToSend) || triggerMsg.contains(topic));

}
// ZMQ.Socket will be automatically closed when ZContext is closed
}
});
thread.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public static Config getByPath(final String configurationPath) {
if (config == null) {
File configFile = new File(System.getProperty("user.dir") + '/' + configurationPath);
if (configFile.exists()) {
try {
config = ConfigFactory
.parseReader(new InputStreamReader(new FileInputStream(configurationPath)));
try (FileInputStream fis = new FileInputStream(configurationPath);
InputStreamReader isr = new InputStreamReader(fis)) {
config = ConfigFactory.parseReader(isr);
logger.info("use user defined config file in current dir");
} catch (FileNotFoundException e) {
} catch (Exception e) {
logger.error("load user defined config file exception: " + e.getMessage());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,35 @@ public class CreateCommonTransactionTest {
* for example create UpdateBrokerageContract
*/
public static void testCreateUpdateBrokerageContract() {
WalletBlockingStub walletStub = WalletGrpc
.newBlockingStub(ManagedChannelBuilder.forTarget(FULL_NODE).usePlaintext().build());
UpdateBrokerageContract.Builder updateBrokerageContract = UpdateBrokerageContract.newBuilder();
updateBrokerageContract.setOwnerAddress(
ByteString.copyFrom(decodeFromBase58Check("TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz")))
.setBrokerage(10);
Transaction.Builder transaction = Transaction.newBuilder();
raw.Builder raw = Transaction.raw.newBuilder();
Contract.Builder contract = Contract.newBuilder();
contract.setType(ContractType.UpdateBrokerageContract)
.setParameter(Any.pack(updateBrokerageContract.build()));
raw.addContract(contract.build());
transaction.setRawData(raw.build());
TransactionExtention transactionExtention = walletStub
.createCommonTransaction(transaction.build());
System.out.println("Common UpdateBrokerage: " + transactionExtention);
io.grpc.ManagedChannel channel = ManagedChannelBuilder.forTarget(FULL_NODE).usePlaintext().build();
try {
WalletBlockingStub walletStub = WalletGrpc.newBlockingStub(channel);
UpdateBrokerageContract.Builder updateBrokerageContract = UpdateBrokerageContract.newBuilder();
updateBrokerageContract.setOwnerAddress(
ByteString.copyFrom(decodeFromBase58Check("TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz")))
.setBrokerage(10);
Transaction.Builder transaction = Transaction.newBuilder();
raw.Builder raw = Transaction.raw.newBuilder();
Contract.Builder contract = Contract.newBuilder();
contract.setType(ContractType.UpdateBrokerageContract)
.setParameter(Any.pack(updateBrokerageContract.build()));
raw.addContract(contract.build());
transaction.setRawData(raw.build());
TransactionExtention transactionExtention = walletStub
.createCommonTransaction(transaction.build());
System.out.println("Common UpdateBrokerage: " + transactionExtention);
} finally {
// Properly shutdown the gRPC channel to prevent resource leaks
channel.shutdown();
try {
if (!channel.awaitTermination(5, java.util.concurrent.TimeUnit.SECONDS)) {
channel.shutdownNow();
}
} catch (InterruptedException e) {
channel.shutdownNow();
Thread.currentThread().interrupt();
}
}
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Resource;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -49,6 +50,13 @@ public void setup() throws Exception {
sectionBloomStore.put(1, 3, bitSet2);
}

@After
public void tearDown() {
if (sectionExecutor != null && !sectionExecutor.isShutdown()) {
sectionExecutor.shutdown();
}
}

@Test
public void testPartialMatch() throws Exception {
// Create a basic LogFilterWrapper
Expand Down Expand Up @@ -97,4 +105,4 @@ public void testPartialMatch() throws Exception {
Assert.assertNotNull(result);
Assert.assertTrue(result.isEmpty());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public void testWriteAndQuery() {
Assert.assertTrue(possibleBlockList.contains(10000L));
} catch (Exception e) {
Assert.fail();
} finally {
sectionExecutor.shutdown();
}

//query multi address
Expand Down
3 changes: 3 additions & 0 deletions framework/src/test/java/org/tron/core/net/BaseNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public static void destroy() {
peer.getChannel().close();
}
}
if (executorService != null && !executorService.isShutdown()) {
executorService.shutdown();
}
Args.clearParam();
context.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,6 @@ public DelegationServiceTest(TronApplicationContext context) {
manager = context.getBean(Manager.class);
}

public static void testGrpc() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted as no usage anymore, and this method has grpc leakage.

WalletBlockingStub walletStub = WalletGrpc
.newBlockingStub(ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext()
.build());
BytesMessage.Builder builder = BytesMessage.newBuilder();
builder.setValue(ByteString.copyFromUtf8("TLTDZBcPoJ8tZ6TTEeEqEvwYFk2wgotSfD"));
System.out
.println("getBrokerageInfo: " + walletStub.getBrokerageInfo(builder.build()).getNum());
System.out.println("getRewardInfo: " + walletStub.getRewardInfo(builder.build()).getNum());
UpdateBrokerageContract.Builder updateBrokerageContract = UpdateBrokerageContract.newBuilder();
updateBrokerageContract.setOwnerAddress(
ByteString.copyFrom(decodeFromBase58Check("TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz")))
.setBrokerage(10);
TransactionExtention transactionExtention = walletStub
.updateBrokerage(updateBrokerageContract.build());
System.out.println("UpdateBrokerage: " + transactionExtention);
}

private void testPay(int cycle) {
double rate = 0.2;
if (cycle == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RpcApiServicesTest {
private static TronApplicationContext context;
private static ManagedChannel channelFull = null;
private static ManagedChannel channelPBFT = null;
private static ManagedChannel channelSolidity = null;
private static DatabaseBlockingStub databaseBlockingStubFull = null;
private static DatabaseBlockingStub databaseBlockingStubSolidity = null;
private static DatabaseBlockingStub databaseBlockingStubPBFT = null;
Expand Down Expand Up @@ -152,13 +155,13 @@ public static void init() throws IOException {
String pBFTNode = String.format("%s:%d", Constant.LOCAL_HOST,
getInstance().getRpcOnPBFTPort());

ManagedChannel channelFull = ManagedChannelBuilder.forTarget(fullNode)
channelFull = ManagedChannelBuilder.forTarget(fullNode)
.usePlaintext()
.build();
ManagedChannel channelPBFT = ManagedChannelBuilder.forTarget(pBFTNode)
channelPBFT = ManagedChannelBuilder.forTarget(pBFTNode)
.usePlaintext()
.build();
ManagedChannel channelSolidity = ManagedChannelBuilder.forTarget(solidityNode)
channelSolidity = ManagedChannelBuilder.forTarget(solidityNode)
.usePlaintext()
.build();
context = new TronApplicationContext(DefaultConfig.class);
Expand All @@ -183,6 +186,15 @@ public static void init() throws IOException {

@AfterClass
public static void destroy() {
if (channelFull != null) {
channelFull.shutdown();
}
if (channelPBFT != null) {
channelPBFT.shutdown();
}
if (channelSolidity != null) {
channelSolidity.shutdown();
}
context.close();
Args.clearParam();
}
Expand Down
25 changes: 19 additions & 6 deletions framework/src/test/java/org/tron/core/services/WalletApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,25 @@ public static void init() throws IOException {
public void listNodesTest() {
String fullNode = String.format("%s:%d", "127.0.0.1",
Args.getInstance().getRpcPort());
WalletGrpc.WalletBlockingStub walletStub = WalletGrpc
.newBlockingStub(ManagedChannelBuilder.forTarget(fullNode)
.usePlaintext()
.build());
Assert.assertTrue(walletStub.listNodes(EmptyMessage.getDefaultInstance())
.getNodesList().isEmpty());
io.grpc.ManagedChannel channel = ManagedChannelBuilder.forTarget(fullNode)
.usePlaintext()
.build();
try {
WalletGrpc.WalletBlockingStub walletStub = WalletGrpc.newBlockingStub(channel);
Assert.assertTrue(walletStub.listNodes(EmptyMessage.getDefaultInstance())
.getNodesList().isEmpty());
} finally {
// Properly shutdown the gRPC channel to prevent resource leaks
channel.shutdown();
try {
if (!channel.awaitTermination(5, java.util.concurrent.TimeUnit.SECONDS)) {
channel.shutdownNow();
}
} catch (InterruptedException e) {
channel.shutdownNow();
Thread.currentThread().interrupt();
}
}
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
public class RpcApiAccessInterceptorTest {

private static TronApplicationContext context;
private static ManagedChannel channelFull = null;
private static ManagedChannel channelPBFT = null;
private static ManagedChannel channelSolidity = null;
private static WalletGrpc.WalletBlockingStub blockingStubFull = null;
private static WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
private static WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPBFT = null;
Expand All @@ -68,13 +71,13 @@ public static void init() throws IOException {
String pBFTNode = String.format("%s:%d", Constant.LOCAL_HOST,
Args.getInstance().getRpcOnPBFTPort());

ManagedChannel channelFull = ManagedChannelBuilder.forTarget(fullNode)
channelFull = ManagedChannelBuilder.forTarget(fullNode)
.usePlaintext()
.build();
ManagedChannel channelPBFT = ManagedChannelBuilder.forTarget(pBFTNode)
channelPBFT = ManagedChannelBuilder.forTarget(pBFTNode)
.usePlaintext()
.build();
ManagedChannel channelSolidity = ManagedChannelBuilder.forTarget(solidityNode)
channelSolidity = ManagedChannelBuilder.forTarget(solidityNode)
.usePlaintext()
.build();

Expand All @@ -93,6 +96,15 @@ public static void init() throws IOException {
*/
@AfterClass
public static void destroy() {
if (channelFull != null) {
channelFull.shutdown();
}
if (channelPBFT != null) {
channelPBFT.shutdown();
}
if (channelSolidity != null) {
channelSolidity.shutdown();
}
context.close();
Args.clearParam();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public void calBenchmarkSpendConcurrent() throws Exception {

countDownLatch.await();

generatePool.shutdown();
logger.info("generate cost time:" + (System.currentTimeMillis() - startGenerate));
}

Expand Down