use of com.icodici.universa.node2.network.Client in project universa by UniversaBlockchain.
the class ResearchTest method registerManySimpleContractsWhite.
@Test
public void registerManySimpleContractsWhite() throws Exception {
int CONTRACTS_PER_THREAD = 1000;
// max 10
int THREADS_COUNT = 10;
AtomicLong totalCounter = new AtomicLong(0);
RunnablePrm r = (threadIndex) -> {
try {
Client cln = clients.get(threadIndex);
for (int i = 0; i < CONTRACTS_PER_THREAD; ++i) {
Contract whiteContract = new Contract(TestKeys.privateKey(threadIndex));
whiteContract.seal();
ItemResult itemResult = cln.register(whiteContract.getPackedTransaction(), 15000);
assertEquals(ItemState.APPROVED, itemResult.state);
totalCounter.incrementAndGet();
}
} catch (Exception e) {
System.out.println("error: " + e.toString());
}
};
List<Thread> threadList = new ArrayList<>();
for (int i = 0; i < THREADS_COUNT; ++i) {
final int threadIndex = i;
Thread t = new Thread(() -> r.run(threadIndex));
t.start();
threadList.add(t);
}
Thread heartbeat = new Thread(() -> {
try {
while (true) {
Thread.sleep(1000);
System.out.println("totalCounter: " + totalCounter.get());
}
} catch (Exception e) {
System.out.println("error: " + e.toString());
}
});
heartbeat.start();
for (Thread t : threadList) t.join();
heartbeat.interrupt();
}
use of com.icodici.universa.node2.network.Client in project universa by UniversaBlockchain.
the class ScriptEngineTest method prepareTestSpace.
private TestSpace prepareTestSpace(PrivateKey key) throws Exception {
TestSpace testSpace = new TestSpace();
testSpace.nodes = new ArrayList<>();
for (int i = 0; i < 4; i++) testSpace.nodes.add(createMain("node" + (i + 1), "", false));
testSpace.node = testSpace.nodes.get(0);
assertEquals("http://localhost:8080", testSpace.node.myInfo.internalUrlString());
assertEquals("http://localhost:8080", testSpace.node.myInfo.publicUrlString());
testSpace.myKey = key;
testSpace.client = new Client(testSpace.myKey, testSpace.node.myInfo, null);
testSpace.clients = new ArrayList();
for (int i = 0; i < 4; i++) testSpace.clients.add(new Client(testSpace.myKey, testSpace.nodes.get(i).myInfo, null));
for (Main m : testSpace.nodes) {
while (m.node.isSanitating()) Thread.sleep(100);
}
return testSpace;
}
use of com.icodici.universa.node2.network.Client in project universa by UniversaBlockchain.
the class JarNetworkTest method registerManySimpleContractsWhite.
@Test
public void registerManySimpleContractsWhite() throws Exception {
int CONTRACTS_PER_THREAD = 20;
int THREADS_COUNT = 4;
AtomicLong totalCounter = new AtomicLong(0);
Runnable r = () -> {
try {
Client cln = createWhiteClient();
int nodeNumber = cln.getNodeNumber();
System.out.println("nodeNumber: " + nodeNumber);
for (int i = 0; i < CONTRACTS_PER_THREAD; ++i) {
Contract whiteContract = new Contract(TestKeys.privateKey(nodeNumber - 1));
whiteContract.seal();
ItemResult itemResult = cln.register(whiteContract.getPackedTransaction(), 15000);
assertEquals(ItemState.APPROVED, itemResult.state);
totalCounter.incrementAndGet();
}
} catch (Exception e) {
System.out.println("error: " + e.toString());
}
};
List<Thread> threadList = new ArrayList<>();
for (int i = 0; i < THREADS_COUNT; ++i) {
Thread t = new Thread(r);
t.start();
threadList.add(t);
}
Thread heartbeat = new Thread(() -> {
try {
while (true) {
Thread.sleep(1000);
System.out.println("totalCounter: " + totalCounter.get());
}
} catch (Exception e) {
System.out.println("totalCounter: " + totalCounter.get());
}
});
heartbeat.start();
for (Thread t : threadList) t.join();
heartbeat.interrupt();
heartbeat.join();
}
use of com.icodici.universa.node2.network.Client in project universa by UniversaBlockchain.
the class UBotSessionsProTest method createSessionConcurrentRequests.
@Test
public void createSessionConcurrentRequests() throws Exception {
Client client = new Client("universa.pro", null, TestKeys.privateKey(0));
Contract executableContract = new Contract(TestKeys.privateKey(1));
executableContract.getStateData().put("cloud_methods", Binder.of("getRandom", Binder.of("pool", Binder.of("size", 5), "quorum", Binder.of("size", 4))));
executableContract.getStateData().put("js", "");
executableContract.seal();
assertEquals(client.register(executableContract.getPackedTransaction(), 100000).state, ItemState.APPROVED);
System.out.println("EID = " + executableContract.getId());
List<Contract> requestContracts = new ArrayList<>();
for (int i = 0; i < client.size(); i++) {
Contract requestContract = new Contract(TestKeys.privateKey(2));
requestContract.getStateData().put("executable_contract_id", executableContract.getId());
requestContract.getStateData().put("method_name", "getRandom");
requestContract.getStateData().put("method_args", Do.listOf(1000));
ContractsService.addReferenceToContract(requestContract, executableContract, "executable_contract_constraint", Reference.TYPE_EXISTING_DEFINITION, Do.listOf("ref.id==this.state.data.executable_contract_id"), true);
requestContract.seal();
requestContract.getTransactionPack().addReferencedItem(executableContract);
requestContracts.add(requestContract);
}
for (int i = 0; i < client.size(); i++) {
int finalI = i;
Do.inParallel(() -> {
System.out.println(client.getClient(finalI).command("ubotCreateSession", "packedRequest", requestContracts.get(finalI).getPackedTransaction()));
});
}
AtomicInteger readyCounter = new AtomicInteger();
AsyncEvent readyEvent = new AsyncEvent();
for (int i = 0; i < client.size(); i++) {
int finalI = i;
Do.inParallel(() -> {
while (true) {
Binder res = client.getClient(finalI).command("ubotGetSession", "executableContractId", executableContract.getId());
System.out.println(client.getClient(finalI).getNodeNumber() + " " + res);
Thread.sleep(500);
if (res.get("session") != null && res.getBinderOrThrow("session").getString("state", "").equals("OPERATIONAL")) {
if (readyCounter.incrementAndGet() == client.size()) {
readyEvent.fire();
}
break;
}
}
});
}
readyEvent.await();
}
use of com.icodici.universa.node2.network.Client in project universa by UniversaBlockchain.
the class UBotSessionsTest method registerUBotRegistryContract.
@Ignore
@Test
public void registerUBotRegistryContract() throws Exception {
// KeyAddress ka = new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s");
// //for(int i = 0; i < TestKeys.binaryKeys.length;i++) {
// // if(TestKeys.publicKey(i).isMatchingKeyAddress(ka)) {
// // System.out.println(i);
// // }
// //}
//
// PrivateKey key = new PrivateKey(Do.read("/Users/romanu/Downloads/ru/roman.uskov.privateKey.unikey"));
// System.out.println(key.getPublicKey().isMatchingKeyAddress(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")));
Client client = new Client("universa.local", null, TestKeys.privateKey(0));
Contract ubotRegistry = Contract.fromPackedTransaction(client.getServiceContracts().getBinaryOrThrow("ubot_registry_contract"));
System.out.println(client.register(ubotRegistry.getPackedTransaction(), 10000));
}
Aggregations