Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -427,6 +427,9 @@ public List<String> getCheckpointList() {
}

private void deleteCheckpoint() {
if(checkTmpStore == null) {
return;
}
try {
Map<byte[], byte[]> hmap = new HashMap<>();
for (Map.Entry<byte[], byte[]> e : checkTmpStore.getDbSource()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static long parseFromBlockNumber(String blockNum) {
try {
number = Long.parseLong(blockNum);
} catch (Exception e) {
logger.error("invalid filter: fromBlockNumber: {}", blockNum);
throw e;
}
}
Expand All @@ -49,7 +48,6 @@ public static long parseToBlockNumber(String blockNum) {
try {
number = Long.parseLong(blockNum);
} catch (Exception e) {
logger.error("invalid filter: toBlockNumber: {}", blockNum);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
Expand All @@ -26,7 +25,6 @@
import org.tron.common.logsfilter.trigger.SolidityTrigger;
import org.tron.common.logsfilter.trigger.TransactionLogTrigger;
import org.tron.common.logsfilter.trigger.Trigger;
import org.tron.common.utils.JsonUtil;

@Slf4j
public class EventPluginLoader {
Expand Down Expand Up @@ -140,7 +138,7 @@ public static boolean matchFilter(ContractTrigger trigger) {

private static boolean filterContractAddress(ContractTrigger trigger, List<String> addressList) {
addressList = addressList.stream().filter(item ->
org.apache.commons.lang3.StringUtils.isNotEmpty(item))
org.apache.commons.lang3.StringUtils.isNotEmpty(item))
.collect(Collectors.toList());
if (Objects.isNull(addressList) || addressList.isEmpty()) {
return true;
Expand Down Expand Up @@ -173,7 +171,7 @@ private static boolean filterContractTopicList(ContractTrigger trigger, List<Str
hset = new HashSet<>(((ContractEventTrigger) trigger).getTopicMap().values());
} else if (trigger != null) {
hset = trigger.getLogInfo().getClonedTopics()
.stream().map(Hex::toHexString).collect(Collectors.toSet());
.stream().map(Hex::toHexString).collect(Collectors.toSet());
}

for (String top : topList) {
Expand Down Expand Up @@ -547,6 +545,9 @@ public boolean isBusy() {
return false;
}
int queueSize = 0;
if (eventListeners == null || eventListeners.isEmpty()) {
return false;
}
for (IPluginEventListener listener : eventListeners) {
try {
queueSize += listener.getPendingSize();
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ private static FilterQuery getEventFilter(final com.typesafe.config.Config confi
try {
fromBlockLong = FilterQuery.parseFromBlockNumber(fromBlock);
} catch (Exception e) {
logger.error("{}", e);
logger.error("invalid filter: fromBlockNumber: {}", fromBlock, e);
return null;
}
filter.setFromBlock(fromBlockLong);
Expand All @@ -1630,7 +1630,7 @@ private static FilterQuery getEventFilter(final com.typesafe.config.Config confi
try {
toBlockLong = FilterQuery.parseToBlockNumber(toBlock);
} catch (Exception e) {
logger.error("{}", e);
logger.error("invalid filter: toBlockNumber: {}", toBlock, e);
return null;
}
filter.setToBlock(toBlockLong);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.rules.Timeout;
import org.tron.common.backup.socket.BackupServer;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.PublicMethod;
import org.tron.core.Constant;
import org.tron.core.config.args.Args;

Expand All @@ -26,7 +27,7 @@ public class BackupServerTest {
@Before
public void setUp() throws Exception {
Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
CommonParameter.getInstance().setBackupPort(80);
CommonParameter.getInstance().setBackupPort(PublicMethod.chooseRandomPort());
List<String> members = new ArrayList<>();
members.add("127.0.0.2");
CommonParameter.getInstance().setBackupMembers(members);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ 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.assertTrue(subscriber.connect(String.format("tcp://localhost:%d", bindPort)));
Assert.assertTrue(subscriber.subscribe(topic));

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

Assert.assertEquals(true, triggerMsg.contains(dataToSend) || triggerMsg.contains(topic));
while (!Thread.currentThread().isInterrupted()) {
byte[] message = subscriber.recv();
String triggerMsg = new String(message);

Assert.assertTrue(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 @@ -4,7 +4,6 @@
import com.typesafe.config.ConfigFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand All @@ -28,12 +27,12 @@ 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) {
logger.error("load user defined config file exception: " + e.getMessage());
} catch (Exception e) {
logger.error("load user defined config file exception: {}", e.getMessage());
}
} else {
config = ConfigFactory.load(configurationPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,37 @@ 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
Comment thread
317787106 marked this conversation as resolved.
Outdated
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 @@ -23,6 +23,7 @@
public class BlockEventLoadTest {
BlockEventLoad blockEventLoad = new BlockEventLoad();

//ignore?
@Test
public void test() throws Exception {
Method method = blockEventLoad.getClass().getDeclaredMethod("load");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class HistoryEventServiceTest {

HistoryEventService historyEventService = new HistoryEventService();

//ignore?
@Test
public void test() throws Exception {
EventPluginLoader instance = mock(EventPluginLoader.class);
Expand All @@ -43,6 +44,7 @@ public void test() throws Exception {
RealtimeEventService realtimeEventService = new RealtimeEventService();
BlockEventLoad blockEventLoad = new BlockEventLoad();
ReflectUtils.setFieldValue(blockEventLoad, "instance", instance);
ReflectUtils.setFieldValue(blockEventLoad, "manager", manager);
Comment thread
317787106 marked this conversation as resolved.

ReflectUtils.setFieldValue(historyEventService, "solidEventService", solidEventService);
ReflectUtils.setFieldValue(historyEventService, "realtimeEventService", realtimeEventService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static int randomInt(int minInt, int maxInt) {
*/
@Test
public void testHandleBlockHash() {
int times = 200;
int times = 100;
Comment thread
317787106 marked this conversation as resolved.
int eachCount = 200;

Map<String, BlockFilterAndResult> conMap = TronJsonRpcImpl.getBlockFilter2ResultFull();
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
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
97 changes: 0 additions & 97 deletions framework/src/test/java/org/tron/core/net/BaseNet.java

This file was deleted.

16 changes: 0 additions & 16 deletions framework/src/test/java/org/tron/core/net/BaseNetTest.java

This file was deleted.

Loading