fix:主备切换

This commit is contained in:
waner
2025-06-04 10:13:37 +08:00
parent fbcbe79388
commit e4020b1bbc
4 changed files with 276 additions and 303 deletions
+58 -7
View File
@@ -15,6 +15,7 @@ import racal.sunyard.main.SydApi4j;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.concurrent.*;
import static com.sunyard.util.CertUtil.convertToX509Cert;
@@ -22,19 +23,19 @@ public class Test4NongxinCW {
private SydApi4j api;
final String SM2dn = "C=CN,ST=zz,L=zz,O=zzz,CN=zzzzz";
final String SM2dn = "1C=CN,ST=zz,L=zz,O=zzz,CN=zzzzz";
byte[] orgData = new byte[100];
@Before
public void before() {
//主备调用接口
SydApi4j.SYD_Set_Parameter_HA("172.1.41.139", "172.1.41.96", 8889, 1000);
SydApi4j.SYD_Set_Parameter_HA("172.1.41.96", "172.1.41.139", 8889, 1000);
api = (SydApi4j) new SydApi4j();
api.startHeartbeat();
// api.startHeartbeat();
// 通过设置debug的属性开启debug,如果不设置则默认不打开
api = (SydApi4j) new SydApi4j().connect("172.1.41.139", 8891, null, 1000);
// api = (SydApi4j) new SydApi4j().connect("172.1.41.139", 8891, null, 1000);
}
@@ -52,6 +53,56 @@ public class Test4NongxinCW {
}
}
@Test
public void testHA() {
for (int i = 0; i < 10000; i++) {
byte[] nakedSign = api.SYD_NakedSign(orgData,SM2dn);
}
}
@Test
public void tes() throws InterruptedException, ExecutionException {
// 配置HA参数
// SydApi4j.SYD_Set_Parameter_HA("172.1.41.139", "172.1.41.96", 8889, 1000);
// 创建20个线程并发操作API
ExecutorService executor = Executors.newFixedThreadPool(20);
List<Future<?>> futures = new ArrayList<>();
// 模拟主节点故障
CountDownLatch startLatch = new CountDownLatch(1);
for (int i = 0; i < 20; i++) {
futures.add(executor.submit(() -> {
try {
startLatch.await(); // 等待统一开始
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
SydApi4j api2 = new SydApi4j();
for (int j = 0; j < 10000; j++) {
byte[] nakedSign = api2.SYD_NakedSign(orgData,SM2dn);
}
}));
}
// 触发所有线程开始
startLatch.countDown();
// 随机触发主节点故障(模拟网络中断)
Thread.sleep(500);
// 等待所有任务完成
for (Future<?> future : futures) {
future.get();
}
executor.shutdown();
}
@Test
public void nakeSign(){
@@ -293,9 +344,9 @@ public class Test4NongxinCW {
@Test
public void selectCert() throws Exception {
// String SM2dn1 = "C=CN,ST=1,L=1,O=1,OU=1,OU=1,CN=1";
// String s = api.getCertByDn(SM2dn);
// System.out.println(s);
String SM2dn1 = "C=CN,ST=1,L=1,O=1,OU=1,OU=1,CN=1";
String s = api.getCertByDn(SM2dn);
System.out.println(s);
String message = "sdas发顺丰";
byte[] gbkBytes = message.getBytes("GBK");
System.out.println("GBK Encoded Bytes: " + Arrays.toString(gbkBytes));