@@ -169,7 +169,9 @@ public class PeerServerBooter { | |||||
app.addInitializers((ApplicationContextInitializer<ConfigurableApplicationContext>) applicationContext -> { | app.addInitializers((ApplicationContextInitializer<ConfigurableApplicationContext>) applicationContext -> { | ||||
ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); | ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); | ||||
for (Object bean : externalBeans) { | for (Object bean : externalBeans) { | ||||
beanFactory.registerSingleton(bean.toString(), bean); | |||||
if (bean != null) { | |||||
beanFactory.registerSingleton(bean.toString(), bean); | |||||
} | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
@@ -6,7 +6,9 @@ import java.util.Map; | |||||
import com.jd.blockchain.consensus.ConsensusSettings; | import com.jd.blockchain.consensus.ConsensusSettings; | ||||
import com.jd.blockchain.crypto.AsymmetricKeypair; | import com.jd.blockchain.crypto.AsymmetricKeypair; | ||||
import com.jd.blockchain.crypto.HashDigest; | |||||
import com.jd.blockchain.ledger.core.LedgerManager; | import com.jd.blockchain.ledger.core.LedgerManager; | ||||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||||
import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | ||||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | ||||
@@ -44,7 +46,7 @@ public class IntegratedContext { | |||||
private LedgerManager ledgerManager; | private LedgerManager ledgerManager; | ||||
private CompositeConnectionFactory storageDB; | |||||
private DbConnectionFactory storageDB; | |||||
private LedgerBindingConfig bindingConfig; | private LedgerBindingConfig bindingConfig; | ||||
@@ -60,7 +62,7 @@ public class IntegratedContext { | |||||
return ledgerManager; | return ledgerManager; | ||||
} | } | ||||
public CompositeConnectionFactory getStorageDB() { | |||||
public DbConnectionFactory getStorageDB() { | |||||
return storageDB; | return storageDB; | ||||
} | } | ||||
@@ -84,7 +86,7 @@ public class IntegratedContext { | |||||
this.ledgerManager = ledgerManager; | this.ledgerManager = ledgerManager; | ||||
} | } | ||||
public void setStorageDB(CompositeConnectionFactory storageDB) { | |||||
public void setStorageDB(DbConnectionFactory storageDB) { | |||||
this.storageDB = storageDB; | this.storageDB = storageDB; | ||||
} | } | ||||
@@ -8,6 +8,9 @@ import java.util.Properties; | |||||
import java.util.Random; | import java.util.Random; | ||||
import java.util.concurrent.CountDownLatch; | import java.util.concurrent.CountDownLatch; | ||||
import com.jd.blockchain.ledger.*; | |||||
import com.jd.blockchain.storage.service.impl.composite.CompositeConnectionFactory; | |||||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||||
import org.springframework.core.io.ClassPathResource; | import org.springframework.core.io.ClassPathResource; | ||||
import com.jd.blockchain.consensus.ConsensusProvider; | import com.jd.blockchain.consensus.ConsensusProvider; | ||||
@@ -21,20 +24,6 @@ import com.jd.blockchain.crypto.KeyGenUtils; | |||||
import com.jd.blockchain.crypto.PrivKey; | import com.jd.blockchain.crypto.PrivKey; | ||||
import com.jd.blockchain.crypto.PubKey; | import com.jd.blockchain.crypto.PubKey; | ||||
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig; | ||||
import com.jd.blockchain.ledger.BlockchainIdentity; | |||||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||||
import com.jd.blockchain.ledger.BytesValue; | |||||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||||
import com.jd.blockchain.ledger.TypedKVEntry; | |||||
import com.jd.blockchain.ledger.LedgerBlock; | |||||
import com.jd.blockchain.ledger.LedgerInfo; | |||||
import com.jd.blockchain.ledger.LedgerInitProperties; | |||||
import com.jd.blockchain.ledger.ParticipantNode; | |||||
import com.jd.blockchain.ledger.PreparedTransaction; | |||||
import com.jd.blockchain.ledger.TransactionResponse; | |||||
import com.jd.blockchain.ledger.TransactionTemplate; | |||||
import com.jd.blockchain.ledger.UserInfo; | |||||
import com.jd.blockchain.ledger.core.DataAccountQuery; | import com.jd.blockchain.ledger.core.DataAccountQuery; | ||||
import com.jd.blockchain.ledger.core.LedgerManage; | import com.jd.blockchain.ledger.core.LedgerManage; | ||||
import com.jd.blockchain.ledger.core.LedgerManager; | import com.jd.blockchain.ledger.core.LedgerManager; | ||||
@@ -73,16 +62,10 @@ public class IntegrationTest { | |||||
private static String memDbConnString = LedgerInitConsensusConfig.memConnectionStrings[0]; | private static String memDbConnString = LedgerInitConsensusConfig.memConnectionStrings[0]; | ||||
// private static final MQConnectionConfig mqConnConfig = new | |||||
// MQConnectionConfig(); | |||||
// static { | |||||
// mqConnConfig.setServer(MQ_SERVER); | |||||
// mqConnConfig.setTopic(MQ_TOPIC); | |||||
// } | |||||
public static void main_(String[] args) { | |||||
public static void main(String[] args) { | |||||
// init ledgers of all nodes ; | // init ledgers of all nodes ; | ||||
IntegratedContext context = initLedgers(); | IntegratedContext context = initLedgers(); | ||||
Node node0 = context.getNode(0); | Node node0 = context.getNode(0); | ||||
Node node1 = context.getNode(1); | Node node1 = context.getNode(1); | ||||
Node node2 = context.getNode(2); | Node node2 = context.getNode(2); | ||||
@@ -100,10 +83,10 @@ public class IntegrationTest { | |||||
NetworkAddress peerSrvAddr3 = new NetworkAddress("127.0.0.1", 10230); | NetworkAddress peerSrvAddr3 = new NetworkAddress("127.0.0.1", 10230); | ||||
PeerTestRunner peer3 = new PeerTestRunner(peerSrvAddr3, node3.getBindingConfig(), node3.getStorageDB()); | PeerTestRunner peer3 = new PeerTestRunner(peerSrvAddr3, node3.getBindingConfig(), node3.getStorageDB()); | ||||
AsyncCallback<Object> peerStarting0 = peer0.start(); | |||||
AsyncCallback<Object> peerStarting1 = peer1.start(); | |||||
AsyncCallback<Object> peerStarting2 = peer2.start(); | |||||
AsyncCallback<Object> peerStarting3 = peer3.start(); | |||||
ThreadInvoker.AsyncCallback<Object> peerStarting0 = peer0.start(); | |||||
ThreadInvoker.AsyncCallback<Object> peerStarting1 = peer1.start(); | |||||
ThreadInvoker.AsyncCallback<Object> peerStarting2 = peer2.start(); | |||||
ThreadInvoker.AsyncCallback<Object> peerStarting3 = peer3.start(); | |||||
peerStarting0.waitReturn(); | peerStarting0.waitReturn(); | ||||
peerStarting1.waitReturn(); | peerStarting1.waitReturn(); | ||||
@@ -116,30 +99,24 @@ public class IntegrationTest { | |||||
gwkey0.setPubKeyValue(LedgerInitializeWebTest.PUB_KEYS[0]); | gwkey0.setPubKeyValue(LedgerInitializeWebTest.PUB_KEYS[0]); | ||||
gwkey0.setPrivKeyValue(LedgerInitializeWebTest.PRIV_KEYS[0]); | gwkey0.setPrivKeyValue(LedgerInitializeWebTest.PRIV_KEYS[0]); | ||||
gwkey0.setPrivKeyPassword(encodedBase58Pwd); | gwkey0.setPrivKeyPassword(encodedBase58Pwd); | ||||
// GatewayTestRunner gateway0 = new GatewayTestRunner("127.0.0.1", 10300, | |||||
// gwkey0, peerSrvAddr0); | |||||
GatewayTestRunner gateway0 = new GatewayTestRunner("127.0.0.1", 10300, gwkey0, peerSrvAddr0); | |||||
// KeyPairConfig gwkey1 = new KeyPairConfig(); | |||||
// gwkey1.setPubKeyValue(LedgerInitializeWebTest.PUB_KEYS[1]); | |||||
// gwkey1.setPrivKeyValue(LedgerInitializeWebTest.PRIV_KEYS[1]); | |||||
// gwkey1.setPrivKeyPassword(encodedBase58Pwd); | |||||
// GatewayTestRunner gateway1 = new GatewayTestRunner("127.0.0.1", 10310, | |||||
// gwkey1, peerSrvAddr1); | |||||
GatewayTestRunner gateway0 = new GatewayTestRunner("127.0.0.1", 10300, gwkey0, peerSrvAddr0, LedgerInitConsensusConfig.bftsmartProvider, null); | |||||
AsyncCallback<Object> gwStarting0 = gateway0.start(); | |||||
// AsyncCallback<Object> gwStarting1 = gateway1.start(); | |||||
ThreadInvoker.AsyncCallback<Object> gwStarting0 = gateway0.start(); | |||||
gwStarting0.waitReturn(); | gwStarting0.waitReturn(); | ||||
// gwStarting1.waitReturn(); | |||||
// 执行测试用例之前,校验每个节点的一致性; | // 执行测试用例之前,校验每个节点的一致性; | ||||
// testConsistencyAmongNodes(context); | |||||
// testConsistencyAmongNodes(context); | |||||
testStorageErrorBlockRollbackSdk(gateway0, context); | |||||
testSDK(gateway0, context); | testSDK(gateway0, context); | ||||
System.out.println("------IntegrationTest Ok--------"); | |||||
// 执行测试用例之后,校验每个节点的一致性; | // 执行测试用例之后,校验每个节点的一致性; | ||||
// testConsistencyAmongNodes(context); | |||||
// testConsistencyAmongNodes(context); | |||||
} | } | ||||
/** | /** | ||||
@@ -147,7 +124,7 @@ public class IntegrationTest { | |||||
* | * | ||||
* @param context | * @param context | ||||
*/ | */ | ||||
private void testConsistencyAmongNodes(IntegratedContext context) { | |||||
private static void testConsistencyAmongNodes(IntegratedContext context) { | |||||
int[] ids = context.getNodeIds(); | int[] ids = context.getNodeIds(); | ||||
Node[] nodes = new Node[ids.length]; | Node[] nodes = new Node[ids.length]; | ||||
LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | LedgerQuery[] ledgers = new LedgerQuery[ids.length]; | ||||
@@ -164,6 +141,30 @@ public class IntegrationTest { | |||||
} | } | ||||
} | } | ||||
private static void testStorageErrorBlockRollbackSdk(GatewayTestRunner gateway, IntegratedContext context) { | |||||
((TestDbFactory)context.getNode(0).getStorageDB()).setErrorSetTurnOn(true); | |||||
((TestDbFactory)context.getNode(1).getStorageDB()).setErrorSetTurnOn(true); | |||||
((TestDbFactory)context.getNode(2).getStorageDB()).setErrorSetTurnOn(true); | |||||
((TestDbFactory)context.getNode(3).getStorageDB()).setErrorSetTurnOn(true); | |||||
// 连接网关; | |||||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||||
BlockchainService bcsrv = gwsrvFact.getBlockchainService(); | |||||
HashDigest[] ledgerHashs = bcsrv.getLedgerHashs(); | |||||
AsymmetricKeypair adminKey = context.getNode(0).getPartiKeyPair(); | |||||
BlockchainKeypair newUserAcount = testSDK_RegisterUser(adminKey, ledgerHashs[0], bcsrv, context); | |||||
((TestDbFactory)context.getNode(0).getStorageDB()).setErrorSetTurnOn(false); | |||||
((TestDbFactory)context.getNode(1).getStorageDB()).setErrorSetTurnOn(false); | |||||
((TestDbFactory)context.getNode(2).getStorageDB()).setErrorSetTurnOn(false); | |||||
((TestDbFactory)context.getNode(3).getStorageDB()).setErrorSetTurnOn(false); | |||||
} | |||||
private static void testSDK(GatewayTestRunner gateway, IntegratedContext context) { | private static void testSDK(GatewayTestRunner gateway, IntegratedContext context) { | ||||
// 连接网关; | // 连接网关; | ||||
GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | ||||
@@ -427,15 +428,15 @@ public class IntegrationTest { | |||||
return; | return; | ||||
} | } | ||||
public static ConsensusProvider getConsensusProvider() { | |||||
return ConsensusProviders.getProvider("com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider"); | |||||
public static ConsensusProvider getConsensusProvider(String providerName) { | |||||
return ConsensusProviders.getProvider(providerName); | |||||
} | } | ||||
private static IntegratedContext initLedgers() { | private static IntegratedContext initLedgers() { | ||||
Prompter consolePrompter = new PresetAnswerPrompter("N"); // new ConsolePrompter(); | Prompter consolePrompter = new PresetAnswerPrompter("N"); // new ConsolePrompter(); | ||||
LedgerInitProperties initSetting = loadInitSetting_integration(); | LedgerInitProperties initSetting = loadInitSetting_integration(); | ||||
Properties props = LedgerInitializeWebTest.loadConsensusSetting(); | |||||
ConsensusProvider csProvider = getConsensusProvider(); | |||||
Properties props = LedgerInitializeWebTest.loadConsensusSetting(LedgerInitConsensusConfig.bftsmartConfig.getConfigPath()); | |||||
ConsensusProvider csProvider = getConsensusProvider(LedgerInitConsensusConfig.bftsmartConfig.getProvider()); | |||||
ConsensusSettings csProps = csProvider.getSettingsFactory() | ConsensusSettings csProps = csProvider.getSettingsFactory() | ||||
.getConsensusSettingsBuilder() | .getConsensusSettingsBuilder() | ||||
.createSettings(props, Utils.loadParticipantNodes()); | .createSettings(props, Utils.loadParticipantNodes()); | ||||
@@ -465,29 +466,39 @@ public class IntegrationTest { | |||||
CountDownLatch quitLatch = new CountDownLatch(4); | CountDownLatch quitLatch = new CountDownLatch(4); | ||||
TestDbFactory dbFactory0 = new TestDbFactory(new CompositeConnectionFactory()); | |||||
dbFactory0.setErrorSetTurnOn(false); | |||||
DBConnectionConfig testDb0 = new DBConnectionConfig(); | DBConnectionConfig testDb0 = new DBConnectionConfig(); | ||||
testDb0.setConnectionUri("memory://local/0"); | testDb0.setConnectionUri("memory://local/0"); | ||||
LedgerBindingConfig bindingConfig0 = new LedgerBindingConfig(); | LedgerBindingConfig bindingConfig0 = new LedgerBindingConfig(); | ||||
AsyncCallback<HashDigest> callback0 = nodeCtx0.startInitCommand(privkey0, encodedPassword, initSetting, csProps, | AsyncCallback<HashDigest> callback0 = nodeCtx0.startInitCommand(privkey0, encodedPassword, initSetting, csProps, | ||||
csProvider, testDb0, consolePrompter, bindingConfig0, quitLatch); | |||||
csProvider, testDb0, consolePrompter, bindingConfig0, quitLatch, dbFactory0); | |||||
TestDbFactory dbFactory1 = new TestDbFactory(new CompositeConnectionFactory()); | |||||
dbFactory1.setErrorSetTurnOn(false); | |||||
DBConnectionConfig testDb1 = new DBConnectionConfig(); | DBConnectionConfig testDb1 = new DBConnectionConfig(); | ||||
testDb1.setConnectionUri("memory://local/1"); | testDb1.setConnectionUri("memory://local/1"); | ||||
LedgerBindingConfig bindingConfig1 = new LedgerBindingConfig(); | LedgerBindingConfig bindingConfig1 = new LedgerBindingConfig(); | ||||
AsyncCallback<HashDigest> callback1 = nodeCtx1.startInitCommand(privkey1, encodedPassword, initSetting, csProps, | AsyncCallback<HashDigest> callback1 = nodeCtx1.startInitCommand(privkey1, encodedPassword, initSetting, csProps, | ||||
csProvider, testDb1, consolePrompter, bindingConfig1, quitLatch); | |||||
csProvider, testDb1, consolePrompter, bindingConfig1, quitLatch, dbFactory1); | |||||
TestDbFactory dbFactory2 = new TestDbFactory(new CompositeConnectionFactory()); | |||||
dbFactory2.setErrorSetTurnOn(false); | |||||
DBConnectionConfig testDb2 = new DBConnectionConfig(); | DBConnectionConfig testDb2 = new DBConnectionConfig(); | ||||
testDb2.setConnectionUri("memory://local/2"); | testDb2.setConnectionUri("memory://local/2"); | ||||
LedgerBindingConfig bindingConfig2 = new LedgerBindingConfig(); | LedgerBindingConfig bindingConfig2 = new LedgerBindingConfig(); | ||||
AsyncCallback<HashDigest> callback2 = nodeCtx2.startInitCommand(privkey2, encodedPassword, initSetting, csProps, | AsyncCallback<HashDigest> callback2 = nodeCtx2.startInitCommand(privkey2, encodedPassword, initSetting, csProps, | ||||
csProvider, testDb2, consolePrompter, bindingConfig2, quitLatch); | |||||
csProvider, testDb2, consolePrompter, bindingConfig2, quitLatch, dbFactory2); | |||||
TestDbFactory dbFactory3 = new TestDbFactory(new CompositeConnectionFactory()); | |||||
dbFactory3.setErrorSetTurnOn(false); | |||||
DBConnectionConfig testDb3 = new DBConnectionConfig(); | DBConnectionConfig testDb3 = new DBConnectionConfig(); | ||||
testDb3.setConnectionUri("memory://local/3"); | testDb3.setConnectionUri("memory://local/3"); | ||||
LedgerBindingConfig bindingConfig3 = new LedgerBindingConfig(); | LedgerBindingConfig bindingConfig3 = new LedgerBindingConfig(); | ||||
AsyncCallback<HashDigest> callback3 = nodeCtx3.startInitCommand(privkey3, encodedPassword, initSetting, csProps, | AsyncCallback<HashDigest> callback3 = nodeCtx3.startInitCommand(privkey3, encodedPassword, initSetting, csProps, | ||||
csProvider, testDb3, consolePrompter, bindingConfig3, quitLatch); | |||||
csProvider, testDb3, consolePrompter, bindingConfig3, quitLatch, dbFactory3); | |||||
HashDigest ledgerHash0 = callback0.waitReturn(); | HashDigest ledgerHash0 = callback0.waitReturn(); | ||||
HashDigest ledgerHash1 = callback1.waitReturn(); | HashDigest ledgerHash1 = callback1.waitReturn(); | ||||
@@ -542,7 +553,7 @@ public class IntegrationTest { | |||||
} | } | ||||
public static LedgerInitProperties loadInitSetting_integration() { | public static LedgerInitProperties loadInitSetting_integration() { | ||||
ClassPathResource ledgerInitSettingResource = new ClassPathResource("ledger_init_test_integration.init"); | |||||
ClassPathResource ledgerInitSettingResource = new ClassPathResource("ledger_init_test_web2.init"); | |||||
try (InputStream in = ledgerInitSettingResource.getInputStream()) { | try (InputStream in = ledgerInitSettingResource.getInputStream()) { | ||||
LedgerInitProperties setting = LedgerInitProperties.resolve(in); | LedgerInitProperties setting = LedgerInitProperties.resolve(in); | ||||
return setting; | return setting; | ||||
@@ -0,0 +1,140 @@ | |||||
package test.com.jd.blockchain.intgr; | |||||
import static org.mockito.Matchers.any; | |||||
import static org.mockito.Matchers.anyLong; | |||||
import static org.mockito.Mockito.doAnswer; | |||||
import static org.mockito.Mockito.when; | |||||
import java.util.concurrent.atomic.AtomicBoolean; | |||||
import com.jd.blockchain.storage.service.*; | |||||
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||||
import org.mockito.Mockito; | |||||
import org.mockito.invocation.InvocationOnMock; | |||||
import org.mockito.stubbing.Answer; | |||||
public class TestDbFactory implements DbConnectionFactory{ | |||||
private DbConnectionFactory innerDbFactory; | |||||
private AtomicBoolean errorSetTurnOn = new AtomicBoolean(false); | |||||
public TestDbFactory(DbConnectionFactory innerDbFactory) { | |||||
this.innerDbFactory = innerDbFactory; | |||||
} | |||||
Answer<ExPolicyKVStorage> exKVStorageMockedAnswer = new Answer<ExPolicyKVStorage>() { | |||||
@Override | |||||
public ExPolicyKVStorage answer(InvocationOnMock invocation) throws Throwable { | |||||
ExPolicyKVStorage reallyExKVStorage = (ExPolicyKVStorage) invocation.callRealMethod(); | |||||
ExPolicyKVStorage mockExKVStorage = Mockito.spy(reallyExKVStorage); | |||||
//按条件开关触发异常; | |||||
doAnswer(new Answer<Boolean>() { | |||||
@Override | |||||
public Boolean answer(InvocationOnMock invocation) throws Throwable { | |||||
if (isErrorSetTurnOn()) { | |||||
return false; | |||||
} | |||||
return (Boolean) invocation.callRealMethod(); | |||||
} | |||||
}).when(mockExKVStorage).set(any(), any(), any()); | |||||
return mockExKVStorage; | |||||
} | |||||
}; | |||||
Answer<VersioningKVStorage> verKVStorageMockedAnswer = new Answer<VersioningKVStorage>() { | |||||
@Override | |||||
public VersioningKVStorage answer(InvocationOnMock invocation) throws Throwable { | |||||
VersioningKVStorage reallyVerKVStorage = (VersioningKVStorage) invocation.callRealMethod(); | |||||
VersioningKVStorage mockVerKVStorage = Mockito.spy(reallyVerKVStorage); | |||||
//按条件开关触发异常; | |||||
doAnswer(new Answer<Long>() { | |||||
@Override | |||||
public Long answer(InvocationOnMock invocation) throws Throwable { | |||||
if (isErrorSetTurnOn()) { | |||||
return (long)(-1); | |||||
} | |||||
return (Long) invocation.callRealMethod(); | |||||
} | |||||
}).when(mockVerKVStorage).set(any(), any(), anyLong()); | |||||
return mockVerKVStorage; | |||||
} | |||||
}; | |||||
Answer<KVStorageService> storageMockedAnswer = new Answer<KVStorageService>() { | |||||
@Override | |||||
public KVStorageService answer(InvocationOnMock invocation) throws Throwable { | |||||
KVStorageService reallyStorage = (KVStorageService) invocation.callRealMethod(); | |||||
TestMemoryKVStorage testMemoryKVStorage = new TestMemoryKVStorage((MemoryKVStorage)reallyStorage); | |||||
KVStorageService mockedStorage = Mockito.spy(testMemoryKVStorage); | |||||
doAnswer(exKVStorageMockedAnswer).when(mockedStorage).getExPolicyKVStorage(); | |||||
doAnswer(verKVStorageMockedAnswer).when(mockedStorage).getVersioningKVStorage(); | |||||
return mockedStorage; | |||||
} | |||||
}; | |||||
@Override | |||||
public String dbPrefix() { | |||||
return innerDbFactory.dbPrefix(); | |||||
} | |||||
@Override | |||||
public boolean support(String scheme) { | |||||
return innerDbFactory.support(scheme); | |||||
} | |||||
@Override | |||||
public DbConnection connect(String dbConnectionString) { | |||||
DbConnection reallyDbConn = innerDbFactory.connect(dbConnectionString); | |||||
DbConnection mockDbConn = Mockito.spy(reallyDbConn); | |||||
when(mockDbConn.getStorageService()).then(storageMockedAnswer); | |||||
return mockDbConn; | |||||
} | |||||
@Override | |||||
public DbConnection connect(String dbConnectionString, String password) { | |||||
return connect(dbConnectionString); | |||||
} | |||||
@Override | |||||
public void close() { | |||||
innerDbFactory.close(); | |||||
} | |||||
public boolean isErrorSetTurnOn() { | |||||
return errorSetTurnOn.get(); | |||||
} | |||||
public void setErrorSetTurnOn(boolean errorSetTurnOn) { | |||||
this.errorSetTurnOn.set(errorSetTurnOn);; | |||||
} | |||||
} |
@@ -0,0 +1,24 @@ | |||||
package test.com.jd.blockchain.intgr; | |||||
import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||||
import com.jd.blockchain.storage.service.VersioningKVStorage; | |||||
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||||
public class TestMemoryKVStorage extends MemoryKVStorage { | |||||
private MemoryKVStorage memoryKVStorage; | |||||
public TestMemoryKVStorage(MemoryKVStorage memoryKVStorage) { | |||||
this.memoryKVStorage = memoryKVStorage; | |||||
} | |||||
@Override | |||||
public ExPolicyKVStorage getExPolicyKVStorage() { | |||||
return memoryKVStorage; | |||||
} | |||||
@Override | |||||
public VersioningKVStorage getVersioningKVStorage() { | |||||
return memoryKVStorage; | |||||
} | |||||
} |
@@ -48,16 +48,17 @@ public class LedgerInitializeTest { | |||||
public static final String PASSWORD = "abc"; | public static final String PASSWORD = "abc"; | ||||
public static final String[] PUB_KEYS = { "endPsK36koyFr1D245Sa9j83vt6pZUdFBJoJRB3xAsWM6cwhRbna", | |||||
"endPsK36sC5JdPCDPDAXUwZtS3sxEmqEhFcC4whayAsTTh8Z6eoZ", | |||||
"endPsK36jEG281HMHeh6oSqzqLkT95DTnCM6REDURjdb2c67uR3R", | |||||
"endPsK36nse1dck4uF19zPvAMijCV336Y3zWdgb4rQG8QoRj5ktR" }; | |||||
public static final String[] PUB_KEYS = { "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9", | |||||
"3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX", | |||||
"3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x", | |||||
"3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk" }; | |||||
public static final String[] PRIV_KEYS = { | public static final String[] PRIV_KEYS = { | ||||
"177gjsj5PHeCpbAtJE7qnbmhuZMHAEKuMsd45zHkv8F8AWBvTBbff8yRKdCyT3kwrmAjSnY", | |||||
"177gjw9u84WtuCsK8u2WeH4nWqzgEoJWY7jJF9AU6XwLHSosrcNX3H6SSBsfvR53HgX7KR2", | |||||
"177gk2FpjufgEon92mf2oRRFXDBZkRy8SkFci7Jxc5pApZEJz3oeCoxieWatDD3Xg7i1QEN", | |||||
"177gjvv7qvfCAXroFezSn23UFXLVLFofKS3y6DXkJ2DwVWS4LcRNtxRgiqWmQEeWNz4KQ3J" }; | |||||
"177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x", | |||||
"177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT", | |||||
"177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF", | |||||
"177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns" }; | |||||
private Map<NetworkAddress, LedgerInitConsensusService> serviceRegisterMap = new ConcurrentHashMap<>(); | private Map<NetworkAddress, LedgerInitConsensusService> serviceRegisterMap = new ConcurrentHashMap<>(); | ||||
@@ -5,6 +5,7 @@ import java.io.InputStream; | |||||
import java.util.Properties; | import java.util.Properties; | ||||
import java.util.concurrent.CountDownLatch; | import java.util.concurrent.CountDownLatch; | ||||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||||
import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||
import org.springframework.context.ConfigurableApplicationContext; | import org.springframework.context.ConfigurableApplicationContext; | ||||
import org.springframework.core.io.ClassPathResource; | import org.springframework.core.io.ClassPathResource; | ||||
@@ -52,6 +53,7 @@ import com.jd.blockchain.utils.io.BytesUtils; | |||||
import com.jd.blockchain.utils.io.FileUtils; | import com.jd.blockchain.utils.io.FileUtils; | ||||
import com.jd.blockchain.utils.net.NetworkAddress; | import com.jd.blockchain.utils.net.NetworkAddress; | ||||
import test.com.jd.blockchain.intgr.LedgerInitConsensusConfig; | |||||
import test.com.jd.blockchain.intgr.PresetAnswerPrompter; | import test.com.jd.blockchain.intgr.PresetAnswerPrompter; | ||||
public class LedgerInitializeWebTest { | public class LedgerInitializeWebTest { | ||||
@@ -73,7 +75,7 @@ public class LedgerInitializeWebTest { | |||||
// 加载初始化配置; | // 加载初始化配置; | ||||
LedgerInitProperties initSetting = loadInitSetting_1(); | LedgerInitProperties initSetting = loadInitSetting_1(); | ||||
// 加载共识配置; | // 加载共识配置; | ||||
Properties props = loadConsensusSetting(); | |||||
Properties props = loadConsensusSetting(LedgerInitConsensusConfig.bftsmartConfig.getConfigPath()); | |||||
// ConsensusProperties csProps = new ConsensusProperties(props); | // ConsensusProperties csProps = new ConsensusProperties(props); | ||||
ConsensusProvider csProvider = getConsensusProvider(); | ConsensusProvider csProvider = getConsensusProvider(); | ||||
ConsensusSettings csProps = csProvider.getSettingsFactory() | ConsensusSettings csProps = csProvider.getSettingsFactory() | ||||
@@ -242,7 +244,7 @@ public class LedgerInitializeWebTest { | |||||
Prompter consolePrompter = new PresetAnswerPrompter("N"); // new ConsolePrompter(); | Prompter consolePrompter = new PresetAnswerPrompter("N"); // new ConsolePrompter(); | ||||
LedgerInitProperties initSetting = loadInitSetting_2(); | LedgerInitProperties initSetting = loadInitSetting_2(); | ||||
Properties props = loadConsensusSetting(); | |||||
Properties props = loadConsensusSetting(LedgerInitConsensusConfig.bftsmartConfig.getConfigPath()); | |||||
// ConsensusProperties csProps = new ConsensusProperties(props); | // ConsensusProperties csProps = new ConsensusProperties(props); | ||||
ConsensusProvider csProvider = getConsensusProvider(); | ConsensusProvider csProvider = getConsensusProvider(); | ||||
ConsensusSettings csProps = csProvider.getSettingsFactory() | ConsensusSettings csProps = csProvider.getSettingsFactory() | ||||
@@ -339,9 +341,9 @@ public class LedgerInitializeWebTest { | |||||
throw new IllegalStateException(e.getMessage(), e); | throw new IllegalStateException(e.getMessage(), e); | ||||
} | } | ||||
} | } | ||||
public static Properties loadConsensusSetting() { | |||||
ClassPathResource ledgerInitSettingResource = new ClassPathResource("bftsmart.config"); | |||||
public static Properties loadConsensusSetting(String configPath) { | |||||
ClassPathResource ledgerInitSettingResource = new ClassPathResource(configPath); | |||||
try (InputStream in = ledgerInitSettingResource.getInputStream()) { | try (InputStream in = ledgerInitSettingResource.getInputStream()) { | ||||
return FileUtils.readProperties(in); | return FileUtils.readProperties(in); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
@@ -365,7 +367,7 @@ public class LedgerInitializeWebTest { | |||||
private volatile LedgerManager ledgerManager; | private volatile LedgerManager ledgerManager; | ||||
private volatile CompositeConnectionFactory db; | |||||
private volatile DbConnectionFactory db; | |||||
private int id; | private int id; | ||||
@@ -429,21 +431,14 @@ public class LedgerInitializeWebTest { | |||||
return invoker.start(); | return invoker.start(); | ||||
} | } | ||||
// public AsyncCallback<HashDigest> startInitCommand(PrivKey privKey, String | |||||
// base58Pwd, LedgerInitProperties ledgerSetting, ConsensusSettings csProps, | |||||
// DBConnectionConfig dbConnConfig, | |||||
// Prompter prompter, LedgerBindingConfig conf, CountDownLatch quitLatch) { | |||||
// return startInitCommand(privKey, base58Pwd, ledgerSetting, csProps, | |||||
// dbConnConfig, prompter, conf, quitLatch); | |||||
// } | |||||
public AsyncCallback<HashDigest> startInitCommand(PrivKey privKey, String base58Pwd, | public AsyncCallback<HashDigest> startInitCommand(PrivKey privKey, String base58Pwd, | ||||
LedgerInitProperties ledgerSetting, ConsensusSettings csProps, ConsensusProvider csProvider, | |||||
DBConnectionConfig dbConnConfig, Prompter prompter, LedgerBindingConfig conf, | |||||
CountDownLatch quitLatch) { | |||||
this.db = new CompositeConnectionFactory(); | |||||
LedgerInitProperties ledgerSetting, ConsensusSettings csProps, ConsensusProvider csProvider, | |||||
DBConnectionConfig dbConnConfig, Prompter prompter, LedgerBindingConfig conf, | |||||
CountDownLatch quitLatch, DbConnectionFactory db) { | |||||
this.dbConnConfig = dbConnConfig; | this.dbConnConfig = dbConnConfig; | ||||
// this.mqConnConfig = mqConnConfig; | // this.mqConnConfig = mqConnConfig; | ||||
this.db = db; | |||||
ThreadInvoker<HashDigest> invoker = new ThreadInvoker<HashDigest>() { | ThreadInvoker<HashDigest> invoker = new ThreadInvoker<HashDigest>() { | ||||
@Override | @Override | ||||
@@ -460,6 +455,7 @@ public class LedgerInitializeWebTest { | |||||
return invoker.start(); | return invoker.start(); | ||||
} | } | ||||
public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitConfiguration initConfig) { | public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitConfiguration initConfig) { | ||||
return controller.prepareLocalPermission(id, privKey, initConfig); | return controller.prepareLocalPermission(id, privKey, initConfig); | ||||
} | } | ||||
@@ -517,7 +513,7 @@ public class LedgerInitializeWebTest { | |||||
// return ctx.getBean(LedgerManager.class); | // return ctx.getBean(LedgerManager.class); | ||||
} | } | ||||
public CompositeConnectionFactory getStorageDB() { | |||||
public DbConnectionFactory getStorageDB() { | |||||
return db; | return db; | ||||
} | } | ||||
} | } | ||||
@@ -2,7 +2,10 @@ | |||||
ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe | ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe | ||||
#账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; | #账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; | ||||
ledger.name= | |||||
ledger.name==myledger | |||||
#声明的账本创建时间;格式为 “yyyy-MM-dd HH:mm:ss.SSSZ”,表示”年-月-日 时:分:秒:毫秒时区“;例如:“2019-08-01 14:26:58.069+0800”,其中,+0800 表示时区是东8区 | |||||
created-time=2019-08-01 14:26:58.069+0800 | |||||
#共识服务提供者;必须; | #共识服务提供者;必须; | ||||
consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider | consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider | ||||
@@ -1,233 +0,0 @@ | |||||
//package test.com.jd.blockchain.intgr; | |||||
// | |||||
//import com.jd.blockchain.consensus.ConsensusProviders; | |||||
//import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusSettings; | |||||
//import com.jd.blockchain.crypto.*; | |||||
//import com.jd.blockchain.gateway.GatewayConfigProperties; | |||||
//import com.jd.blockchain.ledger.BlockRollbackException; | |||||
//import com.jd.blockchain.ledger.BlockchainKeypair; | |||||
//import com.jd.blockchain.ledger.core.LedgerManager; | |||||
//import com.jd.blockchain.ledger.core.LedgerQuery; | |||||
//import com.jd.blockchain.sdk.BlockchainService; | |||||
//import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||||
//import com.jd.blockchain.storage.service.DbConnection; | |||||
//import com.jd.blockchain.storage.service.DbConnectionFactory; | |||||
//import com.jd.blockchain.storage.service.ExPolicyKVStorage; | |||||
//import com.jd.blockchain.storage.service.KVStorageService; | |||||
//import com.jd.blockchain.storage.service.utils.MemoryKVStorage; | |||||
//import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||||
//import com.jd.blockchain.utils.Bytes; | |||||
//import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||||
//import org.junit.Test; | |||||
//import org.mockito.Mockito; | |||||
//import org.mockito.invocation.InvocationOnMock; | |||||
//import org.mockito.stubbing.Answer; | |||||
//import test.com.jd.blockchain.intgr.initializer.LedgerInitializeTest; | |||||
//import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4Nodes; | |||||
// | |||||
//import java.lang.reflect.Method; | |||||
//import java.util.concurrent.CountDownLatch; | |||||
//import java.util.concurrent.ExecutorService; | |||||
//import java.util.concurrent.Executors; | |||||
// | |||||
//import static org.mockito.Matchers.any; | |||||
//import static org.mockito.Matchers.anyLong; | |||||
//import static org.mockito.Mockito.doCallRealMethod; | |||||
//import static org.mockito.Mockito.doThrow; | |||||
//import static test.com.jd.blockchain.intgr.IntegrationBase.*; | |||||
// | |||||
//public class IntegrationTestStorageErrorRollBack { | |||||
// | |||||
// private static final boolean isRegisterUser = true; | |||||
// | |||||
// private static final boolean isRegisterDataAccount = false; | |||||
// | |||||
// private static final boolean isWriteKv = false; | |||||
// | |||||
// private static final String DB_TYPE_MEM = "mem"; | |||||
// | |||||
// public static final String BFTSMART_PROVIDER = "com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider"; | |||||
// | |||||
// public boolean isRollBack = false; | |||||
// | |||||
// @Test | |||||
// public void test4Memory() { | |||||
// test(LedgerInitConsensusConfig.bftsmartProvider, DB_TYPE_MEM, LedgerInitConsensusConfig.memConnectionStrings); | |||||
// } | |||||
// | |||||
// public void test(String[] providers, String dbType, String[] dbConnections) { | |||||
// | |||||
// | |||||
// final ExecutorService sendReqExecutors = Executors.newFixedThreadPool(20); | |||||
// | |||||
// // 内存账本初始化 | |||||
// HashDigest ledgerHash = initLedger(dbConnections); | |||||
// | |||||
// System.out.println("---------------init OK-------------------"); | |||||
// | |||||
// // 启动Peer节点 | |||||
// PeerTestRunner[] peerNodes = peerNodeStart(ledgerHash, dbType); | |||||
// | |||||
// System.out.println("---------------peer start OK-------------------"); | |||||
// String encodedBase58Pwd = KeyGenUtils.encodePasswordAsBase58(LedgerInitializeTest.PASSWORD); | |||||
// | |||||
// GatewayConfigProperties.KeyPairConfig gwkey0 = new GatewayConfigProperties.KeyPairConfig(); | |||||
// gwkey0.setPubKeyValue(IntegrationBase.PUB_KEYS[0]); | |||||
// gwkey0.setPrivKeyValue(IntegrationBase.PRIV_KEYS[0]); | |||||
// gwkey0.setPrivKeyPassword(encodedBase58Pwd); | |||||
// GatewayTestRunner gateway = new GatewayTestRunner("127.0.0.1", 11000, gwkey0, | |||||
// peerNodes[0].getServiceAddress(), providers,null); | |||||
// | |||||
// ThreadInvoker.AsyncCallback<Object> gwStarting = gateway.start(); | |||||
// | |||||
// gwStarting.waitReturn(); | |||||
// | |||||
// LedgerQuery[] ledgers = new LedgerQuery[peerNodes.length]; | |||||
// LedgerManager[] ledgerManagers = new LedgerManager[peerNodes.length]; | |||||
// LedgerBindingConfig[] ledgerBindingConfigs = new LedgerBindingConfig[peerNodes.length]; | |||||
// DbConnection[] connections = new DbConnection[peerNodes.length]; | |||||
// MemoryKVStorage[] storageMocks = new MemoryKVStorage[peerNodes.length]; | |||||
// for (int i = 0; i < peerNodes.length; i++) { | |||||
// ledgerManagers[i] = new LedgerManager(); | |||||
// ledgerBindingConfigs[i] = peerNodes[i].getLedgerBindingConfig(); | |||||
// connections[i] = peerNodes[i].getDBConnectionFactory().connect(ledgerBindingConfigs[i].getLedger(ledgerHash).getDbConnection().getUri()); | |||||
// System.out.printf("StorageService[%s] -> %s \r\n", i, connections[i].getStorageService()); | |||||
// storageMocks[i] = Mockito.spy((MemoryKVStorage)(connections[i].getStorageService())); | |||||
// ledgers[i] = ledgerManagers[i].register(ledgerHash, storageMocks[i]); | |||||
// } | |||||
// | |||||
// final MemoryKVStorage STORAGE_Mock = Mockito.mock(MemoryKVStorage.class); | |||||
// | |||||
// Answer<String> answers = new Answer() { | |||||
// | |||||
// @Override | |||||
// public Object answer(InvocationOnMock invocationOnMock) throws Throwable { | |||||
// | |||||
// Method method = invocationOnMock.getMethod(); | |||||
// if (method.getName().equalsIgnoreCase("set")) { | |||||
// Object arg2Obj = invocationOnMock.getArguments()[2]; | |||||
// if (isRollBack) { | |||||
// if (arg2Obj instanceof ExPolicyKVStorage.ExPolicy) { | |||||
// return false; | |||||
// } else { | |||||
// return -1; | |||||
// } | |||||
// } else { | |||||
// if (arg2Obj instanceof ExPolicyKVStorage.ExPolicy) { | |||||
// return STORAG.set((Bytes) (invocationOnMock.getArguments()[0]), (byte[]) (invocationOnMock.getArguments()[1]), (ExPolicyKVStorage.ExPolicy) (arg2Obj)); | |||||
// } else { | |||||
// return STORAGE.set((Bytes) (invocationOnMock.getArguments()[0]), (byte[]) (invocationOnMock.getArguments()[1]), (long) (arg2Obj)); | |||||
// } | |||||
// } | |||||
// } else if ((method.getName().equalsIgnoreCase("get")) && (method.getParameterCount() == 1)) { | |||||
// return STORAGE.get((Bytes) (invocationOnMock.getArguments()[0])); | |||||
// } else if ((method.getName().equalsIgnoreCase("get")) && (method.getParameterCount() == 2)) { | |||||
// return STORAGE.get((Bytes) (invocationOnMock.getArguments()[0]), (long) (invocationOnMock.getArguments()[1])); | |||||
// } else if (method.getName().equalsIgnoreCase("getVersion")) { | |||||
// return STORAGE.getVersion((Bytes) (invocationOnMock.getArguments()[0])); | |||||
// } else if (method.getName().equalsIgnoreCase("getEntry")) { | |||||
// return STORAGE.get((Bytes) (invocationOnMock.getArguments()[0]), (long) (invocationOnMock.getArguments()[1])); | |||||
// } else if (method.getName().equalsIgnoreCase("exist")) { | |||||
// return STORAGE.get((Bytes) (invocationOnMock.getArguments()[0])); | |||||
// } else if (method.getName().equalsIgnoreCase("keySet")) { | |||||
// return STORAGE.keySet(); | |||||
// } else if (method.getName().equalsIgnoreCase("getStorageKeySet")) { | |||||
// return STORAGE.getStorageKeySet(); | |||||
// } else if (method.getName().equalsIgnoreCase("getValue")) { | |||||
// return STORAGE.getValue((Bytes) (invocationOnMock.getArguments()[0])); | |||||
// } else if (method.getName().equalsIgnoreCase("getStorageCount")) { | |||||
// return STORAGE.getStorageCount(); | |||||
// } else if (method.getName().equalsIgnoreCase("getExPolicyKVStorage")) { | |||||
// return STORAGE.getExPolicyKVStorage(); | |||||
// } else if (method.getName().equalsIgnoreCase("getVersioningKVStorage")) { | |||||
// return STORAGE.getVersioningKVStorage(); | |||||
// } | |||||
// | |||||
// return null; | |||||
// } | |||||
// }; | |||||
// | |||||
// when(STORAGE_Mock.set(any(), any(), anyLong())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.set(any(), any(), any(ExPolicyKVStorage.ExPolicy.class))).thenAnswer(answers); | |||||
// when(STORAGE_Mock.get(any())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.get(any(), anyLong())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getVersion(any())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getEntry(any(), anyLong())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.exist(any())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.keySet()).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getStorageKeySet()).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getValue(any())).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getStorageCount()).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getExPolicyKVStorage()).thenAnswer(answers); | |||||
// when(STORAGE_Mock.getVersioningKVStorage()).thenAnswer(answers); | |||||
// | |||||
// | |||||
// IntegrationBase.testConsistencyAmongNodes(ledgers); | |||||
// | |||||
// LedgerQuery ledgerRepository = ledgers[0]; | |||||
// | |||||
// GatewayServiceFactory gwsrvFact = GatewayServiceFactory.connect(gateway.getServiceAddress()); | |||||
// | |||||
// PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(IntegrationBase.PRIV_KEYS[0], IntegrationBase.PASSWORD); | |||||
// | |||||
// PubKey pubKey0 = KeyGenUtils.decodePubKey(IntegrationBase.PUB_KEYS[0]); | |||||
// | |||||
// AsymmetricKeypair adminKey = new AsymmetricKeypair(pubKey0, privkey0); | |||||
// | |||||
// BlockchainService blockchainService = gwsrvFact.getBlockchainService(); | |||||
// | |||||
// int size = 15; | |||||
// CountDownLatch countDownLatch = new CountDownLatch(size); | |||||
// if (isRegisterUser) { | |||||
// for (int i = 0; i < size; i++) { | |||||
// sendReqExecutors.execute(() -> { | |||||
// | |||||
// System.out.printf(" sdk execute time = %s threadId = %s \r\n", System.currentTimeMillis(), Thread.currentThread().getId()); | |||||
// KeyPairResponse userResponse = IntegrationBase.testSDK_RegisterUser(adminKey, ledgerHash, blockchainService); | |||||
// | |||||
//// validKeyPair(userResponse, ledgerRepository, IntegrationBase.KeyPairType.USER); | |||||
// countDownLatch.countDown(); | |||||
// }); | |||||
// } | |||||
// } | |||||
// try { | |||||
// countDownLatch.await(); | |||||
// } catch (InterruptedException e) { | |||||
// e.printStackTrace(); | |||||
// } | |||||
// | |||||
// for (int i = 0; i < peerNodes.length; i++) { | |||||
// doCallRealMethod().when(storageMocks[i]).set(any(), any(), anyLong()); | |||||
// } | |||||
// | |||||
// if (isRegisterDataAccount) { | |||||
// KeyPairResponse dataAccountResponse = IntegrationBase.testSDK_RegisterDataAccount(adminKey, ledgerHash, blockchainService); | |||||
// | |||||
// validKeyPair(dataAccountResponse, ledgerRepository, KeyPairType.DATAACCOUNT); | |||||
// | |||||
// if (isWriteKv) { | |||||
// | |||||
// for (int m = 0; m < 13; m++) { | |||||
// BlockchainKeypair da = dataAccountResponse.keyPair; | |||||
// KvResponse kvResponse = IntegrationBase.testSDK_InsertData(adminKey, ledgerHash, blockchainService, da.getAddress()); | |||||
// validKvWrite(kvResponse, ledgerRepository, blockchainService); | |||||
// } | |||||
// } | |||||
// } | |||||
// | |||||
// try { | |||||
// System.out.println("----------------- Init Completed -----------------"); | |||||
// Thread.sleep(Integer.MAX_VALUE); | |||||
// } catch (InterruptedException e) { | |||||
// e.printStackTrace(); | |||||
// } | |||||
// | |||||
// IntegrationBase.testConsistencyAmongNodes(ledgers); | |||||
// } | |||||
// private HashDigest initLedger(String[] dbConnections) { | |||||
// LedgerInitializeWeb4Nodes ledgerInit = new LedgerInitializeWeb4Nodes(); | |||||
// HashDigest ledgerHash = ledgerInit.testInitWith4Nodes(LedgerInitConsensusConfig.bftsmartConfig, dbConnections); | |||||
// System.out.printf("LedgerHash = %s \r\n", ledgerHash.toBase58()); | |||||
// return ledgerHash; | |||||
// } | |||||
//} |